redisclient

package
v0.3.37 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	*redis.Pool
}

func NewClient

func NewClient(addr string, pwd string) (*Client, error)

func (*Client) Append

func (this *Client) Append(k string, v string) *RedisReply

如果 key 已经存在并且是一个字符串, APPEND 命令将指定的 value 追加到该 key 原来值(value)的末尾。

func (*Client) BLPop

func (this *Client) BLPop(args ...interface{}) *RedisReply

List 移出并获取列表的第一个元素, 如果列表没有元素会阻塞列表直到等待超时或发现可弹出元素为止。

func (*Client) BRPop

func (this *Client) BRPop(args ...interface{}) *RedisReply

移出并获取列表的最后一个元素, 如果列表没有元素会阻塞列表直到等待超时或发现可弹出元素为止。

func (*Client) BRPopLPush

func (this *Client) BRPopLPush(source, dest string, args ...interface{}) *RedisReply

从列表中弹出一个值,将弹出的元素插入到另外一个列表中并返回它; 如果列表没有元素会阻塞列表直到等待超时或发现可弹出元素为止。

func (*Client) Decr

func (this *Client) Decr(k string) *RedisReply

将 key 中储存的数字值减一。

func (*Client) DecrBy

func (this *Client) DecrBy(k string, decr int) *RedisReply

key 所储存的值减去给定的减量值(decrement) 。

func (*Client) DecrByFloat

func (this *Client) DecrByFloat(k string, decr float64) *RedisReply

key 所储存的值减去给定的浮点减量值(decrement) 。

func (*Client) Del

func (this *Client) Del(k ...interface{}) *RedisReply

func (*Client) Execute

func (this *Client) Execute(cmd string, args ...interface{}) *RedisReply

func (*Client) Exists

func (this *Client) Exists(k string) *RedisReply

String

func (*Client) Get

func (this *Client) Get(k string) *RedisReply

获取指定 key 的值。

func (*Client) GetBit

func (this *Client) GetBit(k string, offset int) *RedisReply

对 key 所储存的字符串值,获取指定偏移量上的位(bit)。

func (*Client) GetRange

func (this *Client) GetRange(k string, start, end int) *RedisReply

返回 key 中字符串值的子字符

func (*Client) GetSet

func (this *Client) GetSet(k string, v interface{}) *RedisReply

将给定 key 的值设为 value ,并返回 key 的旧值(old value)。

func (*Client) HDel

func (this *Client) HDel(k string, f ...interface{}) *RedisReply

Hash 删除一个或多个哈希表字段

func (*Client) HExists

func (this *Client) HExists(k string, f string) *RedisReply

查看哈希表 key 中,指定的字段是否存在。

func (*Client) HGet

func (this *Client) HGet(k string, f string) *RedisReply

获取存储在哈希表中指定字段的值。

func (*Client) HGetAll

func (this *Client) HGetAll(k string) *RedisReply

获取在哈希表中指定 key 的所有字段和值

func (*Client) HIncrBy

func (this *Client) HIncrBy(k string, f string, incre int) *RedisReply

为哈希表 key 中的指定字段的整数值加上增量 increment 。

func (*Client) HIncrByFloat

func (this *Client) HIncrByFloat(k string, f string, incre float64) *RedisReply

为哈希表 key 中的指定字段的浮点数值加上增量 increment 。

func (*Client) HKeys

func (this *Client) HKeys(k string) *RedisReply

获取所有哈希表中的字段

func (*Client) HLen

func (this *Client) HLen(k string) *RedisReply

获取哈希表中字段的数量

func (*Client) HMGet

func (this *Client) HMGet(args ...interface{}) *RedisReply

获取所有给定字段的值

func (*Client) HMSet

func (this *Client) HMSet(k string, args ...interface{}) *RedisReply

同时将多个 field-value (域-值)对设置到哈希表 key 中。

func (*Client) HSet

func (this *Client) HSet(k string, f string, v interface{}) *RedisReply

将哈希表 key 中的字段 field 的值设为 value 。

func (*Client) HSetNx

func (this *Client) HSetNx(k string, f string, v interface{}) *RedisReply

只有在字段 field 不存在时,设置哈希表字段的值。

func (*Client) HVals

func (this *Client) HVals(k string) *RedisReply

获取哈希表中所有值。

func (*Client) Incr

func (this *Client) Incr(k string) *RedisReply

将 key 中储存的数字值增一。

func (*Client) IncrBy

func (this *Client) IncrBy(k string, incr int) *RedisReply

将 key 所储存的值加上给定的增量值(increment) 。

func (*Client) IncrByFloat

func (this *Client) IncrByFloat(k string, incr float64) *RedisReply

将 key 所储存的值加上给定的浮点增量值(increment) 。

func (*Client) LIndex

func (this *Client) LIndex(k string, index int) *RedisReply

通过索引获取列表中的元素

func (*Client) LInsert

func (this *Client) LInsert(k string, before bool, pivot int, v interface{}) *RedisReply

在列表的元素前或者后插入元素

func (*Client) LLen

func (this *Client) LLen(k string) *RedisReply

获取列表长度

func (*Client) LPop

func (this *Client) LPop(k string) *RedisReply

移出并获取列表的第一个元素

func (*Client) LPush

func (this *Client) LPush(k string, v ...interface{}) *RedisReply

将一个或多个值插入到列表头部

func (*Client) LPushX

func (this *Client) LPushX(k string, v interface{}) *RedisReply

将一个值插入到已存在的列表头部

func (*Client) LRange

func (this *Client) LRange(k string, start, end int) *RedisReply

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

func (*Client) LRem

func (this *Client) LRem(k string, count int, v interface{}) *RedisReply

移除列表元素

func (*Client) LSet

func (this *Client) LSet(k string, index int, v interface{}) *RedisReply

通过索引设置列表元素的值

func (*Client) LTrim

func (this *Client) LTrim(k string, start, end int) *RedisReply

对一个列表进行修剪(trim),就是说,让列表只保留指定区间内的元素,不在指定区间之内的元素都将被删除。

func (*Client) MGet

func (this *Client) MGet(keys ...interface{}) *RedisReply

获取所有(一个或多个)给定 key 的值。

func (*Client) MSet

func (this *Client) MSet(args ...interface{}) *RedisReply

同时设置一个或多个 key-value 对。

func (*Client) MSetNx

func (this *Client) MSetNx(args ...interface{}) *RedisReply

同时设置一个或多个 key-value 对,当且仅当所有给定 key 都不存在。

func (*Client) PSetEx

func (this *Client) PSetEx(k string, milliseconds float64) *RedisReply

这个命令和 SETEX 命令相似,但它以毫秒为单位设置 key 的生存时间,而不是像 SETEX 命令那样,以秒为单位。

func (*Client) RPop

func (this *Client) RPop(k string) *RedisReply

移除列表的最后一个元素,返回值为移除的元素。

func (*Client) RPopLPush

func (this *Client) RPopLPush(source, dest string) *RedisReply

移除列表的最后一个元素,并将该元素添加到另一个列表并返回

func (*Client) RPush

func (this *Client) RPush(k string, v ...interface{}) *RedisReply

在列表中添加一个或多个值

func (*Client) RPushX

func (this *Client) RPushX(k string, v interface{}) *RedisReply

为已存在的列表添加值

func (*Client) SAdd

func (this *Client) SAdd(k string, m ...string) *RedisReply

Set 向集合添加一个或多个成员

func (*Client) SCard

func (this *Client) SCard(k string) *RedisReply

获取集合的成员数

func (*Client) SDiff

func (this *Client) SDiff(s ...string) *RedisReply

返回第一个集合与其他集合之间的差异。

func (*Client) SDiffStore

func (this *Client) SDiffStore(dest string, s ...string) *RedisReply

返回给定所有集合的差集并存储在 destination 中

func (*Client) SInter

func (this *Client) SInter(s ...string) *RedisReply

返回给定所有集合的交集

func (*Client) SInterStore

func (this *Client) SInterStore(dest string, s ...string) *RedisReply

返回给定所有集合的交集并存储在 destination 中

func (*Client) SIsMember

func (this *Client) SIsMember(k string, m string) *RedisReply

判断 member 元素是否是集合 key 的成员

func (*Client) SMembers

func (this *Client) SMembers(k string) *RedisReply

返回集合中的所有成员

func (*Client) SMove

func (this *Client) SMove(source string, dest string, m string) *RedisReply

将 member 元素从 source 集合移动到 destination 集合

func (*Client) SPop

func (this *Client) SPop(k string) *RedisReply

移除并返回集合中的一个随机元素

func (*Client) SRandMember

func (this *Client) SRandMember(k string, count ...int) *RedisReply

返回集合中一个或多个随机数

func (*Client) SRem

func (this *Client) SRem(k string, m ...string) *RedisReply

移除集合中一个或多个成员

func (*Client) SUnion

func (this *Client) SUnion(s ...string) *RedisReply

返回所有给定集合的并集

func (*Client) SUnionStore

func (this *Client) SUnionStore(dest string, s ...string) *RedisReply

所有给定集合的并集存储在 destination 集合中

func (*Client) Set

func (this *Client) Set(k string, v interface{}) *RedisReply

设置指定 key 的值

func (*Client) SetBit

func (this *Client) SetBit(k string, offset int, v int) *RedisReply

对 key 所储存的字符串值,设置或清除指定偏移量上的位(bit)。

func (*Client) SetEx

func (this *Client) SetEx(k string, seconds float64) *RedisReply

将值 value 关联到 key ,并将 key 的过期时间设为 seconds (以秒为单位)。

func (*Client) SetNx

func (this *Client) SetNx(k string, v interface{}) *RedisReply

只有在 key 不存在时设置 key 的值。

func (*Client) SetRange

func (this *Client) SetRange(k string, offset int, v interface{}) *RedisReply

用 value 参数覆写给定 key 所储存的字符串值,从偏移量 offset 开始。

func (*Client) StrLen

func (this *Client) StrLen(k string) *RedisReply

返回 key 所储存的字符串值的长度。

func (*Client) ZAdd

func (this *Client) ZAdd(k string, args ...interface{}) *RedisReply

向有序集合添加一个或多个成员,或者更新已存在成员的分数

func (*Client) ZCard

func (this *Client) ZCard(k string) *RedisReply

获取有序集合的成员数

func (*Client) ZCount

func (this *Client) ZCount(k string, min, max float64) *RedisReply

计算在有序集合中指定区间分数的成员数

func (*Client) ZIncrBy

func (this *Client) ZIncrBy(k string, incr float64, m string) *RedisReply

有序集合中对指定成员的分数加上增量 increment

func (*Client) ZInterStore

func (this *Client) ZInterStore(dest string, numkeys int, s ...string) *RedisReply

计算给定的一个或多个有序集的交集并将结果集存储在新的有序集合 destination 中,numKeys指定结果的数量

func (*Client) ZLexCount

func (this *Client) ZLexCount(args ...interface{}) *RedisReply

在有序集合中计算指定字典区间内成员数量

func (*Client) ZREVRank

func (this *Client) ZREVRank(k string, m string) *RedisReply

返回有序集合中指定成员的排名,有序集成员按分数值递减(从大到小)排序

func (*Client) ZRange

func (this *Client) ZRange(k string, start, end int, withScore bool) *RedisReply

通过索引区间返回有序集合指定区间内的成员

func (*Client) ZRangeByLex

func (this *Client) ZRangeByLex(args ...interface{}) *RedisReply

通过字典区间返回有序集合的成员

func (*Client) ZRangeByScore

func (this *Client) ZRangeByScore(k string, min, max float64, withScore bool, limit ...string) *RedisReply

通过分数返回有序集合指定区间内的成员

func (*Client) ZRank

func (this *Client) ZRank(k string, m string) *RedisReply

返回有序集合中指定成员的索引

func (*Client) ZRem

func (this *Client) ZRem(k string, m ...string) *RedisReply

移除有序集合中的一个或多个成员

func (*Client) ZRemRangeByLex

func (this *Client) ZRemRangeByLex(args ...interface{}) *RedisReply

移除有序集合中给定的字典区间的所有成员

func (*Client) ZRemRangeByRank

func (this *Client) ZRemRangeByRank(k string, start, end int) *RedisReply

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

func (*Client) ZRemRangeByScore

func (this *Client) ZRemRangeByScore(k string, min, max float64) *RedisReply

移除有序集合中给定的分数区间的所有成员

func (*Client) ZRevRange

func (this *Client) ZRevRange(k string, start, end int, withScore bool) *RedisReply

返回有序集中指定区间内的成员,通过索引,分数从高到低

func (*Client) ZRevRangeByScore

func (this *Client) ZRevRangeByScore(k string, min, max float64, withScore bool) *RedisReply

返回有序集中指定分数区间内的成员,分数从高到低排序

func (*Client) ZScore

func (this *Client) ZScore(k string, m string) *RedisReply

返回有序集中,成员的分数值

func (*Client) ZUnionStore

func (this *Client) ZUnionStore(dest string, numkeys int, s ...string) *RedisReply

计算给定的一个或多个有序集的并集,并存储在新的 key 中

type GobSerializer

type GobSerializer struct{}

GobSerializer uses gob package to encode the session map

func (GobSerializer) Deserialize

func (s GobSerializer) Deserialize(d []byte, ss *sessions.Session) error

Deserialize back to map[interface{}]interface{}

func (GobSerializer) Serialize

func (s GobSerializer) Serialize(ss *sessions.Session) ([]byte, error)

Serialize using gob

type JSONSerializer

type JSONSerializer struct{}

JSONSerializer encode the session map to JSON.

func (JSONSerializer) Deserialize

func (s JSONSerializer) Deserialize(d []byte, ss *sessions.Session) error

Deserialize back to map[string]interface{}

func (JSONSerializer) Serialize

func (s JSONSerializer) Serialize(ss *sessions.Session) ([]byte, error)

Serialize to JSON. Will err if there are unmarshalable key values

type Pair

type Pair struct {
	Key   string
	Value interface{}
}

func CreatePair

func CreatePair(k string, v interface{}) *Pair

type RediStore

type RediStore struct {
	Pool          *redis.Pool
	Codecs        []securecookie.Codec
	Options       *sessions.Options // default configuration
	DefaultMaxAge int               // default Redis TTL for a MaxAge == 0 session
	// contains filtered or unexported fields
}

RediStore stores sessions in a redis backend.

func NewRediStore

func NewRediStore(size int, network, address, password string, keyPairs ...[]byte) (*RediStore, error)

NewRediStore returns a new RediStore. size: maximum number of idle connections.

func NewRediStoreWithDB

func NewRediStoreWithDB(size int, network, address, password, DB string, keyPairs ...[]byte) (*RediStore, error)

NewRediStoreWithDB - like NewRedisStore but accepts `DB` parameter to select redis DB instead of using the default one ("0")

func NewRediStoreWithPool

func NewRediStoreWithPool(pool *redis.Pool, keyPairs ...[]byte) (*RediStore, error)

NewRediStoreWithPool instantiates a RediStore with a *redis.Pool passed in.

func (*RediStore) Close

func (s *RediStore) Close() error

Close closes the underlying *redis.Pool

func (*RediStore) Delete

func (s *RediStore) Delete(r *http.Request, w http.ResponseWriter, session *sessions.Session) error

Delete removes the session from redis, and sets the cookie to expire.

WARNING: This method should be considered deprecated since it is not exposed via the gorilla/sessions interface. Set session.Options.MaxAge = -1 and call Save instead. - July 18th, 2013

func (*RediStore) Get

func (s *RediStore) Get(r *http.Request, name string) (*sessions.Session, error)

Get returns a session for the given name after adding it to the registry.

See gorilla/sessions FilesystemStore.Get().

func (*RediStore) New

func (s *RediStore) New(r *http.Request, name string) (*sessions.Session, error)

New returns a session for the given name without adding it to the registry.

See gorilla/sessions FilesystemStore.New().

func (*RediStore) Save

func (s *RediStore) Save(r *http.Request, w http.ResponseWriter, session *sessions.Session) error

Save adds a single session to the response.

func (*RediStore) SetKeyPrefix

func (s *RediStore) SetKeyPrefix(p string)

SetKeyPrefix set the prefix

func (*RediStore) SetMaxAge

func (s *RediStore) SetMaxAge(v int)

SetMaxAge restricts the maximum age, in seconds, of the session record both in database and a browser. This is to change session storage configuration. If you want just to remove session use your session `s` object and change it's `Options.MaxAge` to -1, as specified in

http://godoc.org/github.com/gorilla/sessions#Options

Default is the one provided by this package value - `sessionExpire`. Set it to 0 for no restriction. Because we use `MaxAge` also in SecureCookie crypting algorithm you should use this function to change `MaxAge` value.

func (*RediStore) SetMaxLength

func (s *RediStore) SetMaxLength(l int)

SetMaxLength sets RediStore.maxLength if the `l` argument is greater or equal 0 maxLength restricts the maximum length of new sessions to l. If l is 0 there is no limit to the size of a session, use with caution. The default for a new RediStore is 4096. Redis allows for max. value sizes of up to 512MB (http://redis.io/topics/data-types) Default: 4096,

func (*RediStore) SetSerializer

func (s *RediStore) SetSerializer(ss SessionSerializer)

SetSerializer sets the serializer

type RedisReply

type RedisReply struct {
	Value interface{}
	Error error
}

func NewReply

func NewReply(v interface{}, e error) *RedisReply

func (*RedisReply) Bool

func (this *RedisReply) Bool() (bool, error)

func (*RedisReply) ByteSlices

func (this *RedisReply) ByteSlices() ([][]byte, error)

func (*RedisReply) Bytes

func (this *RedisReply) Bytes() ([]byte, error)

func (*RedisReply) Float64

func (this *RedisReply) Float64() (float64, error)

func (*RedisReply) Float64s

func (this *RedisReply) Float64s() ([]float64, error)

func (*RedisReply) Int

func (this *RedisReply) Int() (int, error)

func (*RedisReply) Int64

func (this *RedisReply) Int64() (int64, error)

func (*RedisReply) Int64Map

func (this *RedisReply) Int64Map() (map[string]int64, error)

func (*RedisReply) Int64s

func (this *RedisReply) Int64s() ([]int64, error)

func (*RedisReply) IntMap

func (this *RedisReply) IntMap() (map[string]int, error)

func (*RedisReply) Interface

func (this *RedisReply) Interface() (interface{}, error)

func (*RedisReply) Ints

func (this *RedisReply) Ints() ([]int, error)

func (*RedisReply) MultiBulk

func (this *RedisReply) MultiBulk() ([]interface{}, error)

func (*RedisReply) Positions

func (this *RedisReply) Positions() ([]*[2]float64, error)

func (*RedisReply) SlowLogs

func (this *RedisReply) SlowLogs() ([]redis.SlowLog, error)

func (*RedisReply) String

func (this *RedisReply) String() (string, error)

func (*RedisReply) StringMap

func (this *RedisReply) StringMap() (map[string]string, error)

func (*RedisReply) Strings

func (this *RedisReply) Strings() ([]string, error)

func (*RedisReply) Uint64

func (this *RedisReply) Uint64() (uint64, error)

func (*RedisReply) Uint64Map

func (this *RedisReply) Uint64Map() (map[string]uint64, error)

func (*RedisReply) Uint64s

func (this *RedisReply) Uint64s() ([]uint64, error)

func (*RedisReply) Values

func (this *RedisReply) Values() ([]interface{}, error)

type SessionSerializer

type SessionSerializer interface {
	Deserialize(d []byte, ss *sessions.Session) error
	Serialize(ss *sessions.Session) ([]byte, error)
}

SessionSerializer provides an interface hook for alternative serializers

Jump to

Keyboard shortcuts

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