import "github.com/simonz05/godis/redis"
package redis implements a client for Redis with support for all commands and features such as transactions and pubsub.
var (
// Max connection pool size
MaxClientConn = 2
)
type Client struct {
Rw ReaderWriter
}
func New(netaddr string, db int, password string) *Client
Returns a new Client given a net address, db and password. nettaddr should be formatted using "net:addr", where ":" is acting as a separator. E.g. "unix:/path/to/redis.sock", "tcp:127.0.0.1:12345". Use an empty string for redis defaults.
func (c *Client) Append(key string, value interface{}) (int64, error)
Append a value to a key
func (c *Client) Bgrewriteaof() error
Asynchronously rewrite the append-only file
func (c *Client) Bgsave() error
Asynchronously save the dataset to disk
func (c *Client) Blpop(keys []string, timeout int64) (*Reply, error)
Remove and get the first element in a list, or block until one is available If timeout expires an error is returned errors.New("timeout expired")
func (c *Client) Brpop(keys []string, timeout int64) (*Reply, error)
Remove and get the last element in a list, or block until one is available If timeout expires an error is returned errors.New("timeout expired")
func (c *Client) Brpoplpush(source string, destination string, timeout int64) (Elem, error)
Pop a value from a list, push it to another list and return it; or block until one is available If timeout expires an error is returned errors.New("timeout expired")
func (c *Client) ConfigGet(parameter string) (*Reply, error)
Get the value of a configuration parameter
func (c *Client) ConfigResetstat() error
Reset the stats returned by INFO
func (c *Client) ConfigSet(parameter string, value string) error
Set a configuration parameter to the given value
func (c *Client) Dbsize() (int64, error)
Return the number of keys in the selected database
func (c *Client) DebugObject(key string) (Elem, error)
Get debugging information about a key
func (c *Client) DebugSegfault() error
Make the server crash
func (c *Client) Decr(key string) (int64, error)
Decrement the integer value of a key by one
func (c *Client) Decrby(key string, decrement int64) (int64, error)
Decrement the integer value of a key by the given number
func (c *Client) Del(keys ...string) (int64, error)
Delete a key
func (c *Client) Echo(message interface{}) (Elem, error)
Echo the given string
func (c *Client) Exists(key string) (bool, error)
Determine if a key exists
func (c *Client) Expire(key string, seconds int64) (bool, error)
Set a key's time to live in seconds
func (c *Client) Expireat(key string, timestamp int64) (bool, error)
Set the expiration for a key as a UNIX timestamp
func (c *Client) Flushall() error
Remove all keys from all databases
func (c *Client) Flushdb() error
Remove all keys from the current database
func (c *Client) Get(key string) (Elem, error)
Get the value of a key
func (c *Client) Getbit(key string, offset int) (int64, error)
Returns the bit value at offset in the string value stored at key
func (c *Client) Getrange(key string, start int, end int) (Elem, error)
Get a substring of the string stored at a key
func (c *Client) Getset(key string, value interface{}) (Elem, error)
Set the string value of a key and return its old value
func (c *Client) Hdel(key string, field string) (bool, error)
Delete a hash field TODO: Delete one or more hash fields
func (c *Client) Hexists(key string, field string) (bool, error)
Determine if a hash field exists
func (c *Client) Hget(key string, field string) (Elem, error)
Get the value of a hash field
func (c *Client) Hgetall(key string) (*Reply, error)
Get all the fields and values in a hash
func (c *Client) Hincrby(key string, field string, increment int64) (int64, error)
Increment the integer value of a hash field by the given number
func (c *Client) Hkeys(key string) ([]string, error)
Get all the fields in a hash
func (c *Client) Hlen(key string) (int64, error)
Get the number of fields in a hash
func (c *Client) Hmget(key string, fields ...string) (*Reply, error)
Get the values of all the given hash fields
func (c *Client) Hmset(key string, mapping map[string]interface{}) error
Set multiple hash fields to multiple values
func (c *Client) Hset(key string, field string, value interface{}) (bool, error)
Set the string value of a hash field
func (c *Client) Hsetnx(key string, field string, value interface{}) (bool, error)
Set the value of a hash field, only if the field does not exist
func (c *Client) Hvals(key string) (*Reply, error)
Get all the values in a hash
func (c *Client) Incr(key string) (int64, error)
Increment the integer value of a key by one
func (c *Client) Incrby(key string, increment int64) (int64, error)
Increment the integer value of a key by the given number
func (c *Client) Info() (Elem, error)
Get information and statistics about the server
func (c *Client) Keys(pattern string) ([]string, error)
Find all keys matching the given pattern
func (c *Client) Lastsave() (int64, error)
Get the UNIX time stamp of the last successful save to disk
func (c *Client) Lindex(key string, index int) (Elem, error)
Get an element from a list by its index
func (c *Client) Linsert(key, where string, pivot, value interface{}) (int64, error)
Insert an element before or after another element in a list
func (c *Client) Llen(key string) (int64, error)
Get the length of a list
func (c *Client) Lpop(key string) (Elem, error)
Remove and get the first element in a list
func (c *Client) Lpush(key string, value interface{}) (int64, error)
Prepend a value to a list TODO: Prepend one or multiple values to a list
func (c *Client) Lpushx(key string, value interface{}) (int64, error)
Prepend a value to a list, only if the list exists
func (c *Client) Lrange(key string, start, stop int) (*Reply, error)
Get a range of elements from a list
func (c *Client) Lrem(key string, count int, value interface{}) (int64, error)
Remove elements from a list
func (c *Client) Lset(key string, index int, value interface{}) error
Set the value of an element in a list by its index
func (c *Client) Ltrim(key string, start int, stop int) error
Trim a list to the specified range
func (c *Client) Mget(keys ...string) (*Reply, error)
Get the values of all the given keys
func (c *Client) Monitor() (*Reply, error)
Listen for all requests received by the server in real time
func (c *Client) Move(key string, db int) (bool, error)
Move a key to another database
func (c *Client) Mset(mapping map[string]string) error
Set multiple keys to multiple values
func (c *Client) Msetnx(mapping map[string]string) (bool, error)
Set multiple keys to multiple values, only if none of the keys exist
func (c *Client) Persist(key string) (bool, error)
Remove the expiration from a key
func (c *Client) Ping() (Elem, error)
Ping the server
func (c *Client) Psubscribe(patterns ...string) (*Sub, error)
Listen for messages published to channels matching the given patterns
func (c *Client) Publish(channel string, message interface{}) (int64, error)
Post a message to a channel
func (c *Client) Quit() error
Close the connection
func (c *Client) Randomkey() (string, error)
Return a random key from the keyspace
func (c *Client) Rename(key string, newkey string) error
Rename a key
func (c *Client) Renamenx(key string, newkey string) (bool, error)
Rename a key, only if the new key does not exist
func (c *Client) Rpop(key string) (Elem, error)
Remove and get the last element in a list
func (c *Client) Rpoplpush(source string, destination string) (Elem, error)
Remove the last element in a list, append it to another list and return it
func (c *Client) Rpush(key string, value interface{}) (int64, error)
Append a value to a list TODO: Append one or multiple values to a list
func (c *Client) Rpushx(key string, value interface{}) (int64, error)
Append a value to a list, only if the list exists
func (c *Client) Sadd(key string, member interface{}) (bool, error)
Add a member to a set TODO: Add one or more members to a set
func (c *Client) Save() error
Synchronously save the dataset to disk
func (c *Client) Scard(key string) (int64, error)
Get the number of members in a set
func (c *Client) Sdiff(keys ...string) (*Reply, error)
Subtract multiple sets
func (c *Client) Sdiffstore(destination string, keys ...string) (int64, error)
Subtract multiple sets and store the resulting set in a key
func (c *Client) Select(index int) error
Change the selected database for the current connection
func (c *Client) Set(key string, value interface{}) error
Set the string value of a key
func (c *Client) Setbit(key string, offset int, value int) (int64, error)
Sets or clears the bit at offset in the string value stored at key
func (c *Client) Setex(key string, seconds int64, value interface{}) error
Set the value and expiration of a key
func (c *Client) Setnx(key string, value interface{}) (bool, error)
Set the value of a key, only if the key does not exist
func (c *Client) Setrange(key string, offset int, value interface{}) (int64, error)
Overwrite part of a string at key starting at the specified offset
func (c *Client) Shutdown() error
Synchronously save the dataset to disk and then shut down the server
func (c *Client) Sinter(keys ...string) (*Reply, error)
Intersect multiple sets
func (c *Client) Sinterstore(destination string, keys ...string) (int64, error)
Intersect multiple sets and store the resulting set in a key
func (c *Client) Sismember(key string, member interface{}) (bool, error)
Determine if a given value is a member of a set
func (c *Client) Slaveof(host string, port string) error
Change the replication settings of a slave on the fly
func (c *Client) Smembers(key string) (*Reply, error)
Get all the members in a set
func (c *Client) Smove(source string, destination string, member interface{}) (bool, error)
Move a member from one set to another
func (c *Client) Sort(key string, args ...string) (*Reply, error)
Sort the elements in a list, set or sorted set
func (c *Client) Spop(key string) (Elem, error)
Remove and return a random member from a set
func (c *Client) Srandmember(key string) (Elem, error)
Get a random member from a set
func (c *Client) Srem(key string, member interface{}) (bool, error)
Remove a member from a set TODO: Remove one or more members from a set
func (c *Client) Strlen(key string) (int64, error)
Get the length of the value stored in a key
func (c *Client) Subscribe(channels ...string) (*Sub, error)
Listen for messages published to the given channels
func (c *Client) Sunion(keys ...string) (*Reply, error)
Add multiple sets
func (c *Client) Sunionstore(destination string, keys ...string) (int64, error)
Add multiple sets and store the resulting set in a key
func (c *Client) Ttl(key string) (int64, error)
Get the time to live for a key
func (c *Client) Type(key string) (string, error)
Determine the type stored at key
func (c *Client) Zadd(key string, score float64, member interface{}) (bool, error)
Add a member to a sorted set, or update its score if it already exists
func (c *Client) Zcard(key string) (int64, error)
Get the number of members in a sorted set
func (c *Client) Zcount(key string, min float64, max float64) (int64, error)
Count the members in a sorted set with scores within the given values
func (c *Client) Zincrby(key string, increment float64, member interface{}) (float64, error)
Increment the score of a member in a sorted set
func (c *Client) Zinterstore(destination string, keys []string, args ...string) (int64, error)
Intersect multiple sorted sets and store the resulting sorted set in a new key `numkeys` is determined by the len of `keys` param
func (c *Client) Zrange(key string, start int, stop int) (*Reply, error)
Return a range of members in a sorted set, by index TODO: add WITHSCORES keyword
func (c *Client) Zrangebyscore(key string, min string, max string, args ...string) (*Reply, error)
Return a range of members in a sorted set, by score
func (c *Client) Zrank(key string, member interface{}) (int64, error)
Determine the index of a member in a sorted set TODO: should cast an error when member does not exist
func (c *Client) Zrem(key string, member interface{}) (bool, error)
Remove a member from a sorted set TODO: Remove one or more members from a sorted set
func (c *Client) Zremrangebyrank(key string, start int, stop int) (int64, error)
Remove all members in a sorted set within the given indexes
func (c *Client) Zremrangebyscore(key string, min float64, max float64) (int64, error)
Remove all members in a sorted set within the given scores
func (c *Client) Zrevrange(key string, start int, stop int, args ...string) (*Reply, error)
Return a range of members in a sorted set, by index, with scores ordered from high to low
func (c *Client) Zrevrangebyscore(key string, max float64, min float64, args ...string) (*Reply, error)
Return a range of members in a sorted set, by score, with scores ordered from high to low
func (c *Client) Zrevrank(key string, member interface{}) (int64, error)
Determine the index of a member in a sorted set, with scores ordered from high to low
func (c *Client) Zscore(key string, member interface{}) (float64, error)
Get the score associated with the given member in a sorted set
func (c *Client) Zunionstore(destination string, keys []string, args ...string) (int64, error)
Add multiple sorted sets and store the resulting sorted set in a new key `numkeys` is determined by the len of `keys` param
type Elem []byte
func (e Elem) Bytes() []byte
func (e Elem) Float64() float64
func (e Elem) Int64() int64
func (e Elem) String() string
type Message struct {
Channel string
Elem Elem
}
type Pipe struct {
*Sync
// contains filtered or unexported fields
}
type PipeClient struct {
*Client
}
func NewPipeClient(netaddr string, db int, password string) *PipeClient
PipeClient include support for MULTI/EXEC operations. It implements Exec() which executes all buffered commands. Set transaction to true to wrap buffered commands inside MULTI .. EXEC block. PipeClient is not thread-safe.
func NewPipeClientFromClient(c *Client) *PipeClient
Uses the connection settings from a existing client to create a new PipeClient
func (pc *PipeClient) Exec() []*Reply
Execute all commands issued after EXEC or buffered in the current pipe. Returns a slice of Replies.
func (pc *PipeClient) Multi() error
Mark the start of a transaction block
func (pc *PipeClient) Unwatch() error
Forget about all watched keys
func (pc *PipeClient) Watch(keys ...string) error
Watch the given keys to determine execution of the MULTI/EXEC block
type ReaderWriter interface {
// contains filtered or unexported methods
}
type Reply struct {
Err error
Elem Elem
Elems []*Reply
// contains filtered or unexported fields
}
func Send(rw ReaderWriter, args ...[]byte) *Reply
writes a command a and returns single the Reply object
func SendIface(rw ReaderWriter, name string, args ...interface{}) *Reply
uses reflection to create a bytestring of the name and args parameters, then calls Send()
func SendStr(rw ReaderWriter, name string, args ...string) *Reply
creates a bytestring of the name and args parameters, then calls Send()
func (r *Reply) BytesArray() [][]byte
func (r *Reply) IntArray() []int64
func (r *Reply) Message() *Message
func (r *Reply) StringArray() []string
func (r *Reply) StringMap() map[string]string
type Sub struct {
Messages chan *Message
// contains filtered or unexported fields
}
func NewSub(addr string, db int, password string) *Sub
func (s *Sub) Close()
Free the connection and close the chan
func (s *Sub) Psubscribe(patterns ...string) error
Listen for messages published to channels matching the given patterns
func (s *Sub) Punsubscribe(patterns ...string) error
Stop listening for messages posted to channels matching the given patterns
func (s *Sub) Subscribe(channels ...string) error
Listen for messages published to the given channels
func (s *Sub) Unsubscribe(channels ...string) error
Stop listening for messages posted to the given channels
type Sync struct {
Addr string
Db int
Password string
// contains filtered or unexported fields
}