Skip to content

Commit

Permalink
fix: redis实现的全部分组不公开成员则无法覆盖内部的Do
Browse files Browse the repository at this point in the history
  • Loading branch information
hailaz authored and houseme committed Dec 19, 2023
1 parent 7975e39 commit 0cd5e8d
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 128 deletions.
48 changes: 24 additions & 24 deletions contrib/nosql/redis/redis_group_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import (

// GroupGeneric provides generic functions of redis.
type GroupGeneric struct {
redis *Redis
Redis gredis.Adapter
}

// GroupGeneric creates and returns GroupGeneric.
func (r *Redis) GroupGeneric() gredis.IGroupGeneric {
return GroupGeneric{
redis: r,
Redis: r,
}
}

Expand All @@ -45,7 +45,7 @@ func (r GroupGeneric) Copy(ctx context.Context, source, destination string, opti
if len(option) > 0 {
usedOption = option[0]
}
v, err := r.redis.Do(ctx, "Copy", mustMergeOptionToArgs(
v, err := r.Redis.Do(ctx, "Copy", mustMergeOptionToArgs(
[]interface{}{source, destination}, usedOption,
)...)
return v.Int64(), err
Expand All @@ -59,7 +59,7 @@ func (r GroupGeneric) Copy(ctx context.Context, source, destination string, opti
//
// https://redis.io/commands/exists/
func (r GroupGeneric) Exists(ctx context.Context, keys ...string) (int64, error) {
v, err := r.redis.Do(ctx, "Exists", gconv.Interfaces(keys)...)
v, err := r.Redis.Do(ctx, "Exists", gconv.Interfaces(keys)...)
return v.Int64(), err
}

Expand All @@ -70,7 +70,7 @@ func (r GroupGeneric) Exists(ctx context.Context, keys ...string) (int64, error)
//
// https://redis.io/commands/type/
func (r GroupGeneric) Type(ctx context.Context, key string) (string, error) {
v, err := r.redis.Do(ctx, "Type", key)
v, err := r.Redis.Do(ctx, "Type", key)
return v.String(), err
}

Expand All @@ -83,7 +83,7 @@ func (r GroupGeneric) Type(ctx context.Context, key string) (string, error) {
//
// https://redis.io/commands/unlink/
func (r GroupGeneric) Unlink(ctx context.Context, keys ...string) (int64, error) {
v, err := r.redis.Do(ctx, "Unlink", gconv.Interfaces(keys)...)
v, err := r.Redis.Do(ctx, "Unlink", gconv.Interfaces(keys)...)
return v.Int64(), err
}

Expand All @@ -96,7 +96,7 @@ func (r GroupGeneric) Unlink(ctx context.Context, keys ...string) (int64, error)
//
// https://redis.io/commands/rename/
func (r GroupGeneric) Rename(ctx context.Context, key, newKey string) error {
_, err := r.redis.Do(ctx, "Rename", key, newKey)
_, err := r.Redis.Do(ctx, "Rename", key, newKey)
return err
}

Expand All @@ -111,7 +111,7 @@ func (r GroupGeneric) Rename(ctx context.Context, key, newKey string) error {
//
// https://redis.io/commands/renamenx/
func (r GroupGeneric) RenameNX(ctx context.Context, key, newKey string) (int64, error) {
v, err := r.redis.Do(ctx, "RenameNX", key, newKey)
v, err := r.Redis.Do(ctx, "RenameNX", key, newKey)
return v.Int64(), err
}

Expand All @@ -126,7 +126,7 @@ func (r GroupGeneric) RenameNX(ctx context.Context, key, newKey string) (int64,
//
// https://redis.io/commands/move/
func (r GroupGeneric) Move(ctx context.Context, key string, db int) (int64, error) {
v, err := r.redis.Do(ctx, "Move", key, db)
v, err := r.Redis.Do(ctx, "Move", key, db)
return v.Int64(), err
}

Expand All @@ -137,7 +137,7 @@ func (r GroupGeneric) Move(ctx context.Context, key string, db int) (int64, erro
//
// https://redis.io/commands/del/
func (r GroupGeneric) Del(ctx context.Context, keys ...string) (int64, error) {
v, err := r.redis.Do(ctx, "Del", gconv.Interfaces(keys)...)
v, err := r.Redis.Do(ctx, "Del", gconv.Interfaces(keys)...)
return v.Int64(), err
}

Expand All @@ -147,15 +147,15 @@ func (r GroupGeneric) Del(ctx context.Context, keys ...string) (int64, error) {
//
// https://redis.io/commands/randomkey/
func (r GroupGeneric) RandomKey(ctx context.Context) (string, error) {
v, err := r.redis.Do(ctx, "RandomKey")
v, err := r.Redis.Do(ctx, "RandomKey")
return v.String(), err
}

// DBSize return the number of keys in the currently-selected database.
//
// https://redis.io/commands/dbsize/
func (r GroupGeneric) DBSize(ctx context.Context) (int64, error) {
v, err := r.redis.Do(ctx, "DBSize")
v, err := r.Redis.Do(ctx, "DBSize")
return v.Int64(), err
}

Expand All @@ -166,15 +166,15 @@ func (r GroupGeneric) DBSize(ctx context.Context) (int64, error) {
//
// https://redis.io/commands/keys/
func (r GroupGeneric) Keys(ctx context.Context, pattern string) ([]string, error) {
v, err := r.redis.Do(ctx, "Keys", pattern)
v, err := r.Redis.Do(ctx, "Keys", pattern)
return v.Strings(), err
}

// FlushDB delete all the keys of the currently selected DB. This command never fails.
//
// https://redis.io/commands/flushdb/
func (r GroupGeneric) FlushDB(ctx context.Context, option ...gredis.FlushOp) error {
_, err := r.redis.Do(ctx, "FlushDB", gconv.Interfaces(option)...)
_, err := r.Redis.Do(ctx, "FlushDB", gconv.Interfaces(option)...)
return err
}

Expand All @@ -191,7 +191,7 @@ func (r GroupGeneric) FlushDB(ctx context.Context, option ...gredis.FlushOp) err
//
// https://redis.io/commands/flushall/
func (r GroupGeneric) FlushAll(ctx context.Context, option ...gredis.FlushOp) error {
_, err := r.redis.Do(ctx, "FlushAll", gconv.Interfaces(option)...)
_, err := r.Redis.Do(ctx, "FlushAll", gconv.Interfaces(option)...)
return err
}

Expand All @@ -208,7 +208,7 @@ func (r GroupGeneric) Expire(ctx context.Context, key string, seconds int64, opt
if len(option) > 0 {
usedOption = option[0]
}
v, err := r.redis.Do(ctx, "Expire", mustMergeOptionToArgs(
v, err := r.Redis.Do(ctx, "Expire", mustMergeOptionToArgs(
[]interface{}{key, seconds}, usedOption,
)...)
return v.Int64(), err
Expand All @@ -229,7 +229,7 @@ func (r GroupGeneric) ExpireAt(ctx context.Context, key string, time time.Time,
if len(option) > 0 {
usedOption = option[0]
}
v, err := r.redis.Do(ctx, "ExpireAt", mustMergeOptionToArgs(
v, err := r.Redis.Do(ctx, "ExpireAt", mustMergeOptionToArgs(
[]interface{}{key, gtime.New(time).Timestamp()}, usedOption,
)...)
return v.Int64(), err
Expand All @@ -243,7 +243,7 @@ func (r GroupGeneric) ExpireAt(ctx context.Context, key string, time time.Time,
//
// https://redis.io/commands/expiretime/
func (r GroupGeneric) ExpireTime(ctx context.Context, key string) (*gvar.Var, error) {
return r.redis.Do(ctx, "ExpireTime", key)
return r.Redis.Do(ctx, "ExpireTime", key)
}

// TTL returns the remaining time to live of a key that has a timeout.
Expand All @@ -263,7 +263,7 @@ func (r GroupGeneric) ExpireTime(ctx context.Context, key string) (*gvar.Var, er
//
// https://redis.io/commands/ttl/
func (r GroupGeneric) TTL(ctx context.Context, key string) (int64, error) {
v, err := r.redis.Do(ctx, "TTL", key)
v, err := r.Redis.Do(ctx, "TTL", key)
return v.Int64(), err
}

Expand All @@ -276,7 +276,7 @@ func (r GroupGeneric) TTL(ctx context.Context, key string) (int64, error) {
//
// https://redis.io/commands/persist/
func (r GroupGeneric) Persist(ctx context.Context, key string) (int64, error) {
v, err := r.redis.Do(ctx, "Persist", key)
v, err := r.Redis.Do(ctx, "Persist", key)
return v.Int64(), err
}

Expand All @@ -293,7 +293,7 @@ func (r GroupGeneric) PExpire(ctx context.Context, key string, milliseconds int6
if len(option) > 0 {
usedOption = option[0]
}
v, err := r.redis.Do(ctx, "PExpire", mustMergeOptionToArgs(
v, err := r.Redis.Do(ctx, "PExpire", mustMergeOptionToArgs(
[]interface{}{key, milliseconds}, usedOption,
)...)
return v.Int64(), err
Expand All @@ -308,7 +308,7 @@ func (r GroupGeneric) PExpireAt(ctx context.Context, key string, time time.Time,
if len(option) > 0 {
usedOption = option[0]
}
v, err := r.redis.Do(ctx, "PExpireAt", mustMergeOptionToArgs(
v, err := r.Redis.Do(ctx, "PExpireAt", mustMergeOptionToArgs(
[]interface{}{key, gtime.New(time).TimestampMilli()}, usedOption,
)...)
return v.Int64(), err
Expand All @@ -322,7 +322,7 @@ func (r GroupGeneric) PExpireAt(ctx context.Context, key string, time time.Time,
//
// https://redis.io/commands/pexpiretime/
func (r GroupGeneric) PExpireTime(ctx context.Context, key string) (*gvar.Var, error) {
return r.redis.Do(ctx, "PExpireTime", key)
return r.Redis.Do(ctx, "PExpireTime", key)
}

// PTTL like TTL this command returns the remaining time to live of a key that has an expired set,
Expand All @@ -336,6 +336,6 @@ func (r GroupGeneric) PExpireTime(ctx context.Context, key string) (*gvar.Var, e
//
// https://redis.io/commands/pttl/
func (r GroupGeneric) PTTL(ctx context.Context, key string) (int64, error) {
v, err := r.redis.Do(ctx, "PTTL", key)
v, err := r.Redis.Do(ctx, "PTTL", key)
return v.Int64(), err
}
32 changes: 16 additions & 16 deletions contrib/nosql/redis/redis_group_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import (

// GroupHash is the redis group object for hash operations.
type GroupHash struct {
redis *Redis
Redis gredis.Adapter
}

// GroupHash creates and returns a redis group object for hash operations.
func (r *Redis) GroupHash() gredis.IGroupHash {
return GroupHash{
redis: r,
Redis: r,
}
}

Expand All @@ -38,7 +38,7 @@ func (r GroupHash) HSet(ctx context.Context, key string, fields map[string]inter
for k, v := range fields {
s = append(s, k, v)
}
v, err := r.redis.Do(ctx, "HSet", s...)
v, err := r.Redis.Do(ctx, "HSet", s...)
return v.Int64(), err
}

Expand All @@ -52,7 +52,7 @@ func (r GroupHash) HSet(ctx context.Context, key string, fields map[string]inter
//
// https://redis.io/commands/hsetnx/
func (r GroupHash) HSetNX(ctx context.Context, key, field string, value interface{}) (int64, error) {
v, err := r.redis.Do(ctx, "HSetNX", key, field, value)
v, err := r.Redis.Do(ctx, "HSetNX", key, field, value)
return v.Int64(), err
}

Expand All @@ -62,7 +62,7 @@ func (r GroupHash) HSetNX(ctx context.Context, key, field string, value interfac
//
// https://redis.io/commands/hget/
func (r GroupHash) HGet(ctx context.Context, key, field string) (*gvar.Var, error) {
v, err := r.redis.Do(ctx, "HGet", key, field)
v, err := r.Redis.Do(ctx, "HGet", key, field)
return v, err
}

Expand All @@ -74,7 +74,7 @@ func (r GroupHash) HGet(ctx context.Context, key, field string) (*gvar.Var, erro
//
// https://redis.io/commands/hstrlen/
func (r GroupHash) HStrLen(ctx context.Context, key, field string) (int64, error) {
v, err := r.redis.Do(ctx, "HSTRLEN", key, field)
v, err := r.Redis.Do(ctx, "HSTRLEN", key, field)
return v.Int64(), err
}

Expand All @@ -86,7 +86,7 @@ func (r GroupHash) HStrLen(ctx context.Context, key, field string) (int64, error
//
// https://redis.io/commands/hexists/
func (r GroupHash) HExists(ctx context.Context, key, field string) (int64, error) {
v, err := r.redis.Do(ctx, "HExists", key, field)
v, err := r.Redis.Do(ctx, "HExists", key, field)
return v.Int64(), err
}

Expand All @@ -98,15 +98,15 @@ func (r GroupHash) HExists(ctx context.Context, key, field string) (int64, error
//
// https://redis.io/commands/hdel/
func (r GroupHash) HDel(ctx context.Context, key string, fields ...string) (int64, error) {
v, err := r.redis.Do(ctx, "HDel", append([]interface{}{key}, gconv.Interfaces(fields)...)...)
v, err := r.Redis.Do(ctx, "HDel", append([]interface{}{key}, gconv.Interfaces(fields)...)...)
return v.Int64(), err
}

// HLen returns the number of fields contained in the hash stored at key.
//
// https://redis.io/commands/hlen/
func (r GroupHash) HLen(ctx context.Context, key string) (int64, error) {
v, err := r.redis.Do(ctx, "HLen", key)
v, err := r.Redis.Do(ctx, "HLen", key)
return v.Int64(), err
}

Expand All @@ -118,7 +118,7 @@ func (r GroupHash) HLen(ctx context.Context, key string) (int64, error) {
//
// https://redis.io/commands/hincrby/
func (r GroupHash) HIncrBy(ctx context.Context, key, field string, increment int64) (int64, error) {
v, err := r.redis.Do(ctx, "HIncrBy", key, field, increment)
v, err := r.Redis.Do(ctx, "HIncrBy", key, field, increment)
return v.Int64(), err
}

Expand All @@ -138,7 +138,7 @@ func (r GroupHash) HIncrBy(ctx context.Context, key, field string, increment int
//
// https://redis.io/commands/hincrbyfloat/
func (r GroupHash) HIncrByFloat(ctx context.Context, key, field string, increment float64) (float64, error) {
v, err := r.redis.Do(ctx, "HIncrByFloat", key, field, increment)
v, err := r.Redis.Do(ctx, "HIncrByFloat", key, field, increment)
return v.Float64(), err
}

Expand All @@ -152,7 +152,7 @@ func (r GroupHash) HMSet(ctx context.Context, key string, fields map[string]inte
for k, v := range fields {
s = append(s, k, v)
}
_, err := r.redis.Do(ctx, "HMSet", s...)
_, err := r.Redis.Do(ctx, "HMSet", s...)
return err
}

Expand All @@ -163,23 +163,23 @@ func (r GroupHash) HMSet(ctx context.Context, key string, fields map[string]inte
//
// https://redis.io/commands/hmget/
func (r GroupHash) HMGet(ctx context.Context, key string, fields ...string) (gvar.Vars, error) {
v, err := r.redis.Do(ctx, "HMGet", append([]interface{}{key}, gconv.Interfaces(fields)...)...)
v, err := r.Redis.Do(ctx, "HMGet", append([]interface{}{key}, gconv.Interfaces(fields)...)...)
return v.Vars(), err
}

// HKeys returns all field names in the hash stored at key.
//
// https://redis.io/commands/hkeys/
func (r GroupHash) HKeys(ctx context.Context, key string) ([]string, error) {
v, err := r.redis.Do(ctx, "HKeys", key)
v, err := r.Redis.Do(ctx, "HKeys", key)
return v.Strings(), err
}

// HVals return all values in the hash stored at key.
//
// https://redis.io/commands/hvals/
func (r GroupHash) HVals(ctx context.Context, key string) (gvar.Vars, error) {
v, err := r.redis.Do(ctx, "HVals", key)
v, err := r.Redis.Do(ctx, "HVals", key)
return v.Vars(), err
}

Expand All @@ -189,6 +189,6 @@ func (r GroupHash) HVals(ctx context.Context, key string) (gvar.Vars, error) {
//
// https://redis.io/commands/hgetall/
func (r GroupHash) HGetAll(ctx context.Context, key string) (*gvar.Var, error) {
v, err := r.redis.Do(ctx, "HGetAll", key)
v, err := r.Redis.Do(ctx, "HGetAll", key)
return v, err
}
Loading

0 comments on commit 0cd5e8d

Please # to comment.