1
0
mirror of https://github.com/redis/go-redis.git synced 2025-04-19 07:22:17 +03:00

fix types

This commit is contained in:
ofekshenawa 2025-03-18 20:36:09 +02:00
parent 26c1370a92
commit 2c446fae2b

View File

@ -10,9 +10,9 @@ type HashCmdable interface {
HExists(ctx context.Context, key, field string) *BoolCmd HExists(ctx context.Context, key, field string) *BoolCmd
HGet(ctx context.Context, key, field string) *StringCmd HGet(ctx context.Context, key, field string) *StringCmd
HGetAll(ctx context.Context, key string) *MapStringStringCmd HGetAll(ctx context.Context, key string) *MapStringStringCmd
HGetDel(ctx context.Context, key string, fields ...string) *IntSliceCmd HGetDel(ctx context.Context, key string, fields ...string) *StringSliceCmd
HGetEX(ctx context.Context, key string, fields ...string) *IntSliceCmd HGetEX(ctx context.Context, key string, fields ...string) *StringSliceCmd
HGetEXWithArgs(ctx context.Context, key string, expirationType HGetEXExpirationType, expirationVal int64, fields ...string) *IntSliceCmd HGetEXWithArgs(ctx context.Context, key string, expirationType HGetEXExpirationType, expirationVal int64, fields ...string) *StringSliceCmd
HIncrBy(ctx context.Context, key, field string, incr int64) *IntCmd HIncrBy(ctx context.Context, key, field string, incr int64) *IntCmd
HIncrByFloat(ctx context.Context, key, field string, incr float64) *FloatCmd HIncrByFloat(ctx context.Context, key, field string, incr float64) *FloatCmd
HKeys(ctx context.Context, key string) *StringSliceCmd HKeys(ctx context.Context, key string) *StringSliceCmd
@ -460,28 +460,27 @@ func (c cmdable) HPTTL(ctx context.Context, key string, fields ...string) *IntSl
return cmd return cmd
} }
// TODO check return type func (c cmdable) HGetDel(ctx context.Context, key string, fields ...string) *StringSliceCmd {
func (c cmdable) HGetDel(ctx context.Context, key string, fields ...string) *IntSliceCmd {
args := []interface{}{"HGETDEL", key, "FIELDS", len(fields)} args := []interface{}{"HGETDEL", key, "FIELDS", len(fields)}
for _, field := range fields { for _, field := range fields {
args = append(args, field) args = append(args, field)
} }
cmd := NewIntSliceCmd(ctx, args...) cmd := NewStringSliceCmd(ctx, args...)
_ = c(ctx, cmd) _ = c(ctx, cmd)
return cmd return cmd
} }
func (c cmdable) HGetEX(ctx context.Context, key string, fields ...string) *IntSliceCmd { func (c cmdable) HGetEX(ctx context.Context, key string, fields ...string) *StringSliceCmd {
args := []interface{}{"HGETEX", key, "FIELDS", len(fields)} args := []interface{}{"HGETEX", key, "FIELDS", len(fields)}
for _, field := range fields { for _, field := range fields {
args = append(args, field) args = append(args, field)
} }
cmd := NewIntSliceCmd(ctx, args...) cmd := NewStringSliceCmd(ctx, args...)
_ = c(ctx, cmd) _ = c(ctx, cmd)
return cmd return cmd
} }
// ExpirationType represents an expiration option for the hash commands. // ExpirationType represents an expiration option for the HGETEX command.
type HGetEXExpirationType string type HGetEXExpirationType string
const ( const (
@ -492,10 +491,9 @@ const (
HGetEXExpirationPERSIST HGetEXExpirationType = "PERSIST" HGetEXExpirationPERSIST HGetEXExpirationType = "PERSIST"
) )
func (c cmdable) HGetEXWithArgs(ctx context.Context, key string, expirationType HGetEXExpirationType, expirationVal int64, fields ...string) *IntSliceCmd { func (c cmdable) HGetEXWithArgs(ctx context.Context, key string, expirationType HGetEXExpirationType, expirationVal int64, fields ...string) *StringSliceCmd {
args := []interface{}{"HGETEX", key} args := []interface{}{"HGETEX", key}
// Append expiration option and its value if necessary.
args = append(args, string(expirationType)) args = append(args, string(expirationType))
if expirationType != HGetEXExpirationPERSIST { if expirationType != HGetEXExpirationPERSIST {
args = append(args, expirationVal) args = append(args, expirationVal)
@ -506,7 +504,7 @@ func (c cmdable) HGetEXWithArgs(ctx context.Context, key string, expirationType
args = append(args, field) args = append(args, field)
} }
cmd := NewIntSliceCmd(ctx, args...) cmd := NewStringSliceCmd(ctx, args...)
_ = c(ctx, cmd) _ = c(ctx, cmd)
return cmd return cmd
} }
@ -535,7 +533,7 @@ type HSetXOptions struct {
} }
func (c cmdable) HSetEX(ctx context.Context, key string, fieldsAndValues ...string) *IntCmd { func (c cmdable) HSetEX(ctx context.Context, key string, fieldsAndValues ...string) *IntCmd {
args := []interface{}{"HSETEX", key, "FIELDS", len(fieldsAndValues)} args := []interface{}{"HSETEX", key, "FIELDS", len(fieldsAndValues) / 2}
for _, field := range fieldsAndValues { for _, field := range fieldsAndValues {
args = append(args, field) args = append(args, field)
} }
@ -546,7 +544,6 @@ func (c cmdable) HSetEX(ctx context.Context, key string, fieldsAndValues ...stri
} }
func (c cmdable) HSetEXWithArgs(ctx context.Context, key string, options *HSetXOptions, fieldsAndValues ...string) *IntCmd { func (c cmdable) HSetEXWithArgs(ctx context.Context, key string, options *HSetXOptions, fieldsAndValues ...string) *IntCmd {
// Start with the command name and key.
args := []interface{}{"HSETEX", key} args := []interface{}{"HSETEX", key}
if options.Condition != "" { if options.Condition != "" {
args = append(args, string(options.Condition)) args = append(args, string(options.Condition))
@ -557,12 +554,11 @@ func (c cmdable) HSetEXWithArgs(ctx context.Context, key string, options *HSetXO
args = append(args, options.ExpirationVal) args = append(args, options.ExpirationVal)
} }
} }
args = append(args, "FIELDS", len(fieldsAndValues)) args = append(args, "FIELDS", len(fieldsAndValues)/2)
for _, field := range fieldsAndValues { for _, field := range fieldsAndValues {
args = append(args, field) args = append(args, field)
} }
// Create and execute the command.
cmd := NewIntCmd(ctx, args...) cmd := NewIntCmd(ctx, args...)
_ = c(ctx, cmd) _ = c(ctx, cmd)
return cmd return cmd