redisx

package
v1.0.0-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 19, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTimeOut = 10

DefaultTimeOut 默认超时时间10秒

Variables

This section is empty.

Functions

func IsNil

func IsNil(err error) bool

func TimeOutCtx

func TimeOutCtx(timeout int64) (context.Context, context.CancelFunc)

Types

type DB

type DB struct {
	CtxTimeOut int64
	Cfg        Info
	// contains filtered or unexported fields
}

func (*DB) Close

func (c *DB) Close() error

Close close redis client

func (*DB) Decr

func (c *DB) Decr(key string) *redis.IntCmd

func (*DB) DecrBy

func (c *DB) DecrBy(key string, decrement int64) *redis.IntCmd

func (*DB) Del

func (c *DB) Del(key string, options ...OptionHandler) bool

func (*DB) Exists

func (c *DB) Exists(keys ...string) bool

func (*DB) Expire

func (c *DB) Expire(key string, ttl time.Duration) bool

Expire 设置过期时间(多久之后过期)

func (*DB) ExpireAt

func (c *DB) ExpireAt(key string, ttl time.Time) bool

ExpireAt 设置过期时间(在某一时刻过期)

func (*DB) Get

func (c *DB) Get(key string, options ...OptionHandler) (string, error)

Get get some key from redis

func (*DB) GetBit

func (c *DB) GetBit(key string, offset int64) *redis.IntCmd

func (*DB) GetConn

func (c *DB) GetConn() *redis.Client

func (*DB) GetDel

func (c *DB) GetDel(key string) *redis.StringCmd

func (*DB) GetEx

func (c *DB) GetEx(key string, expiration time.Duration) *redis.StringCmd

func (*DB) GetRange

func (c *DB) GetRange(key string, start int64, end int64) *redis.StringCmd

func (*DB) GetSet

func (c *DB) GetSet(key string, value interface{}) *redis.StringCmd

func (*DB) HDel

func (c *DB) HDel(key string, fields ...string) *redis.IntCmd

func (*DB) HExists

func (c *DB) HExists(key string, field string) *redis.BoolCmd

func (*DB) HGet

func (c *DB) HGet(key string, field string) *redis.StringCmd

func (*DB) HGetAll

func (c *DB) HGetAll(key string) *redis.MapStringStringCmd

func (*DB) HIncrBy

func (c *DB) HIncrBy(key string, field string, incr int64) *redis.IntCmd

func (*DB) HIncrByFloat

func (c *DB) HIncrByFloat(key string, field string, incr float64) *redis.FloatCmd

func (*DB) HKeys

func (c *DB) HKeys(key string) *redis.StringSliceCmd

func (*DB) HLen

func (c *DB) HLen(key string) *redis.IntCmd

func (*DB) HMGet

func (c *DB) HMGet(key string, fields ...string) *redis.SliceCmd

func (*DB) HMSet

func (c *DB) HMSet(key string, values ...interface{}) *redis.BoolCmd

func (*DB) HSet

func (c *DB) HSet(key string, values ...interface{}) *redis.IntCmd

func (*DB) HSetNX

func (c *DB) HSetNX(key string, field string, value interface{}) *redis.BoolCmd

func (*DB) Incr

func (c *DB) Incr(key string, options ...OptionHandler) int64

func (*DB) IncrBy

func (c *DB) IncrBy(key string, value int64) *redis.IntCmd

func (*DB) IncrByFloat

func (c *DB) IncrByFloat(key string, value float64) *redis.FloatCmd

func (*DB) Keys

func (c *DB) Keys(pattern string) *redis.StringSliceCmd

func (*DB) LIndex

func (c *DB) LIndex(key string, index int64) *redis.StringCmd

func (*DB) LInsert

func (c *DB) LInsert(key string, op string, pivot interface{}, value interface{}) *redis.IntCmd

func (*DB) LInsertAfter

func (c *DB) LInsertAfter(key string, pivot interface{}, value interface{}) *redis.IntCmd

func (*DB) LInsertBefore

func (c *DB) LInsertBefore(key string, pivot interface{}, value interface{}) *redis.IntCmd

func (*DB) LLen

func (c *DB) LLen(key string) *redis.IntCmd

func (*DB) LMove

func (c *DB) LMove(source string, destination string, srcpos string, destpos string) *redis.StringCmd

func (*DB) LPop

func (c *DB) LPop(key string) *redis.StringCmd

func (*DB) LPopCount

func (c *DB) LPopCount(key string, count int) *redis.StringSliceCmd

func (*DB) LPos

func (c *DB) LPos(key string, value string, a redis.LPosArgs) *redis.IntCmd

func (*DB) LPosCount

func (c *DB) LPosCount(key string, value string, count int64, a redis.LPosArgs) *redis.IntSliceCmd

func (*DB) LPush

func (c *DB) LPush(key string, values ...interface{}) *redis.IntCmd

func (*DB) LPushX

func (c *DB) LPushX(key string, values ...interface{}) *redis.IntCmd

func (*DB) LRange

func (c *DB) LRange(key string, start int64, stop int64) *redis.StringSliceCmd

func (*DB) LRem

func (c *DB) LRem(key string, count int64, value interface{}) *redis.IntCmd

func (*DB) LSet

func (c *DB) LSet(key string, index int64, value interface{}) *redis.StatusCmd

func (*DB) LTrim

func (c *DB) LTrim(key string, start int64, stop int64) *redis.StatusCmd

func (*DB) MGet

func (c *DB) MGet(keys ...string) *redis.SliceCmd

func (*DB) MSet

func (c *DB) MSet(values ...interface{}) *redis.StatusCmd

func (*DB) MSetNX

func (c *DB) MSetNX(values ...interface{}) *redis.BoolCmd

func (*DB) Move

func (c *DB) Move(key string, db int) *redis.BoolCmd

func (*DB) Publish

func (c *DB) Publish(channel string, message interface{}) (int64, error)

func (*DB) RPop

func (c *DB) RPop(key string) *redis.StringCmd

func (*DB) RPopCount

func (c *DB) RPopCount(key string, count int) *redis.StringSliceCmd

func (*DB) RPopLPush

func (c *DB) RPopLPush(source string, destination string) *redis.StringCmd

func (*DB) RPush

func (c *DB) RPush(key string, values ...interface{}) *redis.IntCmd

func (*DB) RPushX

func (c *DB) RPushX(key string, values ...interface{}) *redis.IntCmd

func (*DB) SAdd

func (c *DB) SAdd(key string, members ...interface{}) *redis.IntCmd

func (*DB) SCard

func (c *DB) SCard(key string) *redis.IntCmd

func (*DB) SIsMember

func (c *DB) SIsMember(key string, member interface{}) *redis.BoolCmd

func (*DB) SMembers

func (c *DB) SMembers(key string) *redis.StringSliceCmd

func (*DB) SPop

func (c *DB) SPop(key string) *redis.StringCmd

func (*DB) SPopN

func (c *DB) SPopN(key string, count int64) *redis.StringSliceCmd

func (*DB) SRem

func (c *DB) SRem(key string, members ...interface{}) *redis.IntCmd

func (*DB) Set

func (c *DB) Set(key, value string, ttl time.Duration, options ...OptionHandler) error

Set set some <key,value> into redis

func (*DB) SetBit

func (c *DB) SetBit(key string, offset int64, value int) *redis.IntCmd

func (*DB) SetEX

func (c *DB) SetEX(key string, value interface{}, expiration time.Duration) *redis.StatusCmd

func (*DB) SetNX

func (c *DB) SetNX(key string, value interface{}, expiration time.Duration) *redis.BoolCmd

func (*DB) Sort

func (c *DB) Sort(key string, sort *redis.Sort) *redis.StringSliceCmd

func (*DB) SortInterfaces

func (c *DB) SortInterfaces(key string, sort *redis.Sort) *redis.SliceCmd

func (*DB) SortStore

func (c *DB) SortStore(key string, store string, sort *redis.Sort) *redis.IntCmd

func (*DB) Subscribe

func (c *DB) Subscribe(handler SubHandler, channels ...string) error

func (*DB) TTL

func (c *DB) TTL(key string) (time.Duration, error)

TTL 获取某个key的过期时间

func (*DB) ZAddNX

func (c *DB) ZAddNX(key string, members ...redis.Z) *redis.IntCmd

func (*DB) ZAddXX

func (c *DB) ZAddXX(key string, members ...redis.Z) *redis.IntCmd

func (*DB) ZCard

func (c *DB) ZCard(key string) *redis.IntCmd

func (*DB) ZCount

func (c *DB) ZCount(key, min, max string) *redis.IntCmd

func (*DB) ZIncrBy

func (c *DB) ZIncrBy(key string, increment float64, member string) *redis.FloatCmd

func (*DB) ZInter

func (c *DB) ZInter(store *redis.ZStore) *redis.StringSliceCmd

func (*DB) ZInterStore

func (c *DB) ZInterStore(destination string, store *redis.ZStore) *redis.IntCmd

func (*DB) ZInterWithScores

func (c *DB) ZInterWithScores(store *redis.ZStore) *redis.ZSliceCmd

func (*DB) ZLexCount

func (c *DB) ZLexCount(key, min, max string) *redis.IntCmd

func (*DB) ZMScore

func (c *DB) ZMScore(key string, members ...string) *redis.FloatSliceCmd

func (*DB) ZPopMax

func (c *DB) ZPopMax(key string, count ...int64) *redis.ZSliceCmd

func (*DB) ZPopMin

func (c *DB) ZPopMin(key string, count ...int64) *redis.ZSliceCmd

func (*DB) ZRem

func (c *DB) ZRem(key string, members ...interface{}) *redis.IntCmd

type Info

type Info struct {
	Addr         string `toml:"Addr" json:"Addr"`
	Pass         string `toml:"Pass" json:"Pass"`
	Db           int    `toml:"Db" json:"Db"`
	MaxRetries   int    `toml:"MaxRetries" json:"MaxRetries"`
	PoolSize     int    `toml:"PoolSize" json:"PoolSize"`
	MinIDleConns int    `toml:"MinIDleConns" json:"MinIDleConns"`
	// 超时时间, 单位秒. 拨号超时, 读写超时采用同一个配置.
	TimeOut int64 `toml:"TimeOut" json:"TimeOut"`
	// redis哨兵相关配置
	Sentinel SentinelInfo `toml:"Sentinel" json:"Sentinel"`
}

type OptionHandler

type OptionHandler func(*option)

func WithTrace

func WithTrace(t Trace) OptionHandler

WithTrace 设置trace信息

type Repo

type Repo interface {
	Set(key, value string, ttl time.Duration, options ...OptionHandler) error
	Get(key string, options ...OptionHandler) (string, error)
	TTL(key string) (time.Duration, error)
	Expire(key string, ttl time.Duration) bool
	ExpireAt(key string, ttl time.Time) bool
	Del(key string, options ...OptionHandler) bool
	Exists(keys ...string) bool
	Incr(key string, options ...OptionHandler) int64
	Close() error
	GetConn() *redis.Client

	// Publish 发布消息
	Publish(channel string, message interface{}) (int64, error)
	// Subscribe 订阅消息
	Subscribe(handler SubHandler, channels ...string) error

	Keys(pattern string) *redis.StringSliceCmd
	Move(key string, db int) *redis.BoolCmd
	Sort(key string, sort *redis.Sort) *redis.StringSliceCmd
	SortStore(key string, store string, sort *redis.Sort) *redis.IntCmd
	SortInterfaces(key string, sort *redis.Sort) *redis.SliceCmd
	Decr(key string) *redis.IntCmd
	DecrBy(key string, decrement int64) *redis.IntCmd
	GetRange(key string, start int64, end int64) *redis.StringCmd
	GetSet(key string, value interface{}) *redis.StringCmd
	GetEx(key string, expiration time.Duration) *redis.StringCmd
	GetDel(key string) *redis.StringCmd
	IncrBy(key string, value int64) *redis.IntCmd
	IncrByFloat(key string, value float64) *redis.FloatCmd
	MGet(keys ...string) *redis.SliceCmd
	MSet(values ...interface{}) *redis.StatusCmd
	MSetNX(values ...interface{}) *redis.BoolCmd
	SetEX(key string, value interface{}, expiration time.Duration) *redis.StatusCmd
	SetNX(key string, value interface{}, expiration time.Duration) *redis.BoolCmd
	GetBit(key string, offset int64) *redis.IntCmd
	SetBit(key string, offset int64, value int) *redis.IntCmd
	HDel(key string, fields ...string) *redis.IntCmd
	HExists(key string, field string) *redis.BoolCmd
	HGet(key string, field string) *redis.StringCmd
	HGetAll(key string) *redis.MapStringStringCmd
	HIncrBy(key string, field string, incr int64) *redis.IntCmd
	HIncrByFloat(key string, field string, incr float64) *redis.FloatCmd
	HKeys(key string) *redis.StringSliceCmd
	HLen(key string) *redis.IntCmd
	HMGet(key string, fields ...string) *redis.SliceCmd
	HSet(key string, values ...interface{}) *redis.IntCmd
	HMSet(key string, values ...interface{}) *redis.BoolCmd
	HSetNX(key string, field string, value interface{}) *redis.BoolCmd
	LIndex(key string, index int64) *redis.StringCmd
	LInsert(key string, op string, pivot interface{}, value interface{}) *redis.IntCmd
	LInsertBefore(key string, pivot interface{}, value interface{}) *redis.IntCmd
	LInsertAfter(key string, pivot interface{}, value interface{}) *redis.IntCmd
	LLen(key string) *redis.IntCmd
	LPop(key string) *redis.StringCmd
	LPopCount(key string, count int) *redis.StringSliceCmd
	LPos(key string, value string, a redis.LPosArgs) *redis.IntCmd
	LPosCount(key string, value string, count int64, a redis.LPosArgs) *redis.IntSliceCmd
	LPush(key string, values ...interface{}) *redis.IntCmd
	LPushX(key string, values ...interface{}) *redis.IntCmd
	LRange(key string, start int64, stop int64) *redis.StringSliceCmd
	LRem(key string, count int64, value interface{}) *redis.IntCmd
	LSet(key string, index int64, value interface{}) *redis.StatusCmd
	LTrim(key string, start int64, stop int64) *redis.StatusCmd
	RPop(key string) *redis.StringCmd
	RPopCount(key string, count int) *redis.StringSliceCmd
	RPopLPush(source string, destination string) *redis.StringCmd
	RPush(key string, values ...interface{}) *redis.IntCmd
	RPushX(key string, values ...interface{}) *redis.IntCmd
	LMove(source string, destination string, srcpos string, destpos string) *redis.StringCmd
	SAdd(key string, members ...interface{}) *redis.IntCmd
	SCard(key string) *redis.IntCmd
	SIsMember(key string, member interface{}) *redis.BoolCmd
	SMembers(key string) *redis.StringSliceCmd
	SPop(key string) *redis.StringCmd
	SPopN(key string, count int64) *redis.StringSliceCmd
	SRem(key string, members ...interface{}) *redis.IntCmd

	ZAddNX(key string, members ...redis.Z) *redis.IntCmd
	ZAddXX(key string, members ...redis.Z) *redis.IntCmd
	ZCard(key string) *redis.IntCmd
	ZRem(key string, members ...interface{}) *redis.IntCmd
	ZCount(key, min, max string) *redis.IntCmd
	ZLexCount(key, min, max string) *redis.IntCmd
	ZIncrBy(key string, increment float64, member string) *redis.FloatCmd
	ZInterStore(destination string, store *redis.ZStore) *redis.IntCmd
	ZInter(store *redis.ZStore) *redis.StringSliceCmd
	ZInterWithScores(store *redis.ZStore) *redis.ZSliceCmd
	ZMScore(key string, members ...string) *redis.FloatSliceCmd
	ZPopMax(key string, count ...int64) *redis.ZSliceCmd
	ZPopMin(key string, count ...int64) *redis.ZSliceCmd
}

func Default

func Default() Repo

func New

func New(cfg Info) (Repo, error)

type SentinelInfo

type SentinelInfo struct {
	MasterName       string   `toml:"MasterName" json:"MasterName"`
	SentinelAddrs    []string `toml:"SentinelAddrs" json:"SentinelAddrs"`
	SentinelPassword string   `toml:"SentinelPassword" json:"SentinelPassword"`
}

type SubHandler

type SubHandler func(msg *redis.Message) error

type Trace

type Trace = trace.T

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL