feat: 增加 ZRangeByScore ZRemRangeByScore ZRangeAndRemByScore
This commit is contained in:
21
wrapper.go
21
wrapper.go
@@ -111,3 +111,24 @@ func (w *wrapper) BLPop(ctx context.Context, instanceFlag string, key []string,
|
||||
paramList = append(paramList, timeout)
|
||||
return Client.Exec(ctx, instanceFlag, consts.RedisCommandBlpop, paramList...)
|
||||
}
|
||||
|
||||
// ZRangeByScore 按分值获取数据
|
||||
func (w *wrapper) ZRangeByScore(ctx context.Context, instanceFlag string, key string, startScore int64, endScore int64) *define.RedisResult {
|
||||
return Client.Exec(ctx, instanceFlag, consts.RedisCommandZrangeByScore, key, startScore, endScore, "WITHSCORES")
|
||||
}
|
||||
|
||||
// ZRemRangeByScore 删除集合中分值区间的数据
|
||||
func (w *wrapper) ZRemRangeByScore(ctx context.Context, instanceFlag string, key string, startScore int64, endScore int64) *define.RedisResult {
|
||||
return Client.Exec(ctx, instanceFlag, consts.RedisCommandZRemRangeByScore, key, startScore, endScore)
|
||||
}
|
||||
|
||||
// ZRangeAndRemByScore 获取集合到期数据并删除
|
||||
// 本质: ZRange + ZRemRangeByScore
|
||||
func (w *wrapper) ZRangeAndRemByScore(ctx context.Context, instanceFlag string, key string, startScore int64, endScore int64) *define.RedisResult {
|
||||
rangeRes := w.ZRangeByScore(ctx, instanceFlag, key, startScore, endScore)
|
||||
if nil == rangeRes.Err {
|
||||
// 读取成功, 删除
|
||||
w.ZRemRangeByScore(ctx, instanceFlag, key, startScore, endScore)
|
||||
}
|
||||
return rangeRes
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user