redis

package module
v0.0.0-...-1183a24 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2019 License: MIT Imports: 7 Imported by: 3 modules, 4 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-redis

一个简洁的Golang Redis访问库.

仅支持单机模式, 如果需要集群, 请使用twemproxy overlord实现集群

使用方式参考 redis_test.go 文件

支持超时设置, 防止出现b站的那个坑, 就是专线断了, 然后全部堵死

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) 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) Ping

func (c *Client) Ping(ctx context.Context) error

func (*Client) PoolStats

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

PoolStats 返回连接池状态

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) 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) 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 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
	// 一个连接的超时时间
	// 防止过多的链接导致Redis崩溃
	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