feat: 增加 ZRangeByScore ZRemRangeByScore ZRangeAndRemByScore

This commit is contained in:
2026-04-13 16:26:18 +08:00
parent beae868232
commit 2adbe2bcd3
3 changed files with 24 additions and 1 deletions

View File

@@ -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
}