Documentation ¶
Overview ¶
Package radix implements an asynchronous Redis client.
Client is a structure for accessing a Redis database. After establishing a connection with NewClient, commands can be executed with Client.Command. Client.Command returns a Reply with different methods for accessing the retrieved values. Client.MultiCommand can be used for sending multiple commands in a single request and Client.Transaction offers a simple way for executing atomic requests. Client.Subscription returns a Subscription that can be used for listening published messages.
Index ¶
- type Client
- func (c *Client) AsyncCommand(cmd Command, args ...interface{}) Future
- func (c *Client) AsyncMultiCommand(f func(*MultiCommand)) Future
- func (c *Client) AsyncTransaction(f func(*MultiCommand)) Future
- func (c *Client) Close()
- func (c *Client) Command(cmd Command, args ...interface{}) *Reply
- func (c *Client) MultiCommand(f func(*MultiCommand)) *Reply
- func (c *Client) Subscription(msgHdlr func(msg *Message)) (*Subscription, *Error)
- func (c *Client) Transaction(f func(*MultiCommand)) *Reply
- type Command
- type Configuration
- type Error
- type ErrorFlag
- type Future
- type Message
- type MessageType
- type MultiCommand
- type Reply
- func (r *Reply) At(i int) *Reply
- func (r *Reply) Bool() bool
- func (r *Reply) Bytes() []byte
- func (r *Reply) Elems() []*Reply
- func (r *Reply) Error() *Error
- func (r *Reply) ErrorString() string
- func (r *Reply) Int() int
- func (r *Reply) Int64() int64
- func (r *Reply) Len() int
- func (r *Reply) Map() (map[string]*Reply, error)
- func (r *Reply) Nil() bool
- func (r *Reply) Str() string
- func (r *Reply) String() string
- func (r *Reply) StringMap() (map[string]string, error)
- func (r *Reply) Strings() ([]string, error)
- func (r *Reply) Type() ReplyType
- type ReplyType
- type Subscription
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client manages the access to a database.
func (*Client) AsyncCommand ¶
AsyncCommand calls a Redis command asynchronously.
func (*Client) AsyncMultiCommand ¶
func (c *Client) AsyncMultiCommand(f func(*MultiCommand)) Future
AsyncMultiCommand calls an asynchronous multi-command.
func (*Client) AsyncTransaction ¶
func (c *Client) AsyncTransaction(f func(*MultiCommand)) Future
AsyncTransaction performs a simple asynchronous transaction.
func (*Client) MultiCommand ¶
func (c *Client) MultiCommand(f func(*MultiCommand)) *Reply
MultiCommand calls a multi-command.
func (*Client) Subscription ¶
func (c *Client) Subscription(msgHdlr func(msg *Message)) (*Subscription, *Error)
Subscription subscribes to given channels and return a Subscription or an error. The msgHdlr function is called whenever a new message arrives.
func (*Client) Transaction ¶
func (c *Client) Transaction(f func(*MultiCommand)) *Reply
Transaction performs a simple transaction. Simple transaction is a multi command that is wrapped in a MULTI-EXEC block. For complex transactions with WATCH, UNWATCH or DISCARD commands use MultiCommand.
type Command ¶
type Command string
const ( Append Command = "append" Asking Command = "asking" Auth Command = "auth" Bgrewriteaof Command = "bgrewriteaof" Bgsave Command = "bgsave" Blpop Command = "blpop" Brpop Command = "brpop" Brpoplpush Command = "brpoplpush" ClientCmd Command = "client" Cluster Command = "cluster" Config Command = "config" Dbsize Command = "dbsize" Debug Command = "debug" Decr Command = "decr" Decrby Command = "decrby" Del Command = "del" Discard Command = "discard" Dump Command = "dump" Echo Command = "echo" Eval Command = "eval" Exec Command = "exec" Exists Command = "exists" Expire Command = "expire" Expireat Command = "expireat" Flushall Command = "flushall" Flushdb Command = "flushdb" Get Command = "get" Getbit Command = "getbit" Getrange Command = "getrange" Getset Command = "getset" Hdel Command = "hdel" Hexists Command = "hexists" Hget Command = "hget" Hgetall Command = "hgetall" Hincrby Command = "hincrby" Hincrbyfloat Command = "hincrbyfloat" Hkeys Command = "hkeys" Hlen Command = "hlen" Hmget Command = "hmget" Hmset Command = "hmset" Hset Command = "hset" Hsetnx Command = "hsetnx" Hvals Command = "hvals" Incr Command = "incr" Incrby Command = "incrby" Incrbyfloat Command = "incrbyfloat" Info Command = "info" Keys Command = "keys" Lastsave Command = "lastsave" Lindex Command = "lindex" Linsert Command = "linsert" Llen Command = "llen" Lpop Command = "lpop" Lpush Command = "lpush" Lpushx Command = "lpushx" Lrange Command = "lrange" Lrem Command = "lrem" Lset Command = "lset" Ltrim Command = "ltrim" Mget Command = "mget" Migrate Command = "migrate" Monitor Command = "monitor" Move Command = "move" Mset Command = "mset" Msetnx Command = "msetnx" Multi Command = "multi" Object Command = "object" Persist Command = "persist" Pexpire Command = "pexpire" Pexpireat Command = "pexpireat" Ping Command = "ping" Psetex Command = "psetex" Psubscribe Command = "psubscribe" Pttl Command = "pttl" Publish Command = "publish" Punsubscribe Command = "punsubscribe" Randomkey Command = "randomkey" Rename Command = "rename" Renamenx Command = "renamenx" Restore Command = "restore" Rpop Command = "rpop" Rpoplpush Command = "rpoplpush" Rpush Command = "rpush" Rpushx Command = "rpushx" Sadd Command = "sadd" Save Command = "save" Scard Command = "scard" Script Command = "script" Sdiff Command = "sdiff" Sdiffstore Command = "sdiffstore" Select Command = "select" Set Command = "set" Setbit Command = "setbit" Setex Command = "setex" Setnx Command = "setnx" Setrange Command = "setrange" Shutdown Command = "shutdown" Sinter Command = "sinter" Sinterstore Command = "sinterstore" Sismember Command = "sismember" Slaveof Command = "slaveof" Smove Command = "smove" Sort Command = "sort" Spop Command = "spop" Srandmember Command = "srandmember" Srem Command = "srem" Strlen Command = "strlen" Subscribe Command = "subscribe" Sunion Command = "sunion" Sunionstore Command = "sunionstore" Sync Command = "sync" Time Command = "time" Ttl Command = "ttl" Type Command = "type" Unsubscribe Command = "unsubscribe" Unwatch Command = "unwatch" Watch Command = "watch" Zadd Command = "zadd" Zcard Command = "zcard" Zcount Command = "zcount" Zincrby Command = "zincrby" Zinterstore Command = "zinterstore" Zrange Command = "zrange" Zrangebyscore Command = "zrangebyscore" Zrank Command = "zrank" Zrem Command = "zrem" Zremrangebyrank Command = "zremrangebyrank" Zremrangebyscore Command = "zremrangebyscore" Zrevrange Command = "zrevrange" Zrevrangebyscore Command = "zrevrangebyscore" Zrevrank Command = "zrevrank" Zscore Command = "zscore" Zunionstore Command = "zunionstore" Smembers Command = "smembers" )
type Configuration ¶
type Configuration struct { Address string Path string Database int Auth string PoolSize int Timeout int NoLoadingRetry bool }
Configuration of a database client.
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
type Future ¶
type Future chan *Reply
Future is a channel for fetching the reply of an asynchronous command.
type Message ¶
type Message struct { Type MessageType Channel string Pattern string Subscriptions int Payload string Error error }
Message describes a pub/sub message
type MessageType ¶
type MessageType int
const ( MessageSubscribe MessageType = iota MessageUnsubscribe MessagePSubscribe MessagePUnsubscribe MessageMessage MessagePMessage MessageError )
type MultiCommand ¶
type MultiCommand struct {
// contains filtered or unexported fields
}
MultiCommand holds data for a Redis multi command.
func (*MultiCommand) Command ¶
func (mc *MultiCommand) Command(cmd Command, args ...interface{})
Command queues a command for later execution.
func (*MultiCommand) Flush ¶
func (mc *MultiCommand) Flush() *Reply
Flush sends queued commands to the Redis server for execution and returns the returned Reply. The Reply associated with the MultiCommand will be reseted.
type Reply ¶
type Reply struct {
// contains filtered or unexported fields
}
Reply holds a Redis reply.
func (*Reply) At ¶
At returns a Reply of a multi reply by its index. It panics, if the reply type is not ReplyMulti or if the index is out of range.
func (*Reply) Bool ¶
Bool returns true, if the reply value equals to 1 or "1", otherwise false. It panics, if the reply type is not ReplyInteger or ReplyString.
func (*Reply) Elems ¶
Elems returns the elements (sub-replies) of a multi reply. It panics, if the reply type is not ReplyMulti.
func (*Reply) Error ¶
Error returns the error value of the reply or nil, if the reply type is not ReplyError.
func (*Reply) ErrorString ¶
ErrorString returns the error string of the error value of the reply or an empty string, if the reply type is not ReplyError.
func (*Reply) Int64 ¶
Int64 returns the reply value as a int64. It panics, if the reply type is not ReplyInteger.
func (*Reply) Len ¶
Len returns the number of elements in a multi reply. Zero is returned when reply type is not ReplyMulti.
func (*Reply) Map ¶
Map returns a multi-bulk reply as a map[string]*Reply or an error. The reply elements must be in a "key value key value..."-style order.
func (*Reply) Str ¶
Str returns the reply value as a string or a nil, if the reply type is ReplyNil. It panics, if the reply type is not ReplyNil, ReplyStatus or ReplyString.
func (*Reply) String ¶
String returns a string representation of the reply and its sub-replies. This method is mainly used for debugging. Use method Reply.Str for fetching a string reply.
func (*Reply) StringMap ¶
StringMap returns a multi-bulk reply as a map[string]string or an error. The reply elements must be in a "key value key value..."-style order.
type ReplyType ¶
type ReplyType uint8
ReplyType describes the type of reply.
Possbile values are:
ReplyStatus -- status reply ReplyError -- error reply ReplyInteger -- integer reply ReplyNil -- nil reply ReplyString -- string reply ReplyMulti -- multi-bulk or multi-command reply
type Subscription ¶
type Subscription struct {
// contains filtered or unexported fields
}
Subscription is a structure for holding a Redis subscription for multiple channels.
func (*Subscription) Close ¶
func (s *Subscription) Close()
Close closes the Subscription and returns its connection to the connection pool.
func (*Subscription) PSubscribe ¶
func (s *Subscription) PSubscribe(patterns ...string) *Error
PSubscribe subscribes to given patterns or returns an error.
func (*Subscription) PUnsubscribe ¶
func (s *Subscription) PUnsubscribe(patterns ...string) *Error
PUnsubscribe unsubscribes from given patterns or returns an error.
func (*Subscription) Subscribe ¶
func (s *Subscription) Subscribe(channels ...string) *Error
Subscribe subscribes to given channels or returns an error.
func (*Subscription) Unsubscribe ¶
func (s *Subscription) Unsubscribe(channels ...string) *Error
Unsubscribe unsubscribes from given channels or returns an error.