浏览代码

feat:新增方法

wangchuanjin 3 年之前
父节点
当前提交
2fef79005d
共有 2 个文件被更改,包括 23 次插入1 次删除
  1. 18 0
      redis/redis.go
  2. 5 1
      redis/redis_test.go

+ 18 - 0
redis/redis.go

@@ -539,6 +539,24 @@ 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()
+	defer conn.Close()
+	ret, err := conn.Do("ZRANGEBYSCORE", key, min, max, "WITHSCORES")
+	r := []string{}
+	if nil != err {
+		log.Println("redisutil-ZRANGEBYSCORE error", err)
+		return r
+	}
+	if res, ok := ret.([]interface{}); ok {
+		for _, v := range res {
+			r = append(r, string(v.([]uint8)))
+		}
+	}
+	return r
+}
+
 func Zrem(code, key string, member ...string) int64 {
 	defer catch()
 	conn := RedisPool[code].Get()

+ 5 - 1
redis/redis_test.go

@@ -14,7 +14,11 @@ func TestZadd(t *testing.T) {
 }
 
 func TestZrevrangebyscore(t *testing.T) {
-	t.Log(Zrevrangebyscore("main", "test", "+inf", "-inf"))
+	t.Log(Zrevrangebyscore("main", "customerservice_list_14184", "+inf", "-inf"))
+}
+
+func TestZrangebyscore(t *testing.T) {
+	t.Log(Zrangebyscore("main", "customerservice_list_14184", 4, "+inf"))
 }
 
 func TestZrem(t *testing.T) {