redis

package module
v0.0.0-...-527cd16 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2021 License: MIT Imports: 8 Imported by: 0

README

redis

最新的go-redis已经支持调用方法传入ctx。

新项目不要使用这个库了。

轻量 redis 客户端

支持传入 ctx 对象。纯单机版 SDK,集群相关内容请使用 envoy 等中间件。

Documentation

Index

Constants

View Source
const (
	FlagNX = 1 << 0
	FlagXX = 1 << 1
	FlagCH = 1 << 2
)
View Source
const Nil = protocol.Nil

Variables

This section is empty.

Functions

func IsBadConn

func IsBadConn(err error, allowTimeout bool) bool

func IsLoadingError

func IsLoadingError(err error) bool

func IsMovedError

func IsMovedError(err error) (moved bool, ask bool, addr string)

func IsReadOnlyError

func IsReadOnlyError(err error) bool

func IsRedisError

func IsRedisError(err error) bool

func IsRetryableError

func IsRetryableError(err error, retryTimeout bool) bool

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func New

func New(opts Options) Client

func (*Client) DecrBy

func (c *Client) DecrBy(ctx context.Context, key string, by int64) (int64, error)

func (*Client) Del

func (c *Client) Del(ctx context.Context, keys ...string) error

func (*Client) Eval

func (c *Client) Eval(ctx context.Context, script string, keys []string, argvs ...interface{}) (result *EvalReturn, err error)

func (*Client) Expire

func (c *Client) Expire(ctx context.Context, key string, ttl int32) error

func (*Client) Get

func (c *Client) Get(ctx context.Context, key string) (item *Item, err error)

func (*Client) IncrBy

func (c *Client) IncrBy(ctx context.Context, key string, by int64) (i int64, err error)

func (*Client) MGet

func (c *Client) MGet(ctx context.Context, keys []string) (items map[string]*Item, err error)

func (*Client) PoolStats

func (c *Client) PoolStats() *pool.Stats

PoolStats 返回连接池状态

func (*Client) SAdd

func (c *Client) SAdd(ctx context.Context, key string, data ...[]byte) (err error)

func (*Client) SCard

func (c *Client) SCard(ctx context.Context, key string) (card int64, err error)

func (*Client) SIsMember

func (c *Client) SIsMember(ctx context.Context, key string, data []byte) (result bool, err error)

func (*Client) SMembers

func (c *Client) SMembers(ctx context.Context, key string) (items [][]byte, err error)

func (*Client) SPop

func (c *Client) SPop(ctx context.Context, key string, cnt int32) (data [][]byte, err error)

func (*Client) SRem

func (c *Client) SRem(ctx context.Context, key string, data ...[]byte) (result int64, err error)

func (*Client) Set

func (c *Client) Set(ctx context.Context, item *Item) error

func (*Client) Stats

func (c *Client) Stats() *pool.Stats

func (*Client) TTL

func (c *Client) TTL(ctx context.Context, key string) (ttl int32, err error)

func (*Client) ZAdd

func (c *Client) ZAdd(ctx context.Context, item *Item) (added int64, err error)

func (*Client) ZCard

func (c *Client) ZCard(ctx context.Context, key string) (card int64, err error)

func (*Client) ZCount

func (c *Client) ZCount(ctx context.Context, key, min, max string) (i int64, err error)

func (*Client) ZIncrBy

func (c *Client) ZIncrBy(ctx context.Context, key, member string, by float64) error

func (*Client) ZRange

func (c *Client) ZRange(ctx context.Context, key string, start, stop int64) (values []*ZSetValue, err error)

func (*Client) ZRangeByScore

func (c *Client) ZRangeByScore(ctx context.Context, key string, min, max float64, offset, count int64) (values []*ZSetValue, err error)

func (*Client) ZRank

func (c *Client) ZRank(ctx context.Context, key, member string) (rank int64, err error)

func (*Client) ZRem

func (c *Client) ZRem(ctx context.Context, keys ...string) error

func (*Client) ZRemRangeByRank

func (c *Client) ZRemRangeByRank(ctx context.Context, key string, start, stop int64) (i int64, err error)

func (*Client) ZRemRangeByScore

func (c *Client) ZRemRangeByScore(ctx context.Context, key, min, max string) (i int64, err error)

func (*Client) ZRevRange

func (c *Client) ZRevRange(ctx context.Context, key string, start, stop int64) (values []*ZSetValue, err error)

func (*Client) ZRevRangeByScore

func (c *Client) ZRevRangeByScore(ctx context.Context, key string, max, min float64, offset, count int64) (values []*ZSetValue, err error)

func (*Client) ZRevRank

func (c *Client) ZRevRank(ctx context.Context, key, member string) (rank int64, err error)

func (*Client) ZScore

func (c *Client) ZScore(ctx context.Context, key, member string) (score float64, err error)

type EvalReturn

type EvalReturn struct {
	// contains filtered or unexported fields
}

func (EvalReturn) Array

func (e EvalReturn) Array() ([]interface{}, error)

func (EvalReturn) Int64

func (e EvalReturn) Int64() (int64, error)

func (EvalReturn) Interface

func (e EvalReturn) Interface() interface{}

func (EvalReturn) String

func (e EvalReturn) String() (string, error)

type Item

type Item struct {
	// Key is the Item's key (250 bytes maximum).
	Key string

	// Value is the Item's value.
	Value []byte

	ZSetValues map[string]float64

	// Flags 一些 redis 标记位,请参考 Flag 开头的常量定义
	Flags uint32

	// TTL 缓存时间,秒,0 表示不过期
	TTL int32
}

type Options

type Options struct {
	Address      string
	PoolSize     int
	MinIdleConns int

	MaxConnAge  time.Duration
	PoolTimeout time.Duration
	IdleTimeout time.Duration

	IdleCheckFrequency time.Duration

	OnPreCmd  func(context.Context, []interface{}) context.Context
	OnPostCmd func(context.Context, error)
}

type ZSetValue

type ZSetValue struct {
	Member string
	Score  float64
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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