2026-05-03 08:43:23 +08:00
|
|
|
package redis
|
|
|
|
|
|
|
|
|
|
func stringsToAnys(in []string) []any {
|
|
|
|
|
a := make([]any, len(in))
|
|
|
|
|
for i, v := range in {
|
|
|
|
|
a[i] = v
|
|
|
|
|
}
|
|
|
|
|
return a
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (rd *Redis) DEL(keys ...string) int {
|
|
|
|
|
return rd.Do("DEL", stringsToAnys(keys)...).Int()
|
|
|
|
|
}
|
|
|
|
|
func (rd *Redis) EXISTS(key string) bool {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("EXISTS", key).Bool()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) EXPIRE(key string, second int) bool {
|
|
|
|
|
if second > 315360000 {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("EXPIREAT", key, second).Bool()
|
2026-05-03 08:43:23 +08:00
|
|
|
} else {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("EXPIRE", key, second).Bool()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
func (rd *Redis) KEYS(patten string) []string {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("KEYS", patten).Strings()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (rd *Redis) GET(key string) *Result {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("GET", key)
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) SET(key string, value any) bool {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("SET", key, value).Bool()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) SETEX(key string, seconds int, value any) bool {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("SETEX", key, seconds, value).Bool()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) SETNX(key string, value any) bool {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("SETNX", key, value).Bool()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) GETSET(key string, value any) *Result {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("GETSET", key, value)
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (rd *Redis) INCR(key string) int64 {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("INCR", key).Int64()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) INCRBY(key string, delta int64) int64 {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("INCRBY", key, delta).Int64()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) DECR(key string, delta int64) int64 {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("DECR", key, delta).Int64()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) DECRBY(key string, delta int64) int64 {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("DECRBY", key, delta).Int64()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (rd *Redis) MGET(keys ...string) []Result {
|
|
|
|
|
return rd.Do("MGET", stringsToAnys(keys)...).Results()
|
|
|
|
|
}
|
|
|
|
|
func (rd *Redis) MSET(keyAndValues ...any) bool {
|
|
|
|
|
return rd.Do("MSET", keyAndValues...).Bool()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (rd *Redis) HGET(key, field string) *Result {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("HGET", key, field)
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) HSET(key, field string, value any) bool {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("HSET", key, field, value).Error == nil
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) HSETNX(key, field string, value any) bool {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("HSETNX", key, field, value).Error == nil
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) HMGET(key string, fields ...string) []Result {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("HMGET", append([]any{key}, stringsToAnys(fields)...)...).Results()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) HGETALL(key string) map[string]*Result {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("HGETALL", key).ResultMap()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) HMSET(key string, fieldAndValues ...any) bool {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("HMSET", append([]any{key}, fieldAndValues...)...).Bool()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) HKEYS(key string) []string {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("HKEYS", key).Strings()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) HLEN(key string) int {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("HLEN", key).Int()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) HDEL(key string, fields ...string) int {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("HDEL", append([]any{key}, stringsToAnys(fields)...)...).Int()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) HEXISTS(key, field string) bool {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("HEXISTS", key, field).Bool()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) HINCR(key, field string) int64 {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("HINCRBY", key, field, 1).Int64()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) HINCRBY(key, field string, delta int64) int64 {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("HINCRBY", key, field, delta).Int64()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) HDECR(key, field string) int64 {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("HDECRBY", key, field, 1).Int64()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) HDECRBY(key, field string, delta int64) int64 {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("HDECRBY", key, field, delta).Int64()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (rd *Redis) LPUSH(key string, values ...string) int {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("LPUSH", append([]any{key}, stringsToAnys(values)...)...).Int()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) RPUSH(key string, values ...string) int {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("RPUSH", append([]any{key}, stringsToAnys(values)...)...).Int()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) LPOP(key string) *Result {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("LPOP", key)
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) RPOP(key string) *Result {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("RPOP", key)
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) LLEN(key string) int {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("LLEN", key).Int()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) LRANGE(key string, start, stop int) []Result {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("LRANGE", key, start, stop).Results()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (rd *Redis) SADD(key string, values ...any) int {
|
|
|
|
|
return rd.Do("SADD", append([]any{key}, values...)...).Int()
|
|
|
|
|
}
|
|
|
|
|
func (rd *Redis) SREM(key string, values ...any) int {
|
|
|
|
|
return rd.Do("SREM", append([]any{key}, values...)...).Int()
|
|
|
|
|
}
|
|
|
|
|
func (rd *Redis) SCARD(key string) int {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("SCARD", key).Int()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) SMEMBERS(key string) []Result {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("SMEMBERS", key).Results()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) SISMEMBER(key string, value any) bool {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("SISMEMBER", key, value).Bool()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (rd *Redis) ZADD(key string, score float64, member any) bool {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("ZADD", key, score, member).Bool()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) ZREM(key string, members ...any) int {
|
|
|
|
|
return rd.Do("ZREM", append([]any{key}, members...)...).Int()
|
|
|
|
|
}
|
|
|
|
|
func (rd *Redis) ZCARD(key string) int {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("ZCARD", key).Int()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) ZRANGE(key string, start, stop int) []Result {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("ZRANGE", key, start, stop).Results()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) ZREVRANGE(key string, start, stop int) []Result {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("ZREVRANGE", key, start, stop).Results()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) ZRANK(key string, member any) int {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("ZRANK", key, member).Int()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) ZREVRANK(key string, member any) int {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("ZREVRANK", key, member).Int()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|
|
|
|
|
func (rd *Redis) ZSCORE(key string, member any) float64 {
|
2026-05-04 00:46:17 +08:00
|
|
|
return rd.Do("ZSCORE", key, member).Float64()
|
2026-05-03 08:43:23 +08:00
|
|
|
}
|