redis

package
v0.0.0-...-d6ac821 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RedisClusterConfig

type RedisClusterConfig struct {
	// Addrs 集群实例配置地址
	Addrs []string `json:"addrs"`
	// Password 密码
	Password string `json:"password"`
	// DB,默认为0, 一般应用不推荐使用DB分片
	DB int `json:"db"`
	// PoolSize 集群内每个节点的最大连接池限制 默认每个CPU10个连接
	PoolSize int `json:"poolSize"`
	// MaxRedirects 网络相关的错误最大重试次数 默认8次
	MaxRedirects int `json:"maxRedirects"`
	// MinIdleConns 最小空闲连接数
	MinIdleConns int `json:"minIdleConns"`
	// DialTimeout 拨超时时间
	DialTimeout time.Duration `json:"dialTimeout"`
	// ReadTimeout 读超时 默认3s
	ReadTimeout time.Duration `json:"readTimeout"`
	// WriteTimeout 读超时 默认3s
	WriteTimeout time.Duration `json:"writeTimeout"`
	// IdleTimeout 连接最大空闲时间,默认60s, 超过该时间,连接会被主动关闭
	IdleTimeout time.Duration `json:"idleTimeout"`
	// ReadOnly 集群模式 在从属节点上启用读模式
	ReadOnly bool `json:"readOnly"`
	// Debug开关
	Debug bool `json:"debug"`
	// 是否开启链路追踪,开启以后。使用DoCotext的请求会被trace
	EnableTrace bool `json:"enableTrace"`
	// 慢日志门限值,超过该门限值的请求,将被记录到慢日志中
	SlowThreshold time.Duration `json:"slowThreshold"`
	// OnDialError panic|error
	OnDialError string `json:"level"`
	// contains filtered or unexported fields
}

RedisClusterConfig redis集群配置信息

func DefaultRedisClusterConfig

func DefaultRedisClusterConfig() RedisClusterConfig

DefaultRedisClusterConfig ...

func RawRedisClusterConfig

func RawRedisClusterConfig(key string) RedisClusterConfig

RawRedisConfig ...

func StdRedisClusterConfig

func StdRedisClusterConfig(name string) RedisClusterConfig

StdRedisClusterConfig ...

func (RedisClusterConfig) Build

func (config RedisClusterConfig) Build() *RedisClusterStub

Build ...

type RedisClusterStub

type RedisClusterStub struct {
	Client *redis.ClusterClient
	// contains filtered or unexported fields
}

RedisClusterStub is an cluster manager.

func (*RedisClusterStub) Close

func (rc *RedisClusterStub) Close() (err error)

Close closes the cluster client, releasing any open resources.

It is rare to Close a ClusterClient, as the ClusterClient is meant to be long-lived and shared between many goroutines.

func (*RedisClusterStub) Decr

func (rc *RedisClusterStub) Decr(key string) bool

Decr redis自减

func (*RedisClusterStub) Del

func (rc *RedisClusterStub) Del(key string) int64

Del redis删除

func (*RedisClusterStub) DelWithErr

func (rc *RedisClusterStub) DelWithErr(key string) (int64, error)

DelWithErr ...

func (*RedisClusterStub) Exists

func (rc *RedisClusterStub) Exists(key string) bool

Exists 键是否存在

func (*RedisClusterStub) ExistsWithErr

func (rc *RedisClusterStub) ExistsWithErr(key string) (bool, error)

ExistsWithErr ...

func (*RedisClusterStub) Expire

func (rc *RedisClusterStub) Expire(key string, expiration time.Duration) (bool, error)

Expire 设置过期时间

func (*RedisClusterStub) GeoAdd

func (rc *RedisClusterStub) GeoAdd(key string, location *redis.GeoLocation) (int64, error)

GeoAdd 写入地理位置

func (*RedisClusterStub) GeoRadius

func (rc *RedisClusterStub) GeoRadius(key string, longitude, latitude float64, query *redis.GeoRadiusQuery) ([]redis.GeoLocation, error)

GeoRadius 根据经纬度查询列表

func (*RedisClusterStub) Get

func (rc *RedisClusterStub) Get(key string) string

Get 从redis获取string

func (*RedisClusterStub) GetRaw

func (rc *RedisClusterStub) GetRaw(key string) ([]byte, error)

GetRaw ...

func (*RedisClusterStub) HDel

func (rc *RedisClusterStub) HDel(key string, field ...string) bool

HDel ...

func (*RedisClusterStub) HGet

func (rc *RedisClusterStub) HGet(key string, fields string) (string, error)

HGet 从redis获取hash单个值

func (*RedisClusterStub) HGetAll

func (rc *RedisClusterStub) HGetAll(key string) map[string]string

HGetAll 从redis获取hash的所有键值对

func (*RedisClusterStub) HIncrBy

func (rc *RedisClusterStub) HIncrBy(key string, field string, incr int) int64

HIncrBy 哈希field自增

func (*RedisClusterStub) HIncrByWithErr

func (rc *RedisClusterStub) HIncrByWithErr(key string, field string, incr int) (int64, error)

HIncrBy 哈希field自增并且返回错误

func (*RedisClusterStub) HKeys

func (rc *RedisClusterStub) HKeys(key string) []string

HKeys 获取hash的所有域

func (*RedisClusterStub) HLen

func (rc *RedisClusterStub) HLen(key string) int64

HLen 获取hash的长度

func (*RedisClusterStub) HMGet

func (rc *RedisClusterStub) HMGet(key string, fileds []string) []string

HMGet 批量获取hash值

func (*RedisClusterStub) HMGetMap

func (rc *RedisClusterStub) HMGetMap(key string, fields []string) map[string]string

HMGetMap 批量获取hash值,返回map

func (*RedisClusterStub) HMSet

func (rc *RedisClusterStub) HMSet(key string, hash map[string]interface{}, expire time.Duration) bool

HMSet 设置redis的hash

func (*RedisClusterStub) HSet

func (rc *RedisClusterStub) HSet(key string, field string, value interface{}) bool

HSet hset

func (*RedisClusterStub) Incr

func (rc *RedisClusterStub) Incr(key string) bool

Incr redis自增

func (*RedisClusterStub) IncrBy

func (rc *RedisClusterStub) IncrBy(key string, increment int64) (int64, error)

IncrBy 将 key 所储存的值加上增量 increment 。

func (*RedisClusterStub) IncrWithErr

func (rc *RedisClusterStub) IncrWithErr(key string) (int64, error)

IncrWithErr ...

func (*RedisClusterStub) LIndex

func (rc *RedisClusterStub) LIndex(key string, idx int64) (string, error)

LIndex ...

func (*RedisClusterStub) LLen

func (rc *RedisClusterStub) LLen(key string) int64

LLen ...

func (*RedisClusterStub) LLenWithErr

func (rc *RedisClusterStub) LLenWithErr(key string) (int64, error)

LLenWithErr ...

func (*RedisClusterStub) LPush

func (rc *RedisClusterStub) LPush(key string, values ...interface{}) (int64, error)

LPush 将一个或多个值 value 插入到列表 key 的表头

func (*RedisClusterStub) LRange

func (rc *RedisClusterStub) LRange(key string, start, stop int64) ([]string, error)

LRange 获取列表指定范围内的元素

func (*RedisClusterStub) LRem

func (rc *RedisClusterStub) LRem(key string, count int64, value interface{}) int64

LRem ...

func (*RedisClusterStub) LTrim

func (rc *RedisClusterStub) LTrim(key string, start, stop int64) (string, error)

LTrim ...

func (*RedisClusterStub) MGet

func (rc *RedisClusterStub) MGet(keys ...string) ([]string, error)

MGet ...

func (*RedisClusterStub) MGets

func (rc *RedisClusterStub) MGets(keys []string) ([]interface{}, error)

MGets ...

func (*RedisClusterStub) RPop

func (rc *RedisClusterStub) RPop(key string) (string, error)

RPop 移除并返回列表 key 的尾元素。

func (*RedisClusterStub) RPush

func (rc *RedisClusterStub) RPush(key string, values ...interface{}) (int64, error)

RPush 将一个或多个值 value 插入到列表 key 的表尾(最右边)。

func (*RedisClusterStub) SAdd

func (rc *RedisClusterStub) SAdd(key string, member ...interface{}) (int64, error)

SAdd 向set中添加成员

func (*RedisClusterStub) SIsMember

func (rc *RedisClusterStub) SIsMember(key string, member interface{}) (bool, error)

SIsMember ...

func (*RedisClusterStub) SMembers

func (rc *RedisClusterStub) SMembers(key string) ([]string, error)

SMembers 返回set的全部成员

func (*RedisClusterStub) Set

func (rc *RedisClusterStub) Set(key string, value interface{}, expire time.Duration) bool

Set 设置redis的string

func (*RedisClusterStub) SetNx

func (rc *RedisClusterStub) SetNx(key string, value interface{}, expiration time.Duration) bool

SetNx 设置redis的string 如果键已存在

func (*RedisClusterStub) SetNxWithErr

func (rc *RedisClusterStub) SetNxWithErr(key string, value interface{}, expiration time.Duration) (bool, error)

SetNxWithErr 设置redis的string 如果键已存在

func (*RedisClusterStub) SetWithErr

func (rc *RedisClusterStub) SetWithErr(key string, value interface{}, expire time.Duration) error

SetWithErr ...

func (*RedisClusterStub) TTL

func (rc *RedisClusterStub) TTL(key string) (int64, error)

Ttl 查询过期时间

func (*RedisClusterStub) Type

func (rc *RedisClusterStub) Type(key string) (string, error)

Type ...

func (*RedisClusterStub) ZAdd

func (rc *RedisClusterStub) ZAdd(key string, members ...redis.Z) (int64, error)

ZAdd 将一个或多个 member 元素及其 score 值加入到有序集 key 当中

func (*RedisClusterStub) ZCard

func (rc *RedisClusterStub) ZCard(key string) (int64, error)

ZCard 获取有序集合的基数

func (*RedisClusterStub) ZCount

func (rc *RedisClusterStub) ZCount(key string, min, max string) (int64, error)

ZCount 返回有序集 key 中, score 值在 min 和 max 之间(默认包括 score 值等于 min 或 max )的成员的数量。

func (*RedisClusterStub) ZRange

func (rc *RedisClusterStub) ZRange(key string, start, stop int64) ([]string, error)

ZRange ...

func (*RedisClusterStub) ZRem

func (rc *RedisClusterStub) ZRem(key string, members ...interface{}) (int64, error)

ZRem 从zset中移除变量

func (*RedisClusterStub) ZRemRangeByRank

func (rc *RedisClusterStub) ZRemRangeByRank(key string, start, stop int64) (int64, error)

ZRemRangeByRank 移除有序集合中给定的排名区间的所有成员

func (*RedisClusterStub) ZRevRange

func (rc *RedisClusterStub) ZRevRange(key string, start, stop int64) ([]string, error)

ZRevRange 倒序获取有序集合的部分数据

func (*RedisClusterStub) ZRevRangeByScore

func (rc *RedisClusterStub) ZRevRangeByScore(key string, opt redis.ZRangeBy) ([]string, error)

ZRevRangeByScore ...

func (*RedisClusterStub) ZRevRangeByScoreWithScores

func (rc *RedisClusterStub) ZRevRangeByScoreWithScores(key string, opt redis.ZRangeBy) ([]redis.Z, error)

ZRevRangeByScoreWithScores ...

func (*RedisClusterStub) ZRevRangeWithScores

func (rc *RedisClusterStub) ZRevRangeWithScores(key string, start, stop int64) ([]redis.Z, error)

ZRevRangeWithScores ...

func (*RedisClusterStub) ZRevRank

func (rc *RedisClusterStub) ZRevRank(key string, member string) (int64, error)

ZRevRank ...

func (*RedisClusterStub) ZScore

func (rc *RedisClusterStub) ZScore(key string, member string) (float64, error)

ZScore 获取有序集合成员 member 的 score 值

type RedisConfig

type RedisConfig struct {
	// Addr 节点连接地址
	Addr string `json:"addr"`
	// Password 密码
	Password string `json:"password"`
	// DB,默认为0, 一般应用不推荐使用DB分片
	DB int `json:"db"`
	// PoolSize 集群内每个节点的最大连接池限制 默认每个CPU10个连接
	PoolSize int `json:"poolSize"`
	// MaxRedirects 网络相关的错误最大重试次数 默认8次
	MaxRetries int `json:"maxRetries"`
	// MinIdleConns 最小空闲连接数
	MinIdleConns int `json:"minIdleConns"`
	// DialTimeout 拨超时时间
	DialTimeout time.Duration `json:"dialTimeout"`
	// ReadTimeout 读超时 默认3s
	ReadTimeout time.Duration `json:"readTimeout"`
	// WriteTimeout 读超时 默认3s
	WriteTimeout time.Duration `json:"writeTimeout"`
	// IdleTimeout 连接最大空闲时间,默认60s, 超过该时间,连接会被主动关闭
	IdleTimeout time.Duration `json:"idleTimeout"`
	// Debug开关
	Debug bool `json:"debug"`
	// 是否开启链路追踪,开启以后。使用DoCotext的请求会被trace
	EnableTrace bool `json:"enableTrace"`
	// 慢日志门限值,超过该门限值的请求,将被记录到慢日志中
	SlowThreshold time.Duration `json:"slowThreshold"`
	// OnDialError panic|error
	OnDialError string `json:"level"`
	// contains filtered or unexported fields
}

RedisConfig 单节点redis配置

func DefaultRedisConfig

func DefaultRedisConfig() RedisConfig

DefaultRedisConfig ...

func RawRedisConfig

func RawRedisConfig(key string) RedisConfig

RawRedisConfig ...

func StdRedisConfig

func StdRedisConfig(name string) RedisConfig

StdRedisConfig ...

func TemplateRedisConfig

func TemplateRedisConfig(name string) RedisConfig

func (RedisConfig) Build

func (config RedisConfig) Build() *RedisStub

Build ...

type RedisStub

type RedisStub struct {
	Client *redis.Client
	// contains filtered or unexported fields
}

RedisStub is an unit that handles master and slave.

func (*RedisStub) Close

func (r *RedisStub) Close() (err error)

Close closes the client, releasing any open resources.

It is rare to Close a Client, as the Client is meant to be long-lived and shared between many goroutines.

func (*RedisStub) Decr

func (r *RedisStub) Decr(key string) bool

Decr redis自减

func (*RedisStub) Del

func (r *RedisStub) Del(key string) int64

Del redis删除

func (*RedisStub) DelWithErr

func (r *RedisStub) DelWithErr(key string) (int64, error)

DelWithErr ...

func (*RedisStub) Exists

func (r *RedisStub) Exists(key string) bool

Exists 键是否存在

func (*RedisStub) ExistsWithErr

func (r *RedisStub) ExistsWithErr(key string) (bool, error)

ExistsWithErr ...

func (*RedisStub) Expire

func (r *RedisStub) Expire(key string, expiration time.Duration) (bool, error)

Expire 设置过期时间

func (*RedisStub) GeoAdd

func (r *RedisStub) GeoAdd(key string, location *redis.GeoLocation) (int64, error)

GeoAdd 写入地理位置

func (*RedisStub) GeoRadius

func (r *RedisStub) GeoRadius(key string, longitude, latitude float64, query *redis.GeoRadiusQuery) ([]redis.GeoLocation, error)

GeoRadius 根据经纬度查询列表

func (*RedisStub) Get

func (r *RedisStub) Get(key string) string

Get get key from stub

func (*RedisStub) GetRaw

func (r *RedisStub) GetRaw(key string) ([]byte, error)

GetRaw get bytes by key, underlying error will thrown up

func (*RedisStub) HDel

func (r *RedisStub) HDel(key string, field ...string) bool

HDel ...

func (*RedisStub) HGet

func (r *RedisStub) HGet(key string, fields string) (string, error)

HGet 从redis获取hash单个值

func (*RedisStub) HGetAll

func (r *RedisStub) HGetAll(key string) map[string]string

HGetAll 从redis获取hash的所有键值对

func (*RedisStub) HIncrBy

func (r *RedisStub) HIncrBy(key string, field string, incr int) int64

HIncrBy 哈希field自增

func (*RedisStub) HIncrByWithErr

func (r *RedisStub) HIncrByWithErr(key string, field string, incr int) (int64, error)

HIncrByWithErr 哈希field自增并且返回错误

func (*RedisStub) HKeys

func (r *RedisStub) HKeys(key string) []string

HKeys 获取hash的所有域

func (*RedisStub) HLen

func (r *RedisStub) HLen(key string) int64

HLen 获取hash的长度

func (*RedisStub) HMGet

func (r *RedisStub) HMGet(key string, fileds []string) []string

HMGet 批量获取hash值

func (*RedisStub) HMGetMap

func (r *RedisStub) HMGetMap(key string, fields []string) map[string]string

HMGetMap 批量获取hash值,返回map

func (*RedisStub) HMSet

func (r *RedisStub) HMSet(key string, hash map[string]interface{}, expire time.Duration) bool

HMSet 设置redis的hash

func (*RedisStub) HSet

func (r *RedisStub) HSet(key string, field string, value interface{}) bool

HSet hset

func (*RedisStub) Incr

func (r *RedisStub) Incr(key string) bool

Incr redis自增

func (*RedisStub) IncrBy

func (r *RedisStub) IncrBy(key string, increment int64) (int64, error)

IncrBy 将 key 所储存的值加上增量 increment 。

func (*RedisStub) IncrWithErr

func (r *RedisStub) IncrWithErr(key string) (int64, error)

IncrWithErr ...

func (*RedisStub) LIndex

func (r *RedisStub) LIndex(key string, idx int64) (string, error)

LIndex ...

func (*RedisStub) LLen

func (r *RedisStub) LLen(key string) int64

LLen ...

func (*RedisStub) LLenWithErr

func (r *RedisStub) LLenWithErr(key string) (int64, error)

LLenWithErr ...

func (*RedisStub) LPush

func (r *RedisStub) LPush(key string, values ...interface{}) (int64, error)

LPush 将一个或多个值 value 插入到列表 key 的表头

func (*RedisStub) LRange

func (r *RedisStub) LRange(key string, start, stop int64) ([]string, error)

LRange 获取列表指定范围内的元素

func (*RedisStub) LRem

func (r *RedisStub) LRem(key string, count int64, value interface{}) int64

LRem ...

func (*RedisStub) LTrim

func (r *RedisStub) LTrim(key string, start, stop int64) (string, error)

LTrim ...

func (*RedisStub) MGet

func (r *RedisStub) MGet(keys ...string) ([]string, error)

MGet mget command, underlying error will thrown up

func (*RedisStub) MGets

func (r *RedisStub) MGets(keys []string) ([]interface{}, error)

MGets ...

func (*RedisStub) RPop

func (r *RedisStub) RPop(key string) (string, error)

RPop 移除并返回列表 key 的尾元素。

func (*RedisStub) RPush

func (r *RedisStub) RPush(key string, values ...interface{}) (int64, error)

RPush 将一个或多个值 value 插入到列表 key 的表尾(最右边)。

func (*RedisStub) SAdd

func (r *RedisStub) SAdd(key string, member ...interface{}) (int64, error)

SAdd 向set中添加成员

func (*RedisStub) SIsMember

func (r *RedisStub) SIsMember(key string, member interface{}) (bool, error)

SIsMember ...

func (*RedisStub) SMembers

func (r *RedisStub) SMembers(key string) ([]string, error)

SMembers 返回set的全部成员

func (*RedisStub) Set

func (r *RedisStub) Set(key string, value interface{}, expire time.Duration) bool

Set 设置redis的string

func (*RedisStub) SetNx

func (r *RedisStub) SetNx(key string, value interface{}, expiration time.Duration) bool

SetNx 设置redis的string 如果键已存在

func (*RedisStub) SetNxWithErr

func (r *RedisStub) SetNxWithErr(key string, value interface{}, expiration time.Duration) (bool, error)

SetNxWithErr 设置redis的string 如果键已存在

func (*RedisStub) SetWithErr

func (r *RedisStub) SetWithErr(key string, value interface{}, expire time.Duration) error

SetWithErr ...

func (*RedisStub) Type

func (r *RedisStub) Type(key string) (string, error)

Type ...

func (*RedisStub) ZAdd

func (r *RedisStub) ZAdd(key string, members ...redis.Z) (int64, error)

ZAdd 将一个或多个 member 元素及其 score 值加入到有序集 key 当中

func (*RedisStub) ZCard

func (r *RedisStub) ZCard(key string) (int64, error)

ZCard 获取有序集合的基数

func (*RedisStub) ZCount

func (r *RedisStub) ZCount(key string, min, max string) (int64, error)

ZCount 返回有序集 key 中, score 值在 min 和 max 之间(默认包括 score 值等于 min 或 max )的成员的数量。

func (*RedisStub) ZRange

func (r *RedisStub) ZRange(key string, start, stop int64) ([]string, error)

ZRange ...

func (*RedisStub) ZRem

func (r *RedisStub) ZRem(key string, members ...interface{}) (int64, error)

ZRem 从zset中移除变量

func (*RedisStub) ZRemRangeByRank

func (r *RedisStub) ZRemRangeByRank(key string, start, stop int64) (int64, error)

ZRemRangeByRank 移除有序集合中给定的排名区间的所有成员

func (*RedisStub) ZRevRange

func (r *RedisStub) ZRevRange(key string, start, stop int64) ([]string, error)

ZRevRange 倒序获取有序集合的部分数据

func (*RedisStub) ZRevRangeByScore

func (r *RedisStub) ZRevRangeByScore(key string, opt redis.ZRangeBy) ([]string, error)

ZRevRangeByScore ...

func (*RedisStub) ZRevRangeByScoreWithScores

func (r *RedisStub) ZRevRangeByScoreWithScores(key string, opt redis.ZRangeBy) ([]redis.Z, error)

ZRevRangeByScoreWithScores ...

func (*RedisStub) ZRevRangeWithScores

func (r *RedisStub) ZRevRangeWithScores(key string, start, stop int64) ([]redis.Z, error)

ZRevRangeWithScores ...

func (*RedisStub) ZRevRank

func (r *RedisStub) ZRevRank(key string, member string) (int64, error)

ZRevRank ...

func (*RedisStub) ZScore

func (r *RedisStub) ZScore(key string, member string) (float64, error)

ZScore 获取有序集合成员 member 的 score 值

Jump to

Keyboard shortcuts

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