Documentation ¶
Overview ¶
Package bedis means bscp redis client package
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrKeyNotExist = errors.New("redis key not exist")
ErrKeyNotExist describe the error that the key is not exist in redis.
Functions ¶
func IsNilError ¶
IsNilError test if the error is returned with redis client and is a nil error which means get the key with a nil value.
func IsWrongTypeError ¶
IsWrongTypeError test if an error is caused by used the wrong redis command
Types ¶
type Client ¶
type Client interface { Set(ctx context.Context, key string, value interface{}, ttlSeconds int) error SetWithTxnPipe(ctx context.Context, kv map[string]string, ttlSeconds int) error HGetWithTxnPipe(ctx context.Context, hashKey string, field string) (string, error) SetNX(ctx context.Context, key string, value interface{}, ttlSeconds int) (bool, error) Get(ctx context.Context, key string) (string, error) GetSet(ctx context.Context, key string, value interface{}) (string, error) MGet(ctx context.Context, key ...string) ([]string, error) HSets(ctx context.Context, hashKey string, kv map[string]string, ttlSeconds int) error HDelete(ctx context.Context, hashKey string, subKey []string) error HDeleteWithTxPipe(ctx context.Context, multiHash map[string][]string) error DeleteWithTxPipe(ctx context.Context, keys []string) error HGet(ctx context.Context, hashKey string, field string) (string, error) HMGet(ctx context.Context, hashKey string, fields ...string) ([]string, error) HGetAll(ctx context.Context, hashKey string) (map[string]string, error) Delete(ctx context.Context, keys ...string) error Expire(ctx context.Context, key string, ttlSeconds int, mode ExpireMode) error Healthz() error LPush(ctx context.Context, key string, values ...interface{}) error RPush(ctx context.Context, key string, values ...interface{}) error LRange(ctx context.Context, key string, start, stop int64) ([]string, error) RPop(ctx context.Context, key string) (string, error) Keys(ctx context.Context, pattern string) ([]string, error) LLen(ctx context.Context, key string) (int64, error) LTrim(ctx context.Context, key string, start, stop int64) (string, error) LRem(ctx context.Context, key string, count int64, value interface{}) error RPopLPush(ctx context.Context, source, destination string) (string, error) BRPopLPush(ctx context.Context, source, destination string, ttlSeconds int) (string, error) ZAdd(ctx context.Context, key string, score float64, value interface{}) (int64, error) ZRangeByScoreWithScores(ctx context.Context, key string, zRangeBy *redis.ZRangeBy) ([]redis.Z, error) ZRem(ctx context.Context, key string, members ...interface{}) (int64, error) }
Client defines all the bscp used redis command
func NewRedisCache ¶
func NewRedisCache(opt cc.RedisCluster) (Client, error)
NewRedisCache create a redis cluster client.
type ExpireMode ¶
type ExpireMode string
ExpireMode defines the mode that how a key is to expire.
const ( // NX -- Set expiry only when the key has no expiry NX ExpireMode = "NX" // XX -- Set expiry only when the key has an existing expiry XX ExpireMode = "XX" // GT -- Set expiry only when the new expiry is greater than current one GT ExpireMode = "GT" // LT -- Set expiry only when the new expiry is less than current one LT ExpireMode = "LT" )
type RedisClient ¶
type RedisClient interface { Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.StatusCmd TxPipeline() redis.Pipeliner SetNX(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.BoolCmd Get(ctx context.Context, key string) *redis.StringCmd GetSet(ctx context.Context, key string, value interface{}) *redis.StringCmd MGet(ctx context.Context, keys ...string) *redis.SliceCmd HDel(ctx context.Context, key string, fields ...string) *redis.IntCmd HGet(ctx context.Context, key, field string) *redis.StringCmd HMGet(ctx context.Context, key string, fields ...string) *redis.SliceCmd HGetAll(ctx context.Context, key string) *redis.StringStringMapCmd Del(ctx context.Context, keys ...string) *redis.IntCmd Do(ctx context.Context, args ...interface{}) *redis.Cmd Ping(ctx context.Context) *redis.StatusCmd LPush(ctx context.Context, key string, values ...interface{}) *redis.IntCmd RPush(ctx context.Context, key string, values ...interface{}) *redis.IntCmd LRange(ctx context.Context, key string, start, stop int64) *redis.StringSliceCmd RPop(ctx context.Context, key string) *redis.StringCmd Keys(ctx context.Context, pattern string) *redis.StringSliceCmd LLen(ctx context.Context, key string) *redis.IntCmd LTrim(ctx context.Context, key string, start, stop int64) *redis.StatusCmd LRem(ctx context.Context, key string, count int64, value interface{}) *redis.IntCmd RPopLPush(ctx context.Context, source, destination string) *redis.StringCmd BRPopLPush(ctx context.Context, source, destination string, timeout time.Duration) *redis.StringCmd ZAdd(ctx context.Context, key string, members ...*redis.Z) *redis.IntCmd ZRangeByScoreWithScores(ctx context.Context, key string, opt *redis.ZRangeBy) *redis.ZSliceCmd ZRem(ctx context.Context, key string, members ...interface{}) *redis.IntCmd }
RedisClient redis cluster/standalone 方法
Click to show internal directories.
Click to hide internal directories.