redis

package
v0.0.0-...-04e6e7a Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2022 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 Config

type Config struct {
	Addrs        []string      `json:"addrs"`          // 连接地址
	Mode         Mode          `json:"mode"`           // 模式(cluster,simple)
	Password     string        `json:"password"`       // 密码
	DB           int           `json:"db"`             // DB,默认为0, 一般应用不推荐使用DB分片
	PoolSize     int           `json:"pool_size"`      // 集群内每个节点的最大连接池限制 默认每个CPU10个连接
	MaxRetries   int           `json:"maxRetries"`     //网络相关的错误最大重试次数 默认5次
	MinIdleConns int           `json:"min_idle_conns"` // 最小空闲连接数,默认100
	DialTimeout  time.Duration `json:"dial_timeout"`   // 连接超时
	ReadTimeout  time.Duration `json:"read_timeout"`   //读取超时 默认3s
	WriteTimeout time.Duration `json:"write_timeout"`  // 写入超时 默认3s
	IdleTimeout  time.Duration `json:"idle_timeout"`   // 连接最大空闲时间,默认60s, 超过该时间,连接会被主动关闭
	Debug        bool          `json:"debug"`          // 是否开启debug模式
	ReadOnly     bool          `json:"readOnly"`       // 集群模式中在从属节点上启用读模式
	// contains filtered or unexported fields
}

func DefaultConfig

func DefaultConfig() *Config

func RawConfig

func RawConfig(key string) *Config

RawConfig 根据key扫描配置

func ScanConfig

func ScanConfig(name string) *Config

ScanConfig 根据名称扫描配置

func (*Config) Build

func (c *Config) Build() *Redis

Build 构建redis

type Mode

type Mode string
const (
	ClusterMode Mode = "cluster"
	SimpleMode  Mode = "simple"
)

type Redis

type Redis struct {
	Config *Config
	// contains filtered or unexported fields
}

func (*Redis) Close

func (r *Redis) Close() error

Close 关闭redis连接

func (*Redis) ClusterClient

func (r *Redis) ClusterClient() *redis.ClusterClient

ClusterClient 获取redis集群客户端

func (*Redis) Decr

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

Decr redis自减

func (*Redis) Del

func (r *Redis) Del(key ...string) int64

Del redis删除

func (*Redis) DelWithErr

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

DelWithErr ...

func (*Redis) Exists

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

Exists 键是否存在

func (*Redis) ExistsWithErr

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

ExistsWithErr ...

func (*Redis) Expire

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

Expire 设置过期时间

func (*Redis) GeoAdd

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

GeoAdd 写入地理位置

func (*Redis) GeoRadius

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

GeoRadius 根据经纬度查询列表

func (*Redis) Get

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

Get 从redis获取string

func (*Redis) GetBytes

func (r *Redis) GetBytes(key string) []byte

GetBytes 从redis获取[]byte

func (*Redis) HDel

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

HDel ...

func (*Redis) HGet

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

HGet 从redis获取hash单个值

func (*Redis) HGetAll

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

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

func (*Redis) HIncrBy

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

HIncrBy 哈希field自增

func (*Redis) HIncrByWithErr

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

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

func (*Redis) HKeys

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

HKeys 获取hash的所有域

func (*Redis) HLen

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

HLen 获取hash的长度

func (*Redis) HMGet

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

HMGet 批量获取hash值

func (*Redis) HMGetMap

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

HMGetMap 批量获取hash值,返回map

func (*Redis) HMSet

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

HMSet 设置redis的hash

func (*Redis) HSet

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

HSet hset

func (*Redis) Incr

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

Incr redis自增

func (*Redis) IncrBy

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

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

func (*Redis) IncrWithErr

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

IncrWithErr ...

func (*Redis) Keys

func (r *Redis) Keys(pattern string) []string

Keys 查询指定前缀的key

func (*Redis) LIndex

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

LIndex ...

func (*Redis) LLen

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

LLen ...

func (*Redis) LLenWithErr

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

LLenWithErr ...

func (*Redis) LPush

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

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

func (*Redis) LRange

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

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

func (*Redis) LRem

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

LRem ...

func (*Redis) LTrim

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

LTrim ...

func (*Redis) MGet

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

func (*Redis) MGets

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

func (*Redis) RPop

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

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

func (*Redis) RPush

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

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

func (*Redis) SAdd

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

SAdd 向set中添加成员

func (*Redis) SIsMember

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

SIsMember ...

func (*Redis) SMembers

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

SMembers 返回set的全部成员

func (*Redis) Scan

func (r *Redis) Scan(cursor uint64, match string, count int64) ([]string, error)

Scan ...

func (*Redis) Set

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

Set 设置redis的string

func (*Redis) SetNx

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

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

func (*Redis) SetNxWithErr

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

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

func (*Redis) SetWithErr

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

SetWithErr ...

func (*Redis) SimpClient

func (r *Redis) SimpClient() *redis.Client

SimpClient 获取redis单节点客户端

func (*Redis) TTL

func (r *Redis) TTL(key string) (int64, error)

TTL 查询过期时间

func (*Redis) Type

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

Type ...

func (*Redis) ZAdd

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

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

func (*Redis) ZCard

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

ZCard 获取有序集合的基数

func (*Redis) ZCount

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

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

func (*Redis) ZRange

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

ZRange ...

func (*Redis) ZRem

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

ZRem 从zset中移除变量

func (*Redis) ZRemRangeByRank

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

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

func (*Redis) ZRevRange

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

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

func (*Redis) ZRevRangeByScore

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

ZRevRangeByScore ...

func (*Redis) ZRevRangeByScoreWithScores

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

ZRevRangeByScoreWithScores ...

func (*Redis) ZRevRangeWithScores

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

ZRevRangeWithScores ...

func (*Redis) ZRevRank

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

ZRevRank ...

func (*Redis) ZScore

func (r *Redis) 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