Documentation
¶
Index ¶
- Constants
- Variables
- func GetBucketId(key []byte, bit int) []byte
- func GetLockFromContext(ctx context.Context) (*lockInfo, bool)
- func GetSort(sort GeoEnum) string
- type Client
- func (c *Client) Close() error
- func (c *Client) Delete(key string) bool
- func (c *Client) GetExpire(key string) (time.Duration, error)
- func (c *Client) GetGeoOps() Geo
- func (c *Client) GetHashOps() Hash
- func (c *Client) GetKVOps() KV
- func (c *Client) GetListOps() List
- func (c *Client) GetLockOps() *Lock
- func (c *Client) GetPipeLineOps() Pipeline
- func (c *Client) GetPipeline() Pipeline
- func (c *Client) GetPubSubOps() PubSub
- func (c *Client) GetSetOps() Set
- func (c *Client) GetTxPipeLineOps() Pipeline
- func (c *Client) GetTxPipeline() Pipeline
- func (c *Client) GetZSetOps() ZSet
- func (c *Client) HasKey(key string) bool
- func (c *Client) Info() (string, error)
- func (c *Client) ListKeys(page uint64, pattern string, pageSize int64) ([]string, int, error)
- func (c *Client) Ping() (string, error)
- func (c *Client) RandomKey() (string, error)
- func (c *Client) SetExpire(key string, expiration time.Duration) (bool, error)
- func (c *Client) SetSerializer(serializer ISerializer)
- type Geo
- func (geo *Geo) GeoAdd(key string, longitude float64, latitude float64, member string) int64
- func (geo *Geo) GeoAddArr(key string, geoPosition []GeoPosition) int64
- func (geo *Geo) GeoDist(key string, member1, member2 string, unit GeoUnit) (error, GeoDistInfo)
- func (geo *Geo) GeoPos(key string, member string) (err error, geoRes GeoPosition)
- func (geo *Geo) GeoPosArr(key string, members []string) (err error, geoRes []GeoPosition)
- func (geo *Geo) GeoRadius(key string, query GeoRadiusQuery) (error, []GeoPosition)
- func (geo *Geo) GeoRadiusByMember(key string, query GeoRadiusByMemberQuery) (error, []GeoPosition)
- type GeoDistInfo
- type GeoEnum
- type GeoPosition
- type GeoRadiusByMemberQuery
- type GeoRadiusQuery
- type GeoUnit
- type GoRedisClusterOps
- func (ops *GoRedisClusterOps) Close() error
- func (ops *GoRedisClusterOps) PSubscribe(patterns ...string) (*Subscription, error)
- func (ops *GoRedisClusterOps) Pipeline() Pipeline
- func (ops *GoRedisClusterOps) Publish(channel string, message interface{}) (int64, error)
- func (ops *GoRedisClusterOps) Subscribe(channels ...string) (*Subscription, error)
- func (ops *GoRedisClusterOps) TxPipeline() Pipeline
- type GoRedisPipeline
- func (p *GoRedisPipeline) Del(keys ...string) *redis.IntCmd
- func (p *GoRedisPipeline) Discard()
- func (p *GoRedisPipeline) Exec(ctx context.Context) ([]redis.Cmder, error)
- func (p *GoRedisPipeline) Get(key string) *redis.StringCmd
- func (p *GoRedisPipeline) HGet(key string, field string) *redis.StringCmd
- func (p *GoRedisPipeline) HSet(key string, field string, value interface{}) *redis.IntCmd
- func (p *GoRedisPipeline) Incr(key string) *redis.IntCmd
- func (p *GoRedisPipeline) IncrBy(key string, value int64) *redis.IntCmd
- func (p *GoRedisPipeline) LPush(key string, values ...interface{}) *redis.IntCmd
- func (p *GoRedisPipeline) MGet(keys ...string) *redis.SliceCmd
- func (p *GoRedisPipeline) MSet(pairs ...interface{}) *redis.StatusCmd
- func (p *GoRedisPipeline) RPush(key string, values ...interface{}) *redis.IntCmd
- func (p *GoRedisPipeline) SAdd(key string, members ...interface{}) *redis.IntCmd
- func (p *GoRedisPipeline) Set(key string, value interface{}, expiration time.Duration) *redis.StatusCmd
- func (p *GoRedisPipeline) SetNX(key string, value interface{}, expiration time.Duration) *redis.BoolCmd
- func (p *GoRedisPipeline) ZAdd(key string, members ...redis.Z) *redis.IntCmd
- type GoRedisStandaloneOps
- func (ops *GoRedisStandaloneOps) Append(key string, value string) (int64, error)
- func (ops *GoRedisStandaloneOps) Close() error
- func (ops *GoRedisStandaloneOps) DeleteKey(keys ...string) (int64, error)
- func (ops *GoRedisStandaloneOps) Eval(script string, keys []string, args ...interface{}) (interface{}, error)
- func (ops *GoRedisStandaloneOps) Exists(key string) (bool, error)
- func (ops *GoRedisStandaloneOps) GeoAddArr(key string, geoLocation ...GeoPosition) int64
- func (ops *GoRedisStandaloneOps) GeoDist(key string, member1, member2 string, unit GeoUnit) (error, GeoDistInfo)
- func (ops *GoRedisStandaloneOps) GeoPos(key string, members ...string) (error, []GeoPosition)
- func (ops *GoRedisStandaloneOps) GeoRadius(key string, query GeoRadiusQuery) (error, []GeoPosition)
- func (ops *GoRedisStandaloneOps) GeoRadiusByMember(key string, member string, query GeoRadiusByMemberQuery) (error, []GeoPosition)
- func (ops *GoRedisStandaloneOps) Get(key string) (string, error)
- func (ops *GoRedisStandaloneOps) GetRange(key string, start int64, end int64) (string, error)
- func (ops *GoRedisStandaloneOps) GetValue(key string) ([]byte, error)
- func (ops *GoRedisStandaloneOps) HDel(key string, fields ...string) (int64, error)
- func (ops *GoRedisStandaloneOps) HExists(key string, field string) (bool, error)
- func (ops *GoRedisStandaloneOps) HGet(key string, field string) (string, error)
- func (ops *GoRedisStandaloneOps) HGetAll(key string) (map[string]string, error)
- func (ops *GoRedisStandaloneOps) HGetFloat64(key string, field string) (float64, error)
- func (ops *GoRedisStandaloneOps) HGetInt64(key string, field string) (int64, error)
- func (ops *GoRedisStandaloneOps) HIncrBy(key string, field string, increment int64) (int64, error)
- func (ops *GoRedisStandaloneOps) HKeys(key string) ([]string, error)
- func (ops *GoRedisStandaloneOps) HLen(key string) (int64, error)
- func (ops *GoRedisStandaloneOps) HMGet(key string, fields ...string) ([]interface{}, error)
- func (ops *GoRedisStandaloneOps) HSet(key string, field string, value interface{}) (int64, error)
- func (ops *GoRedisStandaloneOps) HSetNX(key string, field string, value interface{}) (bool, error)
- func (ops *GoRedisStandaloneOps) HVals(key string) ([]string, error)
- func (ops *GoRedisStandaloneOps) IncrBy(key string, step int64) (int64, error)
- func (ops *GoRedisStandaloneOps) Info() (string, error)
- func (ops *GoRedisStandaloneOps) LIndex(key string, index int64) (string, error)
- func (ops *GoRedisStandaloneOps) LPop(key string) (string, error)
- func (ops *GoRedisStandaloneOps) LPush(key string, values ...interface{}) (int64, error)
- func (ops *GoRedisStandaloneOps) LRange(key string, start int64, end int64) ([]string, error)
- func (ops *GoRedisStandaloneOps) LRemove(key string, count int64, value interface{}) (int64, error)
- func (ops *GoRedisStandaloneOps) LSet(key string, index int64, value interface{}) error
- func (ops *GoRedisStandaloneOps) LSize(key string) (int64, error)
- func (ops *GoRedisStandaloneOps) LTrim(key string, start int64, end int64) error
- func (ops *GoRedisStandaloneOps) ListKeys(page uint64, pattern string, pageSize int64) ([]string, int, error)
- func (ops *GoRedisStandaloneOps) MultiGet(key ...string) ([]interface{}, error)
- func (ops *GoRedisStandaloneOps) MultiSet(values ...interface{}) error
- func (ops *GoRedisStandaloneOps) PSubscribe(patterns ...string) (*Subscription, error)
- func (ops *GoRedisStandaloneOps) Ping() (string, error)
- func (ops *GoRedisStandaloneOps) Pipeline() Pipeline
- func (ops *GoRedisStandaloneOps) Publish(channel string, message interface{}) (int64, error)
- func (ops *GoRedisStandaloneOps) RPop(key string) (string, error)
- func (ops *GoRedisStandaloneOps) RPush(key string, values ...interface{}) (int64, error)
- func (ops *GoRedisStandaloneOps) RandomKey() (string, error)
- func (ops *GoRedisStandaloneOps) SAdd(key string, members ...interface{}) (int64, error)
- func (ops *GoRedisStandaloneOps) SCard(key string) (int64, error)
- func (ops *GoRedisStandaloneOps) SDiff(keys ...string) ([]string, error)
- func (ops *GoRedisStandaloneOps) SInter(keys ...string) ([]string, error)
- func (ops *GoRedisStandaloneOps) SInterStore(destination string, keys ...string) (int64, error)
- func (ops *GoRedisStandaloneOps) SIsMember(key string, member interface{}) (bool, error)
- func (ops *GoRedisStandaloneOps) SMembers(key string) ([]string, error)
- func (ops *GoRedisStandaloneOps) SMove(source string, destination string, member interface{}) (bool, error)
- func (ops *GoRedisStandaloneOps) SPop(key string) (string, error)
- func (ops *GoRedisStandaloneOps) SRandMembers(key string, count int64) ([]string, error)
- func (ops *GoRedisStandaloneOps) SRem(key string, members ...interface{}) (int64, error)
- func (ops *GoRedisStandaloneOps) SUnion(keys ...string) ([]string, error)
- func (ops *GoRedisStandaloneOps) SUnionStore(destination string, keys ...string) (int64, error)
- func (ops *GoRedisStandaloneOps) Set(key string, value string, expiration time.Duration) error
- func (ops *GoRedisStandaloneOps) SetExpire(key string, expiration time.Duration) (bool, error)
- func (ops *GoRedisStandaloneOps) SetIfAbsent(key string, value interface{}) (bool, error)
- func (ops *GoRedisStandaloneOps) SetIfAbsentWithTTL(key string, value interface{}, duration time.Duration) (bool, error)
- func (ops *GoRedisStandaloneOps) SetNX(key string, value interface{}) (bool, error)
- func (ops *GoRedisStandaloneOps) SetNXTtl(key string, value interface{}, duration time.Duration) (bool, error)
- func (ops *GoRedisStandaloneOps) SetValue(key string, value interface{}, expiration time.Duration) error
- func (ops *GoRedisStandaloneOps) StrLen(key string) (int64, error)
- func (ops *GoRedisStandaloneOps) Subscribe(channels ...string) (*Subscription, error)
- func (ops *GoRedisStandaloneOps) TTL(key string) (time.Duration, error)
- func (ops *GoRedisStandaloneOps) TxPipeline() Pipeline
- func (ops *GoRedisStandaloneOps) ZAdd(key string, member ZMember) int64
- func (ops *GoRedisStandaloneOps) ZCard(key string) int64
- func (ops *GoRedisStandaloneOps) ZCount(key, min, max string) int64
- func (ops *GoRedisStandaloneOps) ZIncrby(key string, incr float64, member string) float64
- func (ops *GoRedisStandaloneOps) ZInterStore(destination string, store []ZStore, arg ZStoreEnum) int64
- func (ops *GoRedisStandaloneOps) ZLexCount(key, min, max string) int64
- func (ops *GoRedisStandaloneOps) ZRange(key string, start, stop int64) []string
- func (ops *GoRedisStandaloneOps) ZRangeByLex(key, min, max string, offset int64, count int64) []string
- func (ops *GoRedisStandaloneOps) ZRangeByScore(key, min, max string, offset int64, count int64) []string
- func (ops *GoRedisStandaloneOps) ZRank(key, member string) int64
- func (ops *GoRedisStandaloneOps) ZRem(key string, member ...string) int64
- func (ops *GoRedisStandaloneOps) ZRemRangeByLex(key, min, max string) int64
- func (ops *GoRedisStandaloneOps) ZRemRangeByRank(key string, start, stop int64) int64
- func (ops *GoRedisStandaloneOps) ZRevRange(key string, start, stop int64) []string
- func (ops *GoRedisStandaloneOps) ZRevRangeWithScores(key string, start, stop int64) ([]ZMember, error)
- func (ops *GoRedisStandaloneOps) ZRevRank(key, member string) int64
- func (ops *GoRedisStandaloneOps) ZScore(key, member string) float64
- type Hash
- func (h Hash) Delete(key string, hashKey string) error
- func (h Hash) Exists(key string, hashKey string) bool
- func (h Hash) Get(key string, hashKey string, value interface{}) error
- func (h Hash) GetEntries(key string) (map[string]string, error)
- func (h Hash) GetHashKeys(key string) ([]string, error)
- func (h Hash) GetString(key string, hashKey string) (string, error)
- func (h Hash) Increment(key string, hashKey string, delta int64) int64
- func (h Hash) MultiGet(key string, hashKeys ...string) ([]interface{}, error)
- func (h Hash) Put(key string, hashKey string, value interface{}) error
- func (h Hash) PutIfAbsent(key string, hashKey string, value interface{}) (bool, error)
- func (h Hash) Size(key string) int64
- type IClient
- type ISerializer
- type JsonSerializer
- type KV
- func (kv KV) Append(key string, value string) int64
- func (kv KV) Get(key string, ptr interface{}) error
- func (kv KV) GetAndSet(key string, value string) (string, error)
- func (kv KV) GetString(key string) (string, error)
- func (kv KV) Increment(key string, delta int64) (int64, error)
- func (kv KV) MultiGet(keys ...string) ([]interface{}, error)
- func (kv KV) MultiSet(values ...interface{}) error
- func (kv KV) Set(key string, value interface{}, duration time.Duration) error
- func (kv KV) SetIfAbsent(key string, value interface{}) (bool, error)
- func (kv KV) SetString(key string, value string, duration time.Duration) error
- type List
- func (ls List) AddElements(key string, values ...interface{}) error
- func (ls List) Clear(key string) (bool, error)
- func (ls List) GetElement(key string, index int64, elem interface{}) error
- func (ls List) GetElements(key string, startIndex int64, endIndex int64, elements interface{})
- func (ls List) Index(key string, index int64) (string, error)
- func (ls List) LeftPop(key string) (string, error)
- func (ls List) LeftPush(key string, value ...interface{}) (int64, error)
- func (ls List) Range(key string, start int64, end int64) ([]string, error)
- func (ls List) Remove(key string, count int64, value interface{}) (int64, error)
- func (ls List) RightPop(key string) (string, error)
- func (ls List) RightPush(key string, values ...interface{}) (int64, error)
- func (ls List) Set(key string, index int64, value interface{}) error
- func (ls List) Size(key string) (int64, error)
- func (ls List) Trim(key string, start int64, end int64) error
- type Lock
- func (lock *Lock) DisposeLock(key string) (error, bool)
- func (lock *Lock) Extend(key string, leaseTime time.Duration) error
- func (lock *Lock) ForceUnlock(key string) error
- func (lock *Lock) GetDLock(key string, waitSecond int) (error, bool)
- func (lock *Lock) GetDLockWithTtl(key string, waitSecond int, duration time.Duration) (error, bool)
- func (lock *Lock) IsLocked(key string) (bool, error)
- func (lock *Lock) LockWithContext(ctx context.Context, key string, leaseTime time.Duration) (context.Context, error)
- func (lock *Lock) SetIfAbsent(key string, value interface{}) (bool, error)
- func (lock *Lock) SetIfAbsentWithTTL(key string, value interface{}, duration time.Duration) (bool, error)
- func (lock *Lock) TryLock(key string, leaseTime time.Duration) (error, bool)
- func (lock *Lock) TryLockWithWait(key string, waitTime time.Duration, leaseTime time.Duration) (error, bool)
- func (lock *Lock) Unlock(key string) error
- type Message
- type Ops
- type Options
- type Pipeline
- type PubSub
- func (ps PubSub) PSubscribe(patterns ...string) (*Subscription, error)
- func (ps PubSub) PSubscribeWithCallback(callback func(*Message), patterns ...string) (*Subscription, error)
- func (ps PubSub) Publish(channel string, message interface{}) (int64, error)
- func (ps PubSub) ReceiveMessage(channel string) (*Message, error)
- func (ps PubSub) ReceiveMessageTimeout(channel string, timeout time.Duration) (*Message, error)
- func (ps PubSub) ReceiveMessages(channel string, messageChan chan<- *Message) (*Subscription, error)
- func (ps PubSub) ReceiveMessagesWithPattern(pattern string, messageChan chan<- *Message) (*Subscription, error)
- func (ps PubSub) Subscribe(channels ...string) (*Subscription, error)
- func (ps PubSub) SubscribeWithCallback(callback func(*Message), channels ...string) (*Subscription, error)
- type Set
- func (set Set) Add(key string, members ...interface{}) (int64, error)
- func (set Set) Difference(keys ...string) ([]string, error)
- func (set Set) Intersect(keys ...string) ([]string, error)
- func (set Set) IntersectAndStore(destination string, keys ...string) (int64, error)
- func (set Set) IsMember(key string, member interface{}) (bool, error)
- func (set Set) Members(key string) ([]string, error)
- func (set Set) Move(source string, destination string, member interface{}) (bool, error)
- func (set Set) Pop(key string) (string, error)
- func (set Set) RandMembers(key string, count int64) ([]string, error)
- func (set Set) Remove(key string, members ...interface{}) (int64, error)
- func (set Set) Size(key string) (int64, error)
- func (set Set) Union(keys ...string) ([]string, error)
- func (set Set) UnionAndStore(destination string, keys ...string) (int64, error)
- type Subscription
- type ZMember
- type ZSet
- func (zSet *ZSet) ZAdd(key string, member ZMember) int64
- func (zSet *ZSet) ZCard(key string) int64
- func (zSet *ZSet) ZCount(key string, min, max float64) int64
- func (zSet *ZSet) ZIncrby(key string, incr float64, member string) float64
- func (zSet *ZSet) ZInterStore(destination string, store []ZStore, arg ZStoreEnum) int64
- func (zSet *ZSet) ZLexCount(key, min, max string) int64
- func (zSet *ZSet) ZRange(key string, start, stop int64) []string
- func (zSet *ZSet) ZRangeByLex(key, min, max string, offset int64, count int64) []string
- func (zSet *ZSet) ZRangeByScore(key, min, max string, offset int64, count int64) []string
- func (zSet *ZSet) ZRank(key, member string) int64
- func (zSet *ZSet) ZRem(key string, member ...string) int64
- func (zSet *ZSet) ZRemRangeByLex(key, min, max string) int64
- func (zSet *ZSet) ZRemRangeByRank(key string, start, stop int64) int64
- func (zSet *ZSet) ZRevRange(key string, start, stop int64) []string
- func (zSet *ZSet) ZRevRangeWithScores(key string, start, stop int64) ([]ZMember, error)
- func (zSet *ZSet) ZRevRank(key, member string) int64
- func (zSet *ZSet) ZScore(key, member string) float64
- type ZStore
- type ZStoreEnum
Constants ¶
const ( KM GeoUnit = "km" M GeoUnit = "m" MI GeoUnit = "mi" FT GeoUnit = "ft" WITHCOORD GeoEnum = "WITHCOORD" WITHDIST GeoEnum = "WITHDIST" WITHHASH GeoEnum = "WITHHASH" ASC GeoEnum = "ASC" DESC GeoEnum = "DESC" )
长度计量单位
Variables ¶
var (
DefaultSerializer = JsonSerializer{}
)
Functions ¶
func GetBucketId ¶
getBucketId
https://www.cnblogs.com/colorfulkoala/p/5783556.html 过程变化简单描述为:get(key1) -> hget(md5(key1), key1) 从而得到value1。 如果我们通过预先计算,让很多key可以在BucketId空间里碰撞,那么可以认为一个BucketId下面挂了多个key。比如平均每个BucketId下面挂10个key,那么理论上我们将会减少超过90%的redis key的个数。 具体实现起来有一些麻烦,而且用这个方法之前你要想好容量规模。我们通常使用的md5是32位的hexString(16进制字符),它的空间是128bit,这个量级太大了,我们需要存储的是百亿级,大约是33bit,所以我们需要有一种机制计算出合适位数的散列,而且为了节约内存,我们需要利用全部字符类型(ASCII码在0~127之间)来填充,而不用HexString,这样Key的长度可以缩短到一半。
func GetLockFromContext ¶ added in v1.9.28
GetLockFromContext retrieves lock info from context
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) GetGeoOps ¶
GetGeoOps Geo Returns the operations performed on geo values (also known GIS system).
func (*Client) GetHashOps ¶
GetHashOps Returns the operations performed on hash values.
func (*Client) GetKVOps ¶
GetKVOps Returns the operations performed on simple values (or Strings in Redis terminology).
func (*Client) GetListOps ¶
GetListOps Returns the operations performed on list values.
func (*Client) GetLockOps ¶
GetLockOps Returns the operations performed on locker values.
func (*Client) GetPipeLineOps ¶ added in v1.9.28
GetPipeLineOps creates a pipeline for batch commands execution
func (*Client) GetPipeline ¶ added in v1.9.28
GetPipeline creates a pipeline
func (*Client) GetPubSubOps ¶ added in v1.9.28
GetPubSubOps Returns the operations performed on publish/subscribe values.
func (*Client) GetTxPipeLineOps ¶ added in v1.9.28
GetTxPipeLineOps creates a transaction pipeline for batch commands execution
func (*Client) GetTxPipeline ¶ added in v1.9.28
GetTxPipeline creates a transaction pipeline
func (*Client) GetZSetOps ¶
GetZSetOps Returns the operations performed on zset values (also known as sorted sets).
func (*Client) SetSerializer ¶
func (c *Client) SetSerializer(serializer ISerializer)
SetSerializer set value serializer
type Geo ¶
type Geo struct {
// contains filtered or unexported fields
}
func (*Geo) GeoAddArr ¶
func (geo *Geo) GeoAddArr(key string, geoPosition []GeoPosition) int64
添加一批地理信息
func (*Geo) GeoPos ¶
func (geo *Geo) GeoPos(key string, member string) (err error, geoRes GeoPosition)
根据地理位置名称获取经纬度
func (*Geo) GeoPosArr ¶
func (geo *Geo) GeoPosArr(key string, members []string) (err error, geoRes []GeoPosition)
获取一批地理位置的经纬度
func (*Geo) GeoRadius ¶
func (geo *Geo) GeoRadius(key string, query GeoRadiusQuery) (error, []GeoPosition)
* 经纬度中心距离计算
func (*Geo) GeoRadiusByMember ¶
func (geo *Geo) GeoRadiusByMember(key string, query GeoRadiusByMemberQuery) (error, []GeoPosition)
* 地理标识中心距离计算
type GeoDistInfo ¶
type GeoPosition ¶
type GeoRadiusByMemberQuery ¶
type GeoRadiusQuery ¶
type GoRedisClusterOps ¶
type GoRedisClusterOps struct {
GoRedisStandaloneOps
// contains filtered or unexported fields
}
func NewClusterOps ¶
func NewClusterOps(options *Options, serializer ISerializer) *GoRedisClusterOps
func (*GoRedisClusterOps) Close ¶ added in v1.9.28
func (ops *GoRedisClusterOps) Close() error
Close closes the cluster client
func (*GoRedisClusterOps) PSubscribe ¶ added in v1.9.28
func (ops *GoRedisClusterOps) PSubscribe(patterns ...string) (*Subscription, error)
PSubscribe subscribes the client to the given patterns
func (*GoRedisClusterOps) Pipeline ¶ added in v1.9.28
func (ops *GoRedisClusterOps) Pipeline() Pipeline
Pipeline creates a pipeline for batch commands execution
func (*GoRedisClusterOps) Publish ¶ added in v1.9.28
func (ops *GoRedisClusterOps) Publish(channel string, message interface{}) (int64, error)
Publish posts a message to the channel
func (*GoRedisClusterOps) Subscribe ¶ added in v1.9.28
func (ops *GoRedisClusterOps) Subscribe(channels ...string) (*Subscription, error)
Subscribe subscribes the client to the specified channels
func (*GoRedisClusterOps) TxPipeline ¶ added in v1.9.28
func (ops *GoRedisClusterOps) TxPipeline() Pipeline
TxPipeline creates a transaction pipeline
type GoRedisPipeline ¶ added in v1.9.28
type GoRedisPipeline struct {
// contains filtered or unexported fields
}
GoRedisPipeline 实现 Pipeline 接口
func (*GoRedisPipeline) Del ¶ added in v1.9.28
func (p *GoRedisPipeline) Del(keys ...string) *redis.IntCmd
func (*GoRedisPipeline) Discard ¶ added in v1.9.28
func (p *GoRedisPipeline) Discard()
func (*GoRedisPipeline) Get ¶ added in v1.9.28
func (p *GoRedisPipeline) Get(key string) *redis.StringCmd
func (*GoRedisPipeline) HGet ¶ added in v1.9.28
func (p *GoRedisPipeline) HGet(key string, field string) *redis.StringCmd
func (*GoRedisPipeline) HSet ¶ added in v1.9.28
func (p *GoRedisPipeline) HSet(key string, field string, value interface{}) *redis.IntCmd
func (*GoRedisPipeline) Incr ¶ added in v1.9.28
func (p *GoRedisPipeline) Incr(key string) *redis.IntCmd
func (*GoRedisPipeline) IncrBy ¶ added in v1.9.28
func (p *GoRedisPipeline) IncrBy(key string, value int64) *redis.IntCmd
func (*GoRedisPipeline) LPush ¶ added in v1.9.28
func (p *GoRedisPipeline) LPush(key string, values ...interface{}) *redis.IntCmd
func (*GoRedisPipeline) MGet ¶ added in v1.9.28
func (p *GoRedisPipeline) MGet(keys ...string) *redis.SliceCmd
func (*GoRedisPipeline) MSet ¶ added in v1.9.28
func (p *GoRedisPipeline) MSet(pairs ...interface{}) *redis.StatusCmd
func (*GoRedisPipeline) RPush ¶ added in v1.9.28
func (p *GoRedisPipeline) RPush(key string, values ...interface{}) *redis.IntCmd
func (*GoRedisPipeline) SAdd ¶ added in v1.9.28
func (p *GoRedisPipeline) SAdd(key string, members ...interface{}) *redis.IntCmd
type GoRedisStandaloneOps ¶
type GoRedisStandaloneOps struct {
// contains filtered or unexported fields
}
func NewStandaloneOps ¶
func NewStandaloneOps(options *Options, serializer ISerializer) *GoRedisStandaloneOps
func (*GoRedisStandaloneOps) Append ¶
func (ops *GoRedisStandaloneOps) Append(key string, value string) (int64, error)
func (*GoRedisStandaloneOps) Close ¶
func (ops *GoRedisStandaloneOps) Close() error
func (*GoRedisStandaloneOps) DeleteKey ¶
func (ops *GoRedisStandaloneOps) DeleteKey(keys ...string) (int64, error)
func (*GoRedisStandaloneOps) Eval ¶ added in v1.9.28
func (ops *GoRedisStandaloneOps) Eval(script string, keys []string, args ...interface{}) (interface{}, error)
Eval executes a Lua script with the given keys and arguments
func (*GoRedisStandaloneOps) Exists ¶
func (ops *GoRedisStandaloneOps) Exists(key string) (bool, error)
func (*GoRedisStandaloneOps) GeoAddArr ¶
func (ops *GoRedisStandaloneOps) GeoAddArr(key string, geoLocation ...GeoPosition) int64
func (*GoRedisStandaloneOps) GeoDist ¶
func (ops *GoRedisStandaloneOps) GeoDist(key string, member1, member2 string, unit GeoUnit) (error, GeoDistInfo)
func (*GoRedisStandaloneOps) GeoPos ¶
func (ops *GoRedisStandaloneOps) GeoPos(key string, members ...string) (error, []GeoPosition)
func (*GoRedisStandaloneOps) GeoRadius ¶
func (ops *GoRedisStandaloneOps) GeoRadius(key string, query GeoRadiusQuery) (error, []GeoPosition)
func (*GoRedisStandaloneOps) GeoRadiusByMember ¶
func (ops *GoRedisStandaloneOps) GeoRadiusByMember(key string, member string, query GeoRadiusByMemberQuery) (error, []GeoPosition)
func (*GoRedisStandaloneOps) GetValue ¶
func (ops *GoRedisStandaloneOps) GetValue(key string) ([]byte, error)
func (*GoRedisStandaloneOps) HDel ¶
func (ops *GoRedisStandaloneOps) HDel(key string, fields ...string) (int64, error)
func (*GoRedisStandaloneOps) HExists ¶
func (ops *GoRedisStandaloneOps) HExists(key string, field string) (bool, error)
func (*GoRedisStandaloneOps) HGet ¶
func (ops *GoRedisStandaloneOps) HGet(key string, field string) (string, error)
func (*GoRedisStandaloneOps) HGetAll ¶
func (ops *GoRedisStandaloneOps) HGetAll(key string) (map[string]string, error)
func (*GoRedisStandaloneOps) HGetFloat64 ¶
func (ops *GoRedisStandaloneOps) HGetFloat64(key string, field string) (float64, error)
func (*GoRedisStandaloneOps) HGetInt64 ¶
func (ops *GoRedisStandaloneOps) HGetInt64(key string, field string) (int64, error)
func (*GoRedisStandaloneOps) HKeys ¶
func (ops *GoRedisStandaloneOps) HKeys(key string) ([]string, error)
func (*GoRedisStandaloneOps) HLen ¶
func (ops *GoRedisStandaloneOps) HLen(key string) (int64, error)
func (*GoRedisStandaloneOps) HMGet ¶
func (ops *GoRedisStandaloneOps) HMGet(key string, fields ...string) ([]interface{}, error)
func (*GoRedisStandaloneOps) HSet ¶
func (ops *GoRedisStandaloneOps) HSet(key string, field string, value interface{}) (int64, error)
func (*GoRedisStandaloneOps) HSetNX ¶
func (ops *GoRedisStandaloneOps) HSetNX(key string, field string, value interface{}) (bool, error)
func (*GoRedisStandaloneOps) HVals ¶
func (ops *GoRedisStandaloneOps) HVals(key string) ([]string, error)
func (*GoRedisStandaloneOps) IncrBy ¶
func (ops *GoRedisStandaloneOps) IncrBy(key string, step int64) (int64, error)
func (*GoRedisStandaloneOps) Info ¶ added in v1.9.6
func (ops *GoRedisStandaloneOps) Info() (string, error)
func (*GoRedisStandaloneOps) LIndex ¶
func (ops *GoRedisStandaloneOps) LIndex(key string, index int64) (string, error)
func (*GoRedisStandaloneOps) LPop ¶
func (ops *GoRedisStandaloneOps) LPop(key string) (string, error)
--------------------------------------------------------------------------------------------------- list ops
func (*GoRedisStandaloneOps) LPush ¶
func (ops *GoRedisStandaloneOps) LPush(key string, values ...interface{}) (int64, error)
func (*GoRedisStandaloneOps) LRemove ¶
func (ops *GoRedisStandaloneOps) LRemove(key string, count int64, value interface{}) (int64, error)
func (*GoRedisStandaloneOps) LSet ¶
func (ops *GoRedisStandaloneOps) LSet(key string, index int64, value interface{}) error
func (*GoRedisStandaloneOps) LSize ¶
func (ops *GoRedisStandaloneOps) LSize(key string) (int64, error)
func (*GoRedisStandaloneOps) LTrim ¶
func (ops *GoRedisStandaloneOps) LTrim(key string, start int64, end int64) error
func (*GoRedisStandaloneOps) MultiGet ¶
func (ops *GoRedisStandaloneOps) MultiGet(key ...string) ([]interface{}, error)
func (*GoRedisStandaloneOps) MultiSet ¶
func (ops *GoRedisStandaloneOps) MultiSet(values ...interface{}) error
MultiSet is like Set but accepts multiple values:
- MSet("key1", "value1", "key2", "value2")
- MSet([]string{"key1", "value1", "key2", "value2"})
- MSet(map[string]interface{}{"key1": "value1", "key2": "value2"})
func (*GoRedisStandaloneOps) PSubscribe ¶ added in v1.9.28
func (ops *GoRedisStandaloneOps) PSubscribe(patterns ...string) (*Subscription, error)
PSubscribe subscribes the client to the given patterns
func (*GoRedisStandaloneOps) Ping ¶
func (ops *GoRedisStandaloneOps) Ping() (string, error)
func (*GoRedisStandaloneOps) Pipeline ¶ added in v1.9.28
func (ops *GoRedisStandaloneOps) Pipeline() Pipeline
Pipeline creates a pipeline for batch commands execution
func (*GoRedisStandaloneOps) Publish ¶ added in v1.9.28
func (ops *GoRedisStandaloneOps) Publish(channel string, message interface{}) (int64, error)
Publish posts a message to the channel
func (*GoRedisStandaloneOps) RPop ¶
func (ops *GoRedisStandaloneOps) RPop(key string) (string, error)
func (*GoRedisStandaloneOps) RPush ¶
func (ops *GoRedisStandaloneOps) RPush(key string, values ...interface{}) (int64, error)
func (*GoRedisStandaloneOps) RandomKey ¶
func (ops *GoRedisStandaloneOps) RandomKey() (string, error)
func (*GoRedisStandaloneOps) SAdd ¶
func (ops *GoRedisStandaloneOps) SAdd(key string, members ...interface{}) (int64, error)
func (*GoRedisStandaloneOps) SCard ¶
func (ops *GoRedisStandaloneOps) SCard(key string) (int64, error)
func (*GoRedisStandaloneOps) SDiff ¶
func (ops *GoRedisStandaloneOps) SDiff(keys ...string) ([]string, error)
func (*GoRedisStandaloneOps) SInter ¶
func (ops *GoRedisStandaloneOps) SInter(keys ...string) ([]string, error)
func (*GoRedisStandaloneOps) SInterStore ¶
func (ops *GoRedisStandaloneOps) SInterStore(destination string, keys ...string) (int64, error)
func (*GoRedisStandaloneOps) SIsMember ¶
func (ops *GoRedisStandaloneOps) SIsMember(key string, member interface{}) (bool, error)
func (*GoRedisStandaloneOps) SMembers ¶
func (ops *GoRedisStandaloneOps) SMembers(key string) ([]string, error)
func (*GoRedisStandaloneOps) SMove ¶
func (ops *GoRedisStandaloneOps) SMove(source string, destination string, member interface{}) (bool, error)
func (*GoRedisStandaloneOps) SPop ¶
func (ops *GoRedisStandaloneOps) SPop(key string) (string, error)
func (*GoRedisStandaloneOps) SRandMembers ¶
func (ops *GoRedisStandaloneOps) SRandMembers(key string, count int64) ([]string, error)
func (*GoRedisStandaloneOps) SRem ¶
func (ops *GoRedisStandaloneOps) SRem(key string, members ...interface{}) (int64, error)
func (*GoRedisStandaloneOps) SUnion ¶
func (ops *GoRedisStandaloneOps) SUnion(keys ...string) ([]string, error)
func (*GoRedisStandaloneOps) SUnionStore ¶
func (ops *GoRedisStandaloneOps) SUnionStore(destination string, keys ...string) (int64, error)
func (*GoRedisStandaloneOps) SetIfAbsent ¶ added in v1.9.28
func (ops *GoRedisStandaloneOps) SetIfAbsent(key string, value interface{}) (bool, error)
SetIfAbsent sets the value if the key does not exist (alias for SetNX)
func (*GoRedisStandaloneOps) SetIfAbsentWithTTL ¶ added in v1.9.28
func (ops *GoRedisStandaloneOps) SetIfAbsentWithTTL(key string, value interface{}, duration time.Duration) (bool, error)
SetIfAbsentWithTTL sets the value with TTL if the key does not exist
func (*GoRedisStandaloneOps) SetNX ¶
func (ops *GoRedisStandaloneOps) SetNX(key string, value interface{}) (bool, error)
func (*GoRedisStandaloneOps) SetValue ¶
func (ops *GoRedisStandaloneOps) SetValue(key string, value interface{}, expiration time.Duration) error
func (*GoRedisStandaloneOps) StrLen ¶
func (ops *GoRedisStandaloneOps) StrLen(key string) (int64, error)
func (*GoRedisStandaloneOps) Subscribe ¶ added in v1.9.28
func (ops *GoRedisStandaloneOps) Subscribe(channels ...string) (*Subscription, error)
Subscribe subscribes the client to the specified channels
func (*GoRedisStandaloneOps) TTL ¶
func (ops *GoRedisStandaloneOps) TTL(key string) (time.Duration, error)
func (*GoRedisStandaloneOps) TxPipeline ¶ added in v1.9.28
func (ops *GoRedisStandaloneOps) TxPipeline() Pipeline
TxPipeline creates a transaction pipeline
func (*GoRedisStandaloneOps) ZAdd ¶
func (ops *GoRedisStandaloneOps) ZAdd(key string, member ZMember) int64
func (*GoRedisStandaloneOps) ZCard ¶
func (ops *GoRedisStandaloneOps) ZCard(key string) int64
func (*GoRedisStandaloneOps) ZCount ¶
func (ops *GoRedisStandaloneOps) ZCount(key, min, max string) int64
func (*GoRedisStandaloneOps) ZIncrby ¶
func (ops *GoRedisStandaloneOps) ZIncrby(key string, incr float64, member string) float64
func (*GoRedisStandaloneOps) ZInterStore ¶
func (ops *GoRedisStandaloneOps) ZInterStore(destination string, store []ZStore, arg ZStoreEnum) int64
func (*GoRedisStandaloneOps) ZLexCount ¶
func (ops *GoRedisStandaloneOps) ZLexCount(key, min, max string) int64
func (*GoRedisStandaloneOps) ZRange ¶
func (ops *GoRedisStandaloneOps) ZRange(key string, start, stop int64) []string
func (*GoRedisStandaloneOps) ZRangeByLex ¶
func (ops *GoRedisStandaloneOps) ZRangeByLex(key, min, max string, offset int64, count int64) []string
func (*GoRedisStandaloneOps) ZRangeByScore ¶
func (ops *GoRedisStandaloneOps) ZRangeByScore(key, min, max string, offset int64, count int64) []string
func (*GoRedisStandaloneOps) ZRank ¶
func (ops *GoRedisStandaloneOps) ZRank(key, member string) int64
func (*GoRedisStandaloneOps) ZRem ¶
func (ops *GoRedisStandaloneOps) ZRem(key string, member ...string) int64
func (*GoRedisStandaloneOps) ZRemRangeByLex ¶
func (ops *GoRedisStandaloneOps) ZRemRangeByLex(key, min, max string) int64
func (*GoRedisStandaloneOps) ZRemRangeByRank ¶
func (ops *GoRedisStandaloneOps) ZRemRangeByRank(key string, start, stop int64) int64
func (*GoRedisStandaloneOps) ZRevRange ¶
func (ops *GoRedisStandaloneOps) ZRevRange(key string, start, stop int64) []string
func (*GoRedisStandaloneOps) ZRevRangeWithScores ¶
func (ops *GoRedisStandaloneOps) ZRevRangeWithScores(key string, start, stop int64) ([]ZMember, error)
func (*GoRedisStandaloneOps) ZRevRank ¶
func (ops *GoRedisStandaloneOps) ZRevRank(key, member string) int64
func (*GoRedisStandaloneOps) ZScore ¶
func (ops *GoRedisStandaloneOps) ZScore(key, member string) float64
type Hash ¶
type Hash struct {
// contains filtered or unexported fields
}
func (Hash) GetEntries ¶
GetEntries get all hash keys and values
func (Hash) GetHashKeys ¶
GetHashKeys get hask keys for the key
func (Hash) PutIfAbsent ¶
Put put value (struct , int64, float64) to the key and hash key; cmd by SetNx .
type IClient ¶
type IClient interface {
//SetSerializer set value serializer
SetSerializer(ISerializer)
//GetKVOps Returns the operations performed on simple values (or Strings in Redis terminology).
GetKVOps() KV
//GetListOps Returns the operations performed on list values.
GetListOps() List
//GetHashOps Returns the operations performed on hash values.
GetHashOps() Hash
//GetSetOps Returns the operations performed on set values.
GetSetOps() Set
//GetZSetOps Returns the operations performed on zset values (also known as sorted sets).
GetZSetOps() ZSet
//GetGeoOps Geo Returns the operations performed on geo values (also known GIS system).
GetGeoOps() Geo
//GetLockOps Returns the operations performed on locker values.
GetLockOps() *Lock
//GetPubSubOps Returns the operations performed on publish/subscribe values.
GetPubSubOps() PubSub
Close() error
// SetExpire cmd by expire
Ping() (string, error)
// SetExpire cmd by expire
SetExpire(key string, expiration time.Duration) (bool, error)
// SetExpire cmd by TTL
GetExpire(key string) (time.Duration, error)
// Delete delete the key, cmd by del
Delete(key string) bool
// HasKey exists the key, cmd by exists
HasKey(key string) bool
// RandomKey return random Key for db
RandomKey() (string, error)
Info() (string, error)
ListKeys(page uint64, pattern string, pageSize int64) ([]string, int, error)
// GetPipeline creates a pipeline
GetPipeline() Pipeline
// GetTxPipeline creates a transaction pipeline
GetTxPipeline() Pipeline
}
IClient redis client interface
func NewClientFromOps ¶ added in v1.9.28
NewClientFromOps 使用已有的 Ops 创建客户端 这个方法允许使用外部创建的 Ops(如从连接池获取的)
func WrapClient ¶ added in v1.9.28
WrapClient 包装从连接池获取的 Redis 客户端 这个方法用于将数据源连接池中获取的客户端包装为统一的 IClient 接口
type ISerializer ¶
type JsonSerializer ¶
type JsonSerializer struct {
}
func (JsonSerializer) Deserialization ¶
func (serializer JsonSerializer) Deserialization(byt []byte, ptr interface{}) (err error)
func (JsonSerializer) Serialization ¶
func (serializer JsonSerializer) Serialization(value interface{}) ([]byte, error)
type KV ¶
type KV struct {
// contains filtered or unexported fields
}
func (KV) GetAndSet ¶
GetAndSet get value for the key , and that if it's null, set value to the key.
func (KV) MultiSet ¶
MultiSet is like Set but accepts multiple values:
- MSet("key1", "value1", "key2", "value2")
- MSet([]string{"key1", "value1", "key2", "value2"})
- MSet(map[string]interface{}{"key1": "value1", "key2": "value2"})
func (KV) SetIfAbsent ¶
Set set serialization object to the key, redis cmd: setnx
type List ¶
type List struct {
// contains filtered or unexported fields
}
the List elements type is string
func (List) AddElements ¶
AddElements add serialization elements to key list
func (List) GetElement ¶
GetElement get serialization element for key list
func (List) GetElements ¶
GetElements get serialization elements for key list
type Lock ¶
type Lock struct {
// contains filtered or unexported fields
}
func (*Lock) DisposeLock ¶
DisposeLock releases the lock. Note: This method is deprecated, use Unlock instead.
Parameters:
- key: lock key
Returns:
- error: any error that occurred
- bool: true if lock released, false otherwise
func (*Lock) Extend ¶ added in v1.9.28
Extend extends the lock expiration time. Only the lock holder can extend the lock.
Example:
err := lock.Extend("mykey", 30*time.Second)
func (*Lock) ForceUnlock ¶ added in v1.9.28
ForceUnlock forcibly releases the lock regardless of holder. Use with caution!
Example:
err := lock.ForceUnlock("mykey")
func (*Lock) GetDLock ¶
GetDLock acquires a lock with wait timeout. Note: This method is deprecated, use TryLockWithWait instead.
Parameters:
- key: lock key
- waitSecond: wait timeout in seconds
Returns:
- error: any error that occurred
- bool: true if lock acquired, false otherwise
func (*Lock) GetDLockWithTtl ¶ added in v1.9.28
GetDLockWithTtl acquires a lock with TTL and wait timeout. Note: This method is deprecated, use TryLockWithWait instead.
Parameters:
- key: lock key
- waitSecond: wait timeout in seconds
- duration: lock TTL
Returns:
- error: any error that occurred
- bool: true if lock acquired, false otherwise
func (*Lock) IsLocked ¶ added in v1.9.28
IsLocked checks if the lock is currently held.
Example:
ok := lock.IsLocked("mykey")
func (*Lock) LockWithContext ¶ added in v1.9.28
func (lock *Lock) LockWithContext(ctx context.Context, key string, leaseTime time.Duration) (context.Context, error)
LockWithContext acquires a lock and stores it in context for automatic release. The lock will be automatically released when the context is cancelled.
Example: ctx, cancel := context.WithCancel(context.Background()) ctx, err := lock.LockWithContext(ctx, "mykey", 30*time.Second)
if err != nil {
return err
}
defer cancel() // do work with lock
func (*Lock) SetIfAbsent ¶ added in v1.9.28
SetIfAbsent sets the value if the key does not exist (alias for SetNX)
func (*Lock) SetIfAbsentWithTTL ¶ added in v1.9.28
func (lock *Lock) SetIfAbsentWithTTL(key string, value interface{}, duration time.Duration) (bool, error)
SetIfAbsentWithTTL sets the value with TTL if the key does not exist
func (*Lock) TryLock ¶ added in v1.9.28
TryLock attempts to acquire a lock with the specified lease time. Returns true if lock is acquired, false otherwise.
Parameters:
- key: lock key
- leaseTime: lock expiration time (if <= 0, uses default)
Example:
err, ok := lock.TryLock("mykey", 30*time.Second)
func (*Lock) TryLockWithWait ¶ added in v1.9.28
func (lock *Lock) TryLockWithWait(key string, waitTime time.Duration, leaseTime time.Duration) (error, bool)
TryLockWithWait attempts to acquire a lock with wait timeout. This is similar to Redisson's tryLock() method.
Parameters:
- key: lock key
- waitTime: maximum time to wait for lock
- leaseTime: lock expiration time
Example:
err, ok := lock.TryLockWithWait("mykey", 10*time.Second, 30*time.Second)
type Ops ¶
type Ops interface {
Close() error
Ping() (string, error)
DeleteKey(keys ...string) (int64, error)
Exists(key string) (bool, error)
SetExpire(key string, expiration time.Duration) (bool, error)
TTL(key string) (time.Duration, error)
MultiSet(values ...interface{}) error
SetValue(key string, value interface{}, expiration time.Duration) error
Set(key string, value string, expiration time.Duration) error
SetNX(key string, value interface{}) (bool, error)
SetIfAbsent(key string, value interface{}) (bool, error)
SetIfAbsentWithTTL(key string, value interface{}, duration time.Duration) (bool, error)
Get(key string) (string, error)
GetValue(key string) ([]byte, error)
Append(key string, value string) (int64, error)
StrLen(key string) (int64, error)
GetRange(key string, start int64, end int64) (string, error)
RandomKey() (string, error)
MultiGet(key ...string) ([]interface{}, error)
IncrBy(key string, step int64) (int64, error)
LIndex(key string, index int64) (string, error)
LPop(key string) (string, error)
LPush(key string, values ...interface{}) (int64, error)
LRange(key string, start int64, end int64) ([]string, error)
LTrim(key string, start int64, end int64) error
RPop(key string) (string, error)
RPush(key string, values ...interface{}) (int64, error)
LSet(key string, index int64, value interface{}) error
LSize(key string) (int64, error)
LRemove(key string, count int64, value interface{}) (int64, error)
GeoAddArr(key string, geoLocation ...GeoPosition) int64
GeoPos(key string, members ...string) (error, []GeoPosition)
GeoDist(key string, member1, member2 string, unit GeoUnit) (error, GeoDistInfo)
GeoRadius(key string, query GeoRadiusQuery) (error, []GeoPosition)
GeoRadiusByMember(key string, member string, query GeoRadiusByMemberQuery) (error, []GeoPosition)
SAdd(key string, members ...interface{}) (int64, error)
SDiff(keys ...string) ([]string, error)
SCard(key string) (int64, error)
SInter(keys ...string) ([]string, error)
SInterStore(destination string, keys ...string) (int64, error)
SIsMember(key string, member interface{}) (bool, error)
SMembers(key string) ([]string, error)
SMove(source string, destination string, member interface{}) (bool, error)
SPop(key string) (string, error)
SRandMembers(key string, count int64) ([]string, error)
SRem(key string, members ...interface{}) (int64, error)
SUnion(keys ...string) ([]string, error)
SUnionStore(destination string, keys ...string) (int64, error)
HDel(key string, fields ...string) (int64, error)
HExists(key string, field string) (bool, error)
HGet(key string, field string) (string, error)
HGetAll(key string) (map[string]string, error)
HIncrBy(key string, field string, increment int64) (int64, error)
HKeys(key string) ([]string, error)
HLen(key string) (int64, error)
HMGet(key string, fields ...string) ([]interface{}, error)
HSet(key string, field string, value interface{}) (int64, error)
HSetNX(key string, field string, value interface{}) (bool, error)
HVals(key string) ([]string, error)
ZAdd(key string, member ZMember) int64
ZCard(key string) int64
ZCount(key, min, max string) int64
ZIncrby(key string, incr float64, member string) float64
ZInterStore(destination string, store []ZStore, arg ZStoreEnum) int64
ZLexCount(key, min, max string) int64
ZRange(key string, start, stop int64) []string
ZRangeByLex(key, min, max string, offset int64, count int64) []string
ZRangeByScore(key, min, max string, offset int64, count int64) []string
ZRank(key, member string) int64
ZRem(key string, member ...string) int64
ZRemRangeByLex(key, min, max string) int64
ZRemRangeByRank(key string, start, stop int64) int64
ZRevRange(key string, start, stop int64) []string
ZRevRangeWithScores(key string, start, stop int64) ([]ZMember, error)
ZRevRank(key, member string) int64
ZScore(key, member string) float64
Info() (string, error)
ListKeys(page uint64, pattern string, pageSize int64) ([]string, int, error)
Publish(channel string, message interface{}) (int64, error)
Subscribe(channels ...string) (*Subscription, error)
PSubscribe(patterns ...string) (*Subscription, error)
SetNXTtl(key string, value interface{}, duration time.Duration) (bool, error)
Eval(script string, keys []string, args ...interface{}) (interface{}, error)
Pipeline() Pipeline
TxPipeline() Pipeline
}
type Options ¶
type Options struct {
Addr string
Addrs []string
Password string
DB int
// 连接池配置 (v9 优化)
PoolSize int // 连接池大小,默认 10
MinIdleConns int // 最小空闲连接数,默认 2
MaxRetries int // 最大重试次数,默认 3
MinRetryBackoff time.Duration // 最小重试间隔,默认 8ms
MaxRetryBackoff time.Duration // 最大重试间隔,默认 512ms
DialTimeout time.Duration // 连接超时,默认 5s
ReadTimeout time.Duration // 读取超时,默认 3s
WriteTimeout time.Duration // 写入超时,默认 3s
PoolTimeout time.Duration // 连接池超时,默认 4s
ConnMaxIdleTime time.Duration // 连接间隔时间,默认 1m
}
type Pipeline ¶ added in v1.9.28
type Pipeline interface {
// Set 批量设置值
Set(key string, value interface{}, expiration time.Duration) *redis.StatusCmd
// Get 批量获取值
Get(key string) *redis.StringCmd
// SetNX 批量设置值(仅当键不存在)
SetNX(key string, value interface{}, expiration time.Duration) *redis.BoolCmd
// Del 批量删除键
Del(keys ...string) *redis.IntCmd
// Incr 批量递增
Incr(key string) *redis.IntCmd
// IncrBy 批量递增指定步长
IncrBy(key string, value int64) *redis.IntCmd
// HSet 批量设置哈希字段
HSet(key string, field string, value interface{}) *redis.IntCmd
// HGet 批量获取哈希字段
HGet(key string, field string) *redis.StringCmd
// ZAdd 批量添加有序集合成员
ZAdd(key string, members ...redis.Z) *redis.IntCmd
// SAdd 批量添加无序集合成员
SAdd(key string, members ...interface{}) *redis.IntCmd
// LPush 批量列表左推入
LPush(key string, values ...interface{}) *redis.IntCmd
// RPush 批量列表右推入
RPush(key string, values ...interface{}) *redis.IntCmd
// MGet 批量获取多个键
MGet(keys ...string) *redis.SliceCmd
// MSet 批量设置多个键
MSet(pairs ...interface{}) *redis.StatusCmd
// Exec 执行所有命令
Exec(ctx context.Context) ([]redis.Cmder, error)
// Discard 丢弃 Pipeline
Discard()
}
Pipeline 封装 Redis Pipeline 操作,支持批量执行命令 v9 的 Pipeline 性能相比 v8 提升了约 38%
func NewPipeline ¶ added in v1.9.28
func NewPipeline(client redis.Pipeliner, serializer ISerializer) Pipeline
NewPipeline 创建新的 Pipeline
type PubSub ¶ added in v1.9.28
type PubSub struct {
// contains filtered or unexported fields
}
PubSub provides pub/sub operations following the pattern of KV, List, etc.
func (PubSub) PSubscribe ¶ added in v1.9.28
func (ps PubSub) PSubscribe(patterns ...string) (*Subscription, error)
PSubscribe subscribes to channels matching the given patterns
func (PubSub) PSubscribeWithCallback ¶ added in v1.9.28
func (ps PubSub) PSubscribeWithCallback(callback func(*Message), patterns ...string) (*Subscription, error)
PSubscribeWithCallback subscribes to patterns and invokes callback for each message
func (PubSub) ReceiveMessage ¶ added in v1.9.28
ReceiveMessage receives a single message from a channel
func (PubSub) ReceiveMessageTimeout ¶ added in v1.9.28
ReceiveMessageTimeout receives a single message from a channel with timeout
func (PubSub) ReceiveMessages ¶ added in v1.9.28
func (ps PubSub) ReceiveMessages(channel string, messageChan chan<- *Message) (*Subscription, error)
ReceiveMessages continuously receives messages from a channel
func (PubSub) ReceiveMessagesWithPattern ¶ added in v1.9.28
func (ps PubSub) ReceiveMessagesWithPattern(pattern string, messageChan chan<- *Message) (*Subscription, error)
ReceiveMessagesWithPattern continuously receives messages matching a pattern
func (PubSub) Subscribe ¶ added in v1.9.28
func (ps PubSub) Subscribe(channels ...string) (*Subscription, error)
Subscribe subscribes to the specified channels
func (PubSub) SubscribeWithCallback ¶ added in v1.9.28
func (ps PubSub) SubscribeWithCallback(callback func(*Message), channels ...string) (*Subscription, error)
SubscribeWithCallback subscribes to channels and invokes callback for each message
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
func (Set) IntersectAndStore ¶
type Subscription ¶ added in v1.9.28
type Subscription struct {
// contains filtered or unexported fields
}
Subscription represents a Redis pub/sub subscription
func (*Subscription) Channel ¶ added in v1.9.28
func (s *Subscription) Channel() <-chan *Message
Channel returns a go channel for receiving messages
func (*Subscription) Close ¶ added in v1.9.28
func (s *Subscription) Close() error
Close closes the subscription
func (*Subscription) Ping ¶ added in v1.9.28
func (s *Subscription) Ping() error
Ping sends a PING to the server
func (*Subscription) ReceiveMessage ¶ added in v1.9.28
func (s *Subscription) ReceiveMessage() (*Message, error)
ReceiveMessage receives a message from the subscription
type ZSet ¶
type ZSet struct {
// contains filtered or unexported fields
}
func (*ZSet) ZInterStore ¶
func (zSet *ZSet) ZInterStore(destination string, store []ZStore, arg ZStoreEnum) int64
func (*ZSet) ZRangeByLex ¶
func (*ZSet) ZRangeByScore ¶
func (*ZSet) ZRemRangeByLex ¶
func (*ZSet) ZRemRangeByRank ¶
func (*ZSet) ZRevRangeWithScores ¶
type ZStoreEnum ¶
type ZStoreEnum string
const ( MAX ZStoreEnum = "MAX" MIN ZStoreEnum = "MIN" SUM ZStoreEnum = "SUM" )