redis

package
v0.0.0-...-ab111f3 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2015 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package redis provides a client for the redis cache server.

Index

Constants

View Source
const DefaultTimeout = time.Second

DefaultTimeout is the default socket read/write timeout.

Variables

View Source
var (
	// MaxIdleConnsPerAddr is the maximum number of connections
	// (per server address) idling in the pool.
	//
	// Only update this value before creating or using the client.
	MaxIdleConnsPerAddr = 10

	// ErrNoServers is returned when no servers are configured or available.
	ErrNoServers = errors.New("redis: no servers configured or available")

	// ErrServerError means that a server error occurred.
	ErrServerError = errors.New("redis: server error")

	// ErrTimedOut is returned when a Read or Write operation times out
	ErrTimedOut = errors.New("redis: timed out")
)

Functions

This section is empty.

Types

type Client

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

Client is a redis client. It is safe for use by multiple concurrent goroutines.

func New

func New(server ...string) *Client

New returns a redis client using the provided server(s) with equal weight. If a server is listed multiple times, it gets a proportional amount of weight.

New supports ip:port or /unix/path, and optional *db* and *passwd* arguments. Example:

rc := redis.New("ip:port db=N passwd=foobared")
rc := redis.New("/tmp/redis.sock db=N passwd=foobared")

New panics if the configured servers point to names that cannot be resolved to an address, or unix socket path.

func NewClient

func NewClient(server ...string) (*Client, error)

NewClient is like New, but returns an error in case of failure.

func NewFromSelector

func NewFromSelector(ss ServerSelector) *Client

NewFromSelector returns a new Client using the provided ServerSelector.

func (*Client) Append

func (c *Client) Append(key, value string) (int, error)

Append implements http://redis.io/commands/append.

func (*Client) BLPop

func (c *Client) BLPop(timeout int, keys ...string) (k, v string, err error)

BLPop implements http://redis.io/commands/blpop. Cannot be sharded.

If timeout is 0, DefaultTimeout is used.

func (*Client) BRPop

func (c *Client) BRPop(timeout int, keys ...string) (k, v string, err error)

BRPop implements http://redis.io/commands/brpop. Cannot be sharded.

If timeout is 0, DefaultTimeout is used.

func (*Client) BRPopLPush

func (c *Client) BRPopLPush(src, dst string, timeout int) (string, error)

BRPopLPush implements http://redis.io/commands/brpoplpush. Cannot be sharded.

If timeout is 0, DefaultTimeout is used.

func (*Client) BgRewriteAOF

func (c *Client) BgRewriteAOF() (string, error)

BgRewriteAOF implements http://redis.io/commands/bgrewriteaof. Cannot be sharded.

func (*Client) BgSave

func (c *Client) BgSave() (string, error)

BgSave implements http://redis.io/commands/bgsave. Cannot be sharded.

func (*Client) BitCount

func (c *Client) BitCount(key string, start, end int) (int, error)

BitCount implements http://redis.io/commands/bitcount. Start and end are ignored if start is a negative number.

func (*Client) BitOp

func (c *Client) BitOp(operation, destkey, key string, keys ...string) (int, error)

BitOp implements http://redis.io/commands/bitop. Cannot be sharded.

func (*Client) ClientKill

func (c *Client) ClientKill(addr string) error

ClientKill implements http://redis.io/commands/client-kill. Cannot be sharded.

func (*Client) ClientList

func (c *Client) ClientList() ([]string, error)

ClientList implements http://redis.io/commands/client-list. Cannot be sharded.

func (*Client) ClientSetName

func (c *Client) ClientSetName(name string) error

ClientSetName implements http://redis.io/commands/client-setname. Cannot be sharded.

This driver creates connections on demand, thus naming them is pointless.

func (*Client) Close

func (c *Client) Close()

Close closes all connections in the pool.

func (*Client) ConfigGet

func (c *Client) ConfigGet(name string) (map[string]string, error)

ConfigGet implements http://redis.io/commands/config-get. Cannot be sharded.

func (*Client) ConfigResetStat

func (c *Client) ConfigResetStat() error

ConfigResetStat implements http://redis.io/commands/config-resetstat. Cannot be sharded.

func (*Client) ConfigSet

func (c *Client) ConfigSet(name, value string) error

ConfigSet implements http://redis.io/commands/config-set. Cannot be sharded.

func (*Client) DBSize

func (c *Client) DBSize() (int, error)

DBSize implements http://redis.io/commands/dbsize. Cannot be sharded.

func (*Client) DebugSegfault

func (c *Client) DebugSegfault() error

DebugSegfault implements http://redis.io/commands/debug-segfault. Cannot be sharded.

func (*Client) Decr

func (c *Client) Decr(key string) (int, error)

Decr implements http://redis.io/commands/decr.

func (*Client) DecrBy

func (c *Client) DecrBy(key string, decrement int) (int, error)

DecrBy implements http://redis.io/commands/decrby.

func (*Client) Del

func (c *Client) Del(keys ...string) (n int, err error)

Del implements http://redis.io/commands/del. Del issues a plain DEL command to redis if the client is connected to a single server. On sharded connections, it issues one DEL command per key, in the server selected for each given key.

func (*Client) Dump

func (c *Client) Dump(key string) (string, error)

Dump implements http://redis.io/commands/dump.

func (*Client) Echo

func (c *Client) Echo(message string) (string, error)

Echo implements http://redis.io/commands/echo.

func (*Client) Eval

func (c *Client) Eval(script string, numkeys int, keys, args []string) (interface{}, error)

Eval implemenets http://redis.io/commands/eval. Cannot be sharded.

func (*Client) EvalSha

func (c *Client) EvalSha(sha1 string, numkeys int, keys, args []string) (interface{}, error)

EvalSha implements http://redis.io/commands/evalsha. Cannot be sharded.

func (*Client) Exists

func (c *Client) Exists(key string) (bool, error)

Exists implements http://redis.io/commands/exists.

func (*Client) Expire

func (c *Client) Expire(key string, seconds int) (bool, error)

Expire implements http://redis.io/commands/expire. Expire returns true if a timeout was set for the given key, or false when key does not exist or the timeout could not be set.

func (*Client) ExpireAt

func (c *Client) ExpireAt(key string, timestamp int) (bool, error)

ExpireAt implements http://redis.io/commands/expireat. ExpireAt behaves like Expire.

func (*Client) FlushAll

func (c *Client) FlushAll() error

FlushAll implements http://redis.io/commands/flushall. Cannot be sharded.

func (*Client) FlushDB

func (c *Client) FlushDB() error

FlushDB implements http://redis.io/commands/flushall. Cannot be sharded.

func (*Client) Get

func (c *Client) Get(key string) (string, error)

Get implements http://redis.io/commands/get.

func (*Client) GetBit

func (c *Client) GetBit(key string, offset int) (int, error)

GetBit implements http://redis.io/commands/getbit.

func (*Client) GetRange

func (c *Client) GetRange(key string, start, end int) (string, error)

GetRange implements http://redis.io/commands/getrange.

func (*Client) GetSet

func (c *Client) GetSet(key, value string) (string, error)

GetSet implements http://redis.io/commands/getset.

func (*Client) HDel

func (c *Client) HDel(key, field string) (err error)

HDel implements http://redis.io/commands/hdel.

func (*Client) HGet

func (c *Client) HGet(key, member string) (string, error)

HGet implements http://redis.io/commands/hget.

func (*Client) HGetAll

func (c *Client) HGetAll(key string) (map[string]string, error)

HGetAll implements http://redis.io/commands/hgetall.

func (*Client) HIncrBy

func (c *Client) HIncrBy(key string, field string, increment int) (int, error)

HIncrBy implements http://redis.io/commands/hincrby.

func (*Client) HMGet

func (c *Client) HMGet(key string, field ...string) ([]string, error)

HMGet implements http://redis.io/commands/hmget.

func (*Client) HMSet

func (c *Client) HMSet(key string, items map[string]string) (err error)

HMSet implements http://redis.io/commands/hmset.

func (*Client) HScan

func (c *Client) HScan(hash string, cursor string, options ...interface{}) (string, map[string]string, error)

HScan implements http://redis.io/commands/hscan.

func (*Client) HSet

func (c *Client) HSet(key, field, value string) (err error)

HSet implements http://redis.io/commands/hset.

func (*Client) Incr

func (c *Client) Incr(key string) (int, error)

Incr implements http://redis.io/commands/incr.

func (*Client) IncrBy

func (c *Client) IncrBy(key string, increment int) (int, error)

IncrBy implements http://redis.io/commands/incrby.

func (*Client) Keys

func (c *Client) Keys(pattern string) ([]string, error)

Keys implement http://redis.io/commands/keys. Cannot be sharded.

func (*Client) LIndex

func (c *Client) LIndex(key string, index int) (string, error)

LIndex implements http://redis.io/commands/lindex.

func (*Client) LLen

func (c *Client) LLen(key string) (int, error)

LLen implements http://redis.io/commands/llen.

func (*Client) LPop

func (c *Client) LPop(key string) (string, error)

LPop implements http://redis.io/commands/lpop.

func (*Client) LPush

func (c *Client) LPush(key string, values ...string) (int, error)

LPush implements http://redis.io/commands/lpush.

func (*Client) LRange

func (c *Client) LRange(key string, begin, end int) ([]string, error)

LRange implements http://redis.io/commands/lrange.

func (*Client) LRem

func (c *Client) LRem(key string, count int, value string) (int, error)

LRem implements http://redis.io/commands/lrem.

func (*Client) LTrim

func (c *Client) LTrim(key string, begin, end int) (err error)

LTrim implements http://redis.io/commands/ltrim.

func (*Client) MGet

func (c *Client) MGet(keys ...string) ([]string, error)

MGet implements http://redis.io/commands/mget. Cannot be sharded.

TODO: support sharded connections.

func (*Client) MSet

func (c *Client) MSet(items map[string]string) error

MSet implements http://redis.io/commands/mset. Cannot be sharded.

TODO: support sharded connections.

func (*Client) PFAdd

func (c *Client) PFAdd(key string, vs ...interface{}) (int, error)

PFAdd implements http://redis.io/commands/pfadd.

func (*Client) PFCount

func (c *Client) PFCount(keys ...string) (int, error)

PFCount implements http://redis.io/commands/pfcount.

func (*Client) PFMerge

func (c *Client) PFMerge(keys ...string) (err error)

PFMerge implements http://redis.io/commands/pfmerge.

func (*Client) Ping

func (c *Client) Ping() error

Ping implements http://redis.io/commands/ping. Cannot be sharded.

func (*Client) Publish

func (c *Client) Publish(channel, message string) error

Publish implements http://redis.io/commands/publish.

func (*Client) RPop

func (c *Client) RPop(key string) (string, error)

RPop implements http://redis.io/commands/rpop.

func (*Client) RPush

func (c *Client) RPush(key string, values ...string) (int, error)

RPush implements http://redis.io/commands/rpush.

func (*Client) SAdd

func (c *Client) SAdd(key string, vs ...interface{}) (int, error)

SAdd implements http://redis.io/commands/sadd.

func (*Client) SCard

func (c *Client) SCard(key string) (int, error)

SCard implements http://redis.io/commands/scard.

func (*Client) SIsMember

func (c *Client) SIsMember(key string, vs ...interface{}) (int, error)

SIsMember implements http://redis.io/commands/sismember.

func (*Client) SMembers

func (c *Client) SMembers(key string) ([]string, error)

SMembers implements http://redis.io/commands/smembers.

func (*Client) SMove

func (c *Client) SMove(source string, destination string, member string) (int, error)

SMove implements http://redis.io/commands/smove.

func (*Client) SRandMember

func (c *Client) SRandMember(key string, count int) ([]string, error)

SRandMember implements http://redis.io/commands/srandmember.

func (*Client) SRem

func (c *Client) SRem(key string, vs ...interface{}) (int, error)

SRem implements http://redis.io/commands/srem.

func (*Client) SScan

func (c *Client) SScan(set string, cursor string, options ...interface{}) (string, []string, error)

SScan implements http://redis.io/commands/sscan.

func (*Client) Scan

func (c *Client) Scan(cursor string, options ...interface{}) (string, []string, error)

Scan implements http://redis.io/commands/scan.

func (*Client) ScriptLoad

func (c *Client) ScriptLoad(script string) (string, error)

ScriptLoad implements http://redis.io/commands/script-load. Cannot be sharded.

func (*Client) Set

func (c *Client) Set(key, value string) (err error)

Set implements http://redis.io/commands/set.

func (*Client) SetBit

func (c *Client) SetBit(key string, offset, value int) (int, error)

SetBit implements http://redis.io/commands/setbit.

func (*Client) SetEx

func (c *Client) SetEx(key string, seconds int, value string) (err error)

SetEx implements http://redis.io/commands/setex.

func (*Client) SetNx

func (c *Client) SetNx(key, value string) (int, error)

SetNx implements http://redis.io/commands/setnx.

func (*Client) SetTimeout

func (c *Client) SetTimeout(max time.Duration)

SetTimeout sets the client timeout for read/write operations.

func (*Client) Subscribe

func (c *Client) Subscribe(channel string, m chan<- PubSubMessage, stop <-chan bool) error

Subscribe implements http://redis.io/commands/subscribe.

func (*Client) TTL

func (c *Client) TTL(key string) (int, error)

TTL implements http://redis.io/commands/ttl.

func (*Client) ZAdd

func (c *Client) ZAdd(key string, vs ...interface{}) (int, error)

ZAdd implements http://redis.io/commands/zadd.

func (*Client) ZCard

func (c *Client) ZCard(key string) (int, error)

ZCard implements http://redis.io/commands/zcard.

func (*Client) ZCount

func (c *Client) ZCount(key string, min int, max int) (int, error)

ZCount implements http://redis.io/commands/zcount.

func (*Client) ZIncrBy

func (c *Client) ZIncrBy(key string, increment int, member string) (string, error)

ZIncrBy implements http://redis.io/commands/zincrby.

func (*Client) ZRange

func (c *Client) ZRange(key string, start int, stop int, withscores bool) ([]string, error)

ZRange implements http://redis.io/commands/zrange.

func (*Client) ZRem

func (c *Client) ZRem(key string, vs ...interface{}) (int, error)

ZRem implements http://redis.io/commands/zrem.

func (*Client) ZRemRangeByScore

func (c *Client) ZRemRangeByScore(key string, start interface{}, stop interface{}) (int, error)

ZRemRangeByScore implements http://redis.io/commands/zremrangebyscore.

func (*Client) ZRevRange

func (c *Client) ZRevRange(key string, start int, stop int, withscores bool) ([]string, error)

ZRevRange implements http://redis.io/commands/zrevrange.

func (*Client) ZScan

func (c *Client) ZScan(zset string, cursor string, options ...interface{}) (string, map[string]string, error)

ZScan implements http://redis.io/commands/zscan.

func (*Client) ZScore

func (c *Client) ZScore(key string, member string) (string, error)

ZScore implements http://redis.io/commands/zscore.

type ConnectTimeoutError

type ConnectTimeoutError struct {
	Addr net.Addr
}

ConnectTimeoutError is the error type used when it takes too long to connect to the desired host. This level of detail can generally be ignored.

func (*ConnectTimeoutError) Error

func (cte *ConnectTimeoutError) Error() string

type PubSubMessage

type PubSubMessage struct {
	Error   error
	Value   string
	Channel string
}

A PubSubMessage carries redis pub/sub messages for clients that are subscribed to a topic. See Subscribe for details.

type ServerInfo

type ServerInfo struct {
	Addr   net.Addr
	DB     string
	Passwd string
}

ServerInfo stores parsed the server information.

type ServerList

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

ServerList is a simple ServerSelector. Its zero value is usable.

func (*ServerList) PickServer

func (ss *ServerList) PickServer(key string) (srv ServerInfo, err error)

PickServer implements the ServerSelector interface.

func (*ServerList) SetServers

func (ss *ServerList) SetServers(servers ...string) error

SetServers changes a ServerList's set of servers at runtime and is threadsafe.

Each server is given equal weight. A server is given more weight if it's listed multiple times.

SetServers returns an error if any of the server names fail to resolve. No attempt is made to connect to the server. If any error is returned, no changes are made to the ServerList.

func (*ServerList) Sharding

func (ss *ServerList) Sharding() bool

Sharding implements the ServerSelector interface.

type ServerSelector

type ServerSelector interface {
	// PickServer returns the server address that a given item
	// should be shared onto, or the first listed server if an
	// empty key is given.
	PickServer(key string) (ServerInfo, error)

	// Sharding indicates that the client can connect to multiple servers.
	Sharding() bool
}

ServerSelector is the interface that selects a redis server as a function of the item's key.

All ServerSelector implementations must be threadsafe.

Jump to

Keyboard shortcuts

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