mirror of
https://github.com/redis/go-redis.git
synced 2025-07-28 06:42:00 +03:00
perf: reduce unnecessary memory allocation (#3399)
Signed-off-by: fukua95 <fukua95@gmail.com> Co-authored-by: Nedyalko Dyakov <1547186+ndyakov@users.noreply.github.com>
This commit is contained in:
@ -1116,18 +1116,14 @@ func (c cmdable) TopKListWithCount(ctx context.Context, key string) *MapStringIn
|
||||
// Returns OK on success or an error if the operation could not be completed.
|
||||
// For more information - https://redis.io/commands/tdigest.add/
|
||||
func (c cmdable) TDigestAdd(ctx context.Context, key string, elements ...float64) *StatusCmd {
|
||||
args := make([]interface{}, 2, 2+len(elements))
|
||||
args := make([]interface{}, 2+len(elements))
|
||||
args[0] = "TDIGEST.ADD"
|
||||
args[1] = key
|
||||
|
||||
// Convert floatSlice to []interface{}
|
||||
interfaceSlice := make([]interface{}, len(elements))
|
||||
for i, v := range elements {
|
||||
interfaceSlice[i] = v
|
||||
args[2+i] = v
|
||||
}
|
||||
|
||||
args = append(args, interfaceSlice...)
|
||||
|
||||
cmd := NewStatusCmd(ctx, args...)
|
||||
_ = c(ctx, cmd)
|
||||
return cmd
|
||||
@ -1138,18 +1134,14 @@ func (c cmdable) TDigestAdd(ctx context.Context, key string, elements ...float64
|
||||
// Returns an array of floats representing the values at the specified ranks or an error if the operation could not be completed.
|
||||
// For more information - https://redis.io/commands/tdigest.byrank/
|
||||
func (c cmdable) TDigestByRank(ctx context.Context, key string, rank ...uint64) *FloatSliceCmd {
|
||||
args := make([]interface{}, 2, 2+len(rank))
|
||||
args := make([]interface{}, 2+len(rank))
|
||||
args[0] = "TDIGEST.BYRANK"
|
||||
args[1] = key
|
||||
|
||||
// Convert uint slice to []interface{}
|
||||
interfaceSlice := make([]interface{}, len(rank))
|
||||
for i, v := range rank {
|
||||
interfaceSlice[i] = v
|
||||
for i, r := range rank {
|
||||
args[2+i] = r
|
||||
}
|
||||
|
||||
args = append(args, interfaceSlice...)
|
||||
|
||||
cmd := NewFloatSliceCmd(ctx, args...)
|
||||
_ = c(ctx, cmd)
|
||||
return cmd
|
||||
@ -1160,18 +1152,14 @@ func (c cmdable) TDigestByRank(ctx context.Context, key string, rank ...uint64)
|
||||
// Returns an array of floats representing the values at the specified ranks or an error if the operation could not be completed.
|
||||
// For more information - https://redis.io/commands/tdigest.byrevrank/
|
||||
func (c cmdable) TDigestByRevRank(ctx context.Context, key string, rank ...uint64) *FloatSliceCmd {
|
||||
args := make([]interface{}, 2, 2+len(rank))
|
||||
args := make([]interface{}, 2+len(rank))
|
||||
args[0] = "TDIGEST.BYREVRANK"
|
||||
args[1] = key
|
||||
|
||||
// Convert uint slice to []interface{}
|
||||
interfaceSlice := make([]interface{}, len(rank))
|
||||
for i, v := range rank {
|
||||
interfaceSlice[i] = v
|
||||
for i, r := range rank {
|
||||
args[2+i] = r
|
||||
}
|
||||
|
||||
args = append(args, interfaceSlice...)
|
||||
|
||||
cmd := NewFloatSliceCmd(ctx, args...)
|
||||
_ = c(ctx, cmd)
|
||||
return cmd
|
||||
@ -1182,18 +1170,14 @@ func (c cmdable) TDigestByRevRank(ctx context.Context, key string, rank ...uint6
|
||||
// Returns an array of floats representing the CDF values for each element or an error if the operation could not be completed.
|
||||
// For more information - https://redis.io/commands/tdigest.cdf/
|
||||
func (c cmdable) TDigestCDF(ctx context.Context, key string, elements ...float64) *FloatSliceCmd {
|
||||
args := make([]interface{}, 2, 2+len(elements))
|
||||
args := make([]interface{}, 2+len(elements))
|
||||
args[0] = "TDIGEST.CDF"
|
||||
args[1] = key
|
||||
|
||||
// Convert floatSlice to []interface{}
|
||||
interfaceSlice := make([]interface{}, len(elements))
|
||||
for i, v := range elements {
|
||||
interfaceSlice[i] = v
|
||||
args[2+i] = v
|
||||
}
|
||||
|
||||
args = append(args, interfaceSlice...)
|
||||
|
||||
cmd := NewFloatSliceCmd(ctx, args...)
|
||||
_ = c(ctx, cmd)
|
||||
return cmd
|
||||
@ -1376,18 +1360,14 @@ func (c cmdable) TDigestMin(ctx context.Context, key string) *FloatCmd {
|
||||
// Returns an array of floats representing the quantile values for each element or an error if the operation could not be completed.
|
||||
// For more information - https://redis.io/commands/tdigest.quantile/
|
||||
func (c cmdable) TDigestQuantile(ctx context.Context, key string, elements ...float64) *FloatSliceCmd {
|
||||
args := make([]interface{}, 2, 2+len(elements))
|
||||
args := make([]interface{}, 2+len(elements))
|
||||
args[0] = "TDIGEST.QUANTILE"
|
||||
args[1] = key
|
||||
|
||||
// Convert floatSlice to []interface{}
|
||||
interfaceSlice := make([]interface{}, len(elements))
|
||||
for i, v := range elements {
|
||||
interfaceSlice[i] = v
|
||||
args[2+i] = v
|
||||
}
|
||||
|
||||
args = append(args, interfaceSlice...)
|
||||
|
||||
cmd := NewFloatSliceCmd(ctx, args...)
|
||||
_ = c(ctx, cmd)
|
||||
return cmd
|
||||
@ -1398,18 +1378,14 @@ func (c cmdable) TDigestQuantile(ctx context.Context, key string, elements ...fl
|
||||
// Returns an array of integers representing the rank values for each element or an error if the operation could not be completed.
|
||||
// For more information - https://redis.io/commands/tdigest.rank/
|
||||
func (c cmdable) TDigestRank(ctx context.Context, key string, values ...float64) *IntSliceCmd {
|
||||
args := make([]interface{}, 2, 2+len(values))
|
||||
args := make([]interface{}, 2+len(values))
|
||||
args[0] = "TDIGEST.RANK"
|
||||
args[1] = key
|
||||
|
||||
// Convert floatSlice to []interface{}
|
||||
interfaceSlice := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
interfaceSlice[i] = v
|
||||
args[i+2] = v
|
||||
}
|
||||
|
||||
args = append(args, interfaceSlice...)
|
||||
|
||||
cmd := NewIntSliceCmd(ctx, args...)
|
||||
_ = c(ctx, cmd)
|
||||
return cmd
|
||||
@ -1431,18 +1407,14 @@ func (c cmdable) TDigestReset(ctx context.Context, key string) *StatusCmd {
|
||||
// Returns an array of integers representing the reverse rank values for each element or an error if the operation could not be completed.
|
||||
// For more information - https://redis.io/commands/tdigest.revrank/
|
||||
func (c cmdable) TDigestRevRank(ctx context.Context, key string, values ...float64) *IntSliceCmd {
|
||||
args := make([]interface{}, 2, 2+len(values))
|
||||
args := make([]interface{}, 2+len(values))
|
||||
args[0] = "TDIGEST.REVRANK"
|
||||
args[1] = key
|
||||
|
||||
// Convert floatSlice to []interface{}
|
||||
interfaceSlice := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
interfaceSlice[i] = v
|
||||
args[2+i] = v
|
||||
}
|
||||
|
||||
args = append(args, interfaceSlice...)
|
||||
|
||||
cmd := NewIntSliceCmd(ctx, args...)
|
||||
_ = c(ctx, cmd)
|
||||
return cmd
|
||||
|
Reference in New Issue
Block a user