redis

package
v0.0.0-...-730ab85 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Client        *r.Client
	ClusterClient *r.ClusterClient
)

Functions

func Close

func 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 Decr

func Decr(ctx context.Context, key string) bool

Decr redis自减

func Del

func Del(ctx context.Context, key string) int64

Del redis删除

func DelWithErr

func DelWithErr(ctx context.Context, key string) (int64, error)

DelWithErr ...

func Exists

func Exists(ctx context.Context, key string) bool

Exists 键是否存在

func ExistsWithErr

func ExistsWithErr(ctx context.Context, key string) (bool, error)

ExistsWithErr ...

func Expire

func Expire(ctx context.Context, key string, expiration time.Duration) (res bool, err error)

Expire 设置过期时间

func GeoAdd

func GeoAdd(ctx context.Context, key string, location *redis.GeoLocation) (res int64, err error)

GeoAdd 写入地理位置

func GeoRadius

func GeoRadius(ctx context.Context, key string, longitude, latitude float64, query *redis.GeoRadiusQuery) (res []redis.GeoLocation, err error)

GeoRadius 根据经纬度查询列表

func Get

func Get(ctx context.Context, key string) string

func GetRaw

func GetRaw(ctx context.Context, key string) (bts []byte, err error)

func HDel

func HDel(ctx context.Context, key string, field ...string) bool

HDel ...

func HGet

func HGet(ctx context.Context, key string, fields string) (string, error)

HGet 从redis获取hash单个值

func HGetAll

func HGetAll(ctx context.Context, key string) map[string]string

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

func HIncrBy

func HIncrBy(ctx context.Context, key string, field string, incr int)

HIncrBy 哈希field自增

func HKeys

func HKeys(ctx context.Context, key string) []string

HKeys 获取hash的所有域

func HLen

func HLen(ctx context.Context, key string) int64

HLen 获取hash的长度

func HMGet

func HMGet(ctx context.Context, key string, fileds []string) []string

HMGet 批量获取hash值

func HMGetMap

func HMGetMap(ctx context.Context, key string, fields []string) map[string]string

HMGetMap 批量获取hash值,返回map

func HMSet

func HMSet(ctx context.Context, key string, hash map[string]interface{}, expire time.Duration) bool

HMSet 设置redis的hash

func HSet

func HSet(ctx context.Context, key string, field string, value interface{}) bool

HSet hset

func Incr

func Incr(ctx context.Context, key string) bool

Incr redis自增

func IncrBy

func IncrBy(ctx context.Context, key string, increment int64) (int64, error)

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

func IncrWithErr

func IncrWithErr(ctx context.Context, key string) (int64, error)

IncrWithErr ...

func Init

func Init(ctx context.Context, option *Options) (err error)

func LIndex

func LIndex(ctx context.Context, key string, idx int64) (string, error)

LIndex ...

func LLen

func LLen(ctx context.Context, key string) int64

LLen ...

func LLenWithErr

func LLenWithErr(ctx context.Context, key string) (int64, error)

LLenWithErr ...

func LPush

func LPush(ctx context.Context, key string, values ...interface{}) (int64, error)

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

func LRange

func LRange(ctx context.Context, key string, start, stop int64) (res []string, err error)

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

func LRem

func LRem(ctx context.Context, key string, count int64, value interface{}) int64

LRem ...

func LTrim

func LTrim(ctx context.Context, key string, start, stop int64) (string, error)

LTrim ...

func MGet

func MGet(ctx context.Context, keys ...string) ([]string, error)

func MGets

func MGets(ctx context.Context, keys []string) (ret []interface{}, err error)

func RPop

func RPop(ctx context.Context, key string) (string, error)

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

func RPush

func RPush(ctx context.Context, key string, values ...interface{}) (int64, error)

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

func SAdd

func SAdd(ctx context.Context, key string, member ...interface{}) (int64, error)

SAdd 向set中添加成员

func SIsMember

func SIsMember(ctx context.Context, key string, member interface{}) (bool, error)

SIsMember ...

func SMembers

func SMembers(ctx context.Context, key string) ([]string, error)

SMembers 返回set的全部成员

func Set

func Set(ctx context.Context, key string, value interface{}, expire time.Duration) bool

func SetNx

func SetNx(ctx context.Context, key string, value interface{}, expiration time.Duration) bool

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

func SetNxWithErr

func SetNxWithErr(ctx context.Context, key string, value interface{}, expiration time.Duration) (bool, error)

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

func SetWithErr

func SetWithErr(ctx context.Context, key string, value interface{}, expire time.Duration) error

SetWithErr ...

func Type

func Type(ctx context.Context, key string) (string, error)

Type ...

func ZAdd

func ZAdd(ctx context.Context, key string, members ...*redis.Z) (int64, error)

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

func ZCount

func ZCount(ctx context.Context, key string, min, max string) (int64, error)

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

func ZRange

func ZRange(ctx context.Context, key string, start, stop int64) ([]string, error)

ZRange ...

func ZRem

func ZRem(ctx context.Context, key string, members ...interface{}) (res int64, err error)

ZRem 从zset中移除变量

func ZRemRangeByRank

func ZRemRangeByRank(ctx context.Context, key string, start, stop int64) (res int64, err error)

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

func ZRevRange

func ZRevRange(ctx context.Context, key string, start, stop int64) ([]string, error)

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

func ZRevRangeByScore

func ZRevRangeByScore(ctx context.Context, key string, opt *redis.ZRangeBy) (res []string, err error)

ZRevRangeByScore ...

func ZRevRangeByScoreWithScores

func ZRevRangeByScoreWithScores(ctx context.Context, key string, opt *redis.ZRangeBy) (res []redis.Z, err error)

ZRevRangeByScoreWithScores ...

func ZRevRangeWithScores

func ZRevRangeWithScores(ctx context.Context, key string, start, stop int64) ([]redis.Z, error)

ZRevRangeWithScores ...

func ZRevRank

func ZRevRank(ctx context.Context, key string, member string) (int64, error)

ZRevRank ...

func ZScore

func ZScore(ctx context.Context, key string, member string) (float64, error)

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

Types

type Cluster

type Cluster struct {
	ClusterAddrs string `json:"metric"`
	// contains filtered or unexported fields
}

type Option

type Option func(*Options)

func Addr

func Addr(addr string) Option

func ClusterAddrs

func ClusterAddrs(clusterAddrs string) Option

func Db

func Db(db int) Option

func Master

func Master(master string) Option

func MaxRetries

func MaxRetries(maxRetries int) Option

func MinIdleConns

func MinIdleConns(minIdleConns int) Option

func Mode

func Mode(mode string) Option

func Network

func Network(network string) Option

func Password

func Password(password string) Option

func PoolSize

func PoolSize(poolSize int) Option

func SentinelAddrs

func SentinelAddrs(sentinelAddrs string) Option

type Options

type Options struct {
	Mode       string   `json:"mode"` //single,sentinel,cluster
	Password   string   `json:"password"`
	DB         int      `json:"db"`
	Timeout    int      `json:"timeout"`
	MaxRetries int      `json:"maxRetries"`
	Single     Single   `json:"single"`
	Sentinel   Sentinel `json:"sentinel"`
	Cluster    Cluster  `json:"cluster"`
	Pool       Pool     `json:"pool"`
}

func NewOptions

func NewOptions(opts ...Option) Options

type Pool

type Pool struct {
	PoolSize     int `json:"poolSize"`
	MinIdleConns int `json:"minIdleConns"`
}

type Sentinel

type Sentinel struct {
	Master        string `json:"master"`
	SentinelAddrs string `json:"metric"`
	// contains filtered or unexported fields
}

type Single

type Single struct {
	Network string `json:network`
	Addr    string `json:addr`
}

Jump to

Keyboard shortcuts

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