123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- // Copyright 2019 getensh.com. All rights reserved.
- // Use of this source code is governed by getensh.com.
- package redis
- import (
- "fmt"
- "github.com/go-redis/redis"
- )
- func (p *Redis) ZRevRange(key string, start, stop int64) (res []string, err error) {
- // 安全检查
- if p == nil {
- return res, errRedis
- }
- if p.cluster {
- // 客户端安全检查
- if p.cclient == nil {
- return res, errRedisCClient
- }
- return p.cclient.ZRevRange(key, start, stop).Result()
- }
- // 客户端安全检查
- if p.client == nil {
- return res, errRedisClient
- }
- return p.client.ZRevRange(key, start, stop).Result()
- }
- func (p *Redis) ZRevRangeByScore(key string, max, min string, offset, count int64) (res []string, err error) {
- // 安全检查
- if p == nil {
- return res, errRedis
- }
- if p.cluster {
- // 客户端安全检查
- if p.cclient == nil {
- return res, errRedisCClient
- }
- return p.cclient.ZRevRangeByScore(key,
- redis.ZRangeBy{
- Min: min,
- Max: max,
- Offset: offset,
- Count: count,
- }).Result()
- }
- // 客户端安全检查
- if p.client == nil {
- return res, errRedisClient
- }
- return p.client.ZRevRangeByScore(key,
- redis.ZRangeBy{
- Min: min,
- Max: max,
- Offset: offset,
- Count: count,
- }).Result()
- }
- func (p *Redis) ZAdd(key string, score float64, member interface{}) (res int64, err error) {
- // 安全检查
- if p == nil {
- return res, errRedis
- }
- if p.cluster {
- // 客户端安全检查
- if p.cclient == nil {
- return res, errRedisCClient
- }
- return p.cclient.ZAdd(key,
- redis.Z{
- Score: score,
- Member: member,
- }).Result()
- }
- // 客户端安全检查
- if p.client == nil {
- return res, errRedisClient
- }
- return p.client.ZAdd(key,
- redis.Z{
- Score: score,
- Member: member,
- }).Result()
- }
- func (p *Redis) ZCount(key, min, max string) (res int64, err error) {
- // 安全检查
- if p == nil {
- return res, errRedis
- }
- if p.cluster {
- // 客户端安全检查
- if p.cclient == nil {
- return res, errRedisCClient
- }
- return p.cclient.ZCount(key, min, max).Result()
- }
- // 客户端安全检查
- if p.client == nil {
- return res, errRedisClient
- }
- return p.client.ZCount(key, min, max).Result()
- }
- func (p *Redis) ZScore(key, member string) (res float64, err error) {
- // 安全检查
- if p == nil {
- return res, errRedis
- }
- if p.cluster {
- // 客户端安全检查
- if p.cclient == nil {
- return res, errRedisCClient
- }
- return p.cclient.ZScore(key, member).Result()
- }
- // 客户端安全检查
- if p.client == nil {
- return res, errRedisClient
- }
- return p.client.ZScore(key, member).Result()
- }
- func (p *Redis) ZRange(key string, start, stop int64) (res []string, err error) {
- // 安全检查
- if p == nil {
- return res, errRedis
- }
- if p.cluster {
- // 客户端安全检查
- if p.cclient == nil {
- return res, errRedisCClient
- }
- return p.cclient.ZRange(key, start, stop).Result()
- }
- // 客户端安全检查
- if p.client == nil {
- return res, errRedisClient
- }
- return p.client.ZRange(key, start, stop).Result()
- }
- func (p *Redis) ZIncrBy(key string, incr float64, member string) (res float64, err error) {
- // 安全检查
- if p == nil {
- return res, errRedis
- }
- if p.cluster {
- // 客户端安全检查
- if p.cclient == nil {
- return res, errRedisCClient
- }
- return p.cclient.ZIncrBy(key, incr, member).Result()
- }
- // 客户端安全检查
- if p.client == nil {
- return res, errRedisClient
- }
- return p.client.ZIncrBy(key, incr, member).Result()
- }
- func (p *Redis) ZRem(key string, members ...interface{}) (res int64, err error) {
- // 安全检查
- if p == nil {
- return res, errRedis
- }
- if p.cluster {
- // 客户端安全检查
- if p.cclient == nil {
- return res, errRedisCClient
- }
- return p.cclient.ZRem(key, members...).Result()
- }
- // 客户端安全检查
- if p.client == nil {
- return res, errRedisClient
- }
- return p.client.ZRem(key, members...).Result()
- }
- func (p *Redis) ZUnionStore(dest string, weights []float64, aggregate string, keys ...string) (res int64, err error) {
- // 安全检查
- if p == nil {
- return res, errRedis
- }
- if p.cluster {
- return 0, fmt.Errorf("cluster unsupport <zunionstore>.")
- }
- // 客户端安全检查
- if p.client == nil {
- return res, errRedisClient
- }
- return p.client.ZUnionStore(dest,
- redis.ZStore{
- Weights: weights,
- Aggregate: aggregate,
- },
- keys...).Result()
- }
- func (p *Redis) ZCard(key string) (res int64, err error) {
- // 安全检查
- if p == nil {
- return res, errRedis
- }
- if p.cluster {
- // 客户端安全检查
- if p.cclient == nil {
- return res, errRedisCClient
- }
- return p.cclient.ZCard(key).Result()
- }
- // 客户端安全检查
- if p.client == nil {
- return res, errRedisClient
- }
- return p.client.ZCard(key).Result()
- }
- func (p *Redis) ZRemRangeByScore(key, min, max string) (res int64, err error) {
- // 安全检查
- if p == nil {
- return res, errRedis
- }
- if p.cluster {
- // 客户端安全检查
- if p.cclient == nil {
- return res, errRedisCClient
- }
- return p.cclient.ZRemRangeByScore(key, min, max).Result()
- }
- // 客户端安全检查
- if p.client == nil {
- return res, errRedisClient
- }
- return p.client.ZRemRangeByScore(key, min, max).Result()
- }
- func (p *Redis) ZRevRangeWithScores(key string, star, stop int64) (res []redis.Z, err error) {
- // 安全检查
- if p == nil {
- return res, errRedis
- }
- if p.cluster {
- // 客户端安全检查
- if p.cclient == nil {
- return res, errRedisCClient
- }
- return p.cclient.ZRevRangeWithScores(key, star, stop).Result()
- }
- // 客户端安全检查
- if p.client == nil {
- return res, errRedisClient
- }
- return p.client.ZRevRangeWithScores(key, star, stop).Result()
- }
|