mirror of
https://github.com/duanhf2012/origin.git
synced 2026-05-21 00:37:31 +08:00
ZSet operation
This commit is contained in:
@@ -1222,7 +1222,7 @@ func makeListJson(redisReply []interface{}, withScores bool) []byte {
|
|||||||
return buf.Bytes()
|
return buf.Bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (slf *RedisModule) ZRangeByScoreJSON(key string, start, stop int, ascend bool, withScores bool, data interface{}) error {
|
func (slf *RedisModule) ZRangeByScoreJSON(key string, start, stop float64, ascend bool, withScores bool, data interface{}) error {
|
||||||
if withScores {
|
if withScores {
|
||||||
if _, ok := data.(*[]ZSetDataWithScore); !ok {
|
if _, ok := data.(*[]ZSetDataWithScore); !ok {
|
||||||
return errors.New("withScores must decode by []ZSetDataWithScore")
|
return errors.New("withScores must decode by []ZSetDataWithScore")
|
||||||
@@ -1241,7 +1241,7 @@ func (slf *RedisModule) ZRangeByScoreJSON(key string, start, stop int, ascend bo
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (slf *RedisModule) ZRangeByScore(key string, start, stop int, ascend bool, withScores bool) ([]byte, error) {
|
func (slf *RedisModule) ZRangeByScore(key string, start, stop float64, ascend bool, withScores bool) ([]byte, error) {
|
||||||
conn, err := slf.getConn()
|
conn, err := slf.getConn()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -1263,6 +1263,41 @@ func (slf *RedisModule) ZRangeByScore(key string, start, stop int, ascend bool,
|
|||||||
return makeListJson(reply.([]interface{}), withScores), nil
|
return makeListJson(reply.([]interface{}), withScores), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//获取指定member的排名
|
||||||
|
func (slf *RedisModule) ZScore(key string, member interface{}) (float64, error) {
|
||||||
|
conn, err := slf.getConn()
|
||||||
|
if err != nil {
|
||||||
|
return -1, err
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
cmd := "ZSCORE"
|
||||||
|
var reply interface{}
|
||||||
|
reply, err = conn.Do(cmd, key, member)
|
||||||
|
if err != nil {
|
||||||
|
return -1, err
|
||||||
|
}
|
||||||
|
return redis.Float64(reply, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取指定member的排名
|
||||||
|
func (slf *RedisModule) ZRank(key string, member interface{}, ascend bool) (int, error) {
|
||||||
|
conn, err := slf.getConn()
|
||||||
|
if err != nil {
|
||||||
|
return -1, err
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
cmd := "ZREVRANK"
|
||||||
|
if ascend {
|
||||||
|
cmd = "ZRANK"
|
||||||
|
}
|
||||||
|
var reply interface{}
|
||||||
|
reply, err = conn.Do(cmd, key, member)
|
||||||
|
if err != nil {
|
||||||
|
return -1, err
|
||||||
|
}
|
||||||
|
return redis.Int(reply, err)
|
||||||
|
}
|
||||||
|
|
||||||
func (slf *RedisModule) ZREMRANGEBYSCORE(key string, start, stop interface{}) error {
|
func (slf *RedisModule) ZREMRANGEBYSCORE(key string, start, stop interface{}) error {
|
||||||
conn, err := slf.getConn()
|
conn, err := slf.getConn()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user