zset.go
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package redis
import (
"errors"
"github.com/gomodule/redigo/redis"
)
//设置集合
func Zadd(key string, score float64, member interface{}) error {
if len(key) < 1 {
return errors.New("Invalid argument")
}
c := redisPool.Get()
defer c.Close()
var err error
_, err = c.Do("ZADD", key, score, member)
if err != nil {
return err
}
return nil
}
//有序集合中对指定成员的分数加上增量 increment
func Zincrby(key string, increment int64, member interface{}) error {
if len(key) < 1 {
return errors.New("Invalid argument")
}
c := redisPool.Get()
defer c.Close()
var err error
_, err = c.Do("ZINCRBY", key, increment, member)
if err != nil {
return err
}
return nil
}
// 有序集合中对指定成员的分数加上增量 increment
// 注意:次函数只能获取member是整形的情况,如遇到member不少整形的情况需要另外函数
func Zrevrange(key string, start, stop int64) ([]string, error) {
if len(key) < 1 {
return nil, errors.New("Invalid argument")
}
c := redisPool.Get()
defer c.Close()
datas, err := redis.Strings(c.Do("ZREVRANGE", key, start, stop, "WITHSCORES"))
if err != nil {
return nil, err
}
return datas, nil
}