Browse Source

feat:增加方法

wangchuanjin 3 years ago
parent
commit
f25d53ea0f
1 changed files with 23 additions and 0 deletions
  1. 23 0
      redis/redis.go

+ 23 - 0
redis/redis.go

@@ -505,6 +505,7 @@ func LLEN(code, list string) int64 {
 	}
 }
 
+//向有序集合添加一个,或者更新已存在成员的分数
 func Zadd(code, key string, score float64, value string) int64 {
 	defer catch()
 	conn := RedisPool[code].Get()
@@ -521,6 +522,7 @@ func Zadd(code, key string, score float64, value string) int64 {
 	}
 }
 
+//返回有序集中指定分数区间内的所有的成员。有序集成员按分数值递减(从大到小)的次序排列。
 func Zrevrangebyscore(code, key string, max, min interface{}) []string {
 	defer catch()
 	conn := RedisPool[code].Get()
@@ -539,6 +541,7 @@ func Zrevrangebyscore(code, key string, max, min interface{}) []string {
 	return r
 }
 
+//返回有序集合中指定分数区间的成员列表。有序集成员按分数值递增(从小到大)次序排列。
 func Zrangebyscore(code, key string, min, max interface{}) []string {
 	defer catch()
 	conn := RedisPool[code].Get()
@@ -557,6 +560,7 @@ func Zrangebyscore(code, key string, min, max interface{}) []string {
 	return r
 }
 
+//移除有序集合中的一个或多个成员
 func Zrem(code, key string, member ...string) int64 {
 	defer catch()
 	conn := RedisPool[code].Get()
@@ -576,6 +580,7 @@ func Zrem(code, key string, member ...string) int64 {
 	return -1
 }
 
+//返回有序集中指定成员的排名。其中有序集成员按分数值递增(从小到大)顺序排列。
 func Zrank(code, key, member string) int64 {
 	defer catch()
 	conn := RedisPool[code].Get()
@@ -591,6 +596,23 @@ func Zrank(code, key, member string) int64 {
 	return -1
 }
 
+//返回有序集合中指定成员的排名,有序集成员按分数值递减(从大到小)排序
+func Zrevrank(code, key, member string) int64 {
+	defer catch()
+	conn := RedisPool[code].Get()
+	defer conn.Close()
+	ret, err := conn.Do("ZREVRANK", key, member)
+	if nil != err {
+		log.Println("redisutil-ZREVRANK error", err)
+		return -1
+	}
+	if res, ok := ret.(int64); ok {
+		return res
+	}
+	return -1
+}
+
+//返回有序集中,成员的分数值
 func Zscore(code, key, member string) string {
 	defer catch()
 	conn := RedisPool[code].Get()
@@ -606,6 +628,7 @@ func Zscore(code, key, member string) string {
 	return ""
 }
 
+//有序集合中对指定成员的分数加上增量 increment
 func Zincrby(code, key string, increment float64, member string) int64 {
 	defer catch()
 	conn := RedisPool[code].Get()