godis: github.com/simonz05/godis/redis Index | Files | Directories

package redis

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.

Index

Package Files

commands.go conn.go godis.go

Variables

var (
    // Max connection pool size
    MaxClientConn = 2
)

type Client Uses

type Client struct {
    Rw ReaderWriter
}

func New Uses

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 (*Client) Append Uses

func (c *Client) Append(key string, value interface{}) (int64, error)

Append a value to a key

func (*Client) Bgrewriteaof Uses

func (c *Client) Bgrewriteaof() error

Asynchronously rewrite the append-only file

func (*Client) Bgsave Uses

func (c *Client) Bgsave() error

Asynchronously save the dataset to disk

func (*Client) Blpop Uses

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 (*Client) Brpop Uses

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 (*Client) Brpoplpush Uses

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 (*Client) ConfigGet Uses

func (c *Client) ConfigGet(parameter string) (*Reply, error)

Get the value of a configuration parameter

func (*Client) ConfigResetstat Uses

func (c *Client) ConfigResetstat() error

Reset the stats returned by INFO

func (*Client) ConfigSet Uses

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

Set a configuration parameter to the given value

func (*Client) Dbsize Uses

func (c *Client) Dbsize() (int64, error)

Return the number of keys in the selected database

func (*Client) DebugObject Uses

func (c *Client) DebugObject(key string) (Elem, error)

Get debugging information about a key

func (*Client) DebugSegfault Uses

func (c *Client) DebugSegfault() error

Make the server crash

func (*Client) Decr Uses

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

Decrement the integer value of a key by one

func (*Client) Decrby Uses

func (c *Client) Decrby(key string, decrement int64) (int64, error)

Decrement the integer value of a key by the given number

func (*Client) Del Uses

func (c *Client) Del(keys ...string) (int64, error)

Delete a key

func (*Client) Echo Uses

func (c *Client) Echo(message interface{}) (Elem, error)

Echo the given string

func (*Client) Exists Uses

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

Determine if a key exists

func (*Client) Expire Uses

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

Set a key's time to live in seconds

func (*Client) Expireat Uses

func (c *Client) Expireat(key string, timestamp int64) (bool, error)

Set the expiration for a key as a UNIX timestamp

func (*Client) Flushall Uses

func (c *Client) Flushall() error

Remove all keys from all databases

func (*Client) Flushdb Uses

func (c *Client) Flushdb() error

Remove all keys from the current database

func (*Client) Get Uses

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

Get the value of a key

func (*Client) Getbit Uses

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

Returns the bit value at offset in the string value stored at key

func (*Client) Getrange Uses

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

Get a substring of the string stored at a key

func (*Client) Getset Uses

func (c *Client) Getset(key string, value interface{}) (Elem, error)

Set the string value of a key and return its old value

func (*Client) Hdel Uses

func (c *Client) Hdel(key string, field string) (bool, error)

Delete a hash field TODO: Delete one or more hash fields

func (*Client) Hexists Uses

func (c *Client) Hexists(key string, field string) (bool, error)

Determine if a hash field exists

func (*Client) Hget Uses

func (c *Client) Hget(key string, field string) (Elem, error)

Get the value of a hash field

func (*Client) Hgetall Uses

func (c *Client) Hgetall(key string) (*Reply, error)

Get all the fields and values in a hash

func (*Client) Hincrby Uses

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 (*Client) Hkeys Uses

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

Get all the fields in a hash

func (*Client) Hlen Uses

func (c *Client) Hlen(key string) (int64, error)

Get the number of fields in a hash

func (*Client) Hmget Uses

func (c *Client) Hmget(key string, fields ...string) (*Reply, error)

Get the values of all the given hash fields

func (*Client) Hmset Uses

func (c *Client) Hmset(key string, mapping map[string]interface{}) error

Set multiple hash fields to multiple values

func (*Client) Hset Uses

func (c *Client) Hset(key string, field string, value interface{}) (bool, error)

Set the string value of a hash field

func (*Client) Hsetnx Uses

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 (*Client) Hvals Uses

func (c *Client) Hvals(key string) (*Reply, error)

Get all the values in a hash

func (*Client) Incr Uses

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

Increment the integer value of a key by one

func (*Client) Incrby Uses

func (c *Client) Incrby(key string, increment int64) (int64, error)

Increment the integer value of a key by the given number

func (*Client) Info Uses

func (c *Client) Info() (Elem, error)

Get information and statistics about the server

func (*Client) Keys Uses

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

Find all keys matching the given pattern

func (*Client) Lastsave Uses

func (c *Client) Lastsave() (int64, error)

Get the UNIX time stamp of the last successful save to disk

func (*Client) Lindex Uses

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

Get an element from a list by its index

func (*Client) Linsert Uses

func (c *Client) Linsert(key, where string, pivot, value interface{}) (int64, error)

Insert an element before or after another element in a list

func (*Client) Llen Uses

func (c *Client) Llen(key string) (int64, error)

Get the length of a list

func (*Client) Lpop Uses

func (c *Client) Lpop(key string) (Elem, error)

Remove and get the first element in a list

func (*Client) Lpush Uses

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 (*Client) Lpushx Uses

func (c *Client) Lpushx(key string, value interface{}) (int64, error)

Prepend a value to a list, only if the list exists

func (*Client) Lrange Uses

func (c *Client) Lrange(key string, start, stop int) (*Reply, error)

Get a range of elements from a list

func (*Client) Lrem Uses

func (c *Client) Lrem(key string, count int, value interface{}) (int64, error)

Remove elements from a list

func (*Client) Lset Uses

func (c *Client) Lset(key string, index int, value interface{}) error

Set the value of an element in a list by its index

func (*Client) Ltrim Uses

func (c *Client) Ltrim(key string, start int, stop int) error

Trim a list to the specified range

func (*Client) Mget Uses

func (c *Client) Mget(keys ...string) (*Reply, error)

Get the values of all the given keys

func (*Client) Monitor Uses

func (c *Client) Monitor() (*Reply, error)

Listen for all requests received by the server in real time

func (*Client) Move Uses

func (c *Client) Move(key string, db int) (bool, error)

Move a key to another database

func (*Client) Mset Uses

func (c *Client) Mset(mapping map[string]string) error

Set multiple keys to multiple values

func (*Client) Msetnx Uses

func (c *Client) Msetnx(mapping map[string]string) (bool, error)

Set multiple keys to multiple values, only if none of the keys exist

func (*Client) Persist Uses

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

Remove the expiration from a key

func (*Client) Ping Uses

func (c *Client) Ping() (Elem, error)

Ping the server

func (*Client) Psubscribe Uses

func (c *Client) Psubscribe(patterns ...string) (*Sub, error)

Listen for messages published to channels matching the given patterns

func (*Client) Publish Uses

func (c *Client) Publish(channel string, message interface{}) (int64, error)

Post a message to a channel

func (*Client) Quit Uses

func (c *Client) Quit() error

Close the connection

func (*Client) Randomkey Uses

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

Return a random key from the keyspace

func (*Client) Rename Uses

func (c *Client) Rename(key string, newkey string) error

Rename a key

func (*Client) Renamenx Uses

func (c *Client) Renamenx(key string, newkey string) (bool, error)

Rename a key, only if the new key does not exist

func (*Client) Rpop Uses

func (c *Client) Rpop(key string) (Elem, error)

Remove and get the last element in a list

func (*Client) Rpoplpush Uses

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 (*Client) Rpush Uses

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 (*Client) Rpushx Uses

func (c *Client) Rpushx(key string, value interface{}) (int64, error)

Append a value to a list, only if the list exists

func (*Client) Sadd Uses

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 (*Client) Save Uses

func (c *Client) Save() error

Synchronously save the dataset to disk

func (*Client) Scard Uses

func (c *Client) Scard(key string) (int64, error)

Get the number of members in a set

func (*Client) Sdiff Uses

func (c *Client) Sdiff(keys ...string) (*Reply, error)

Subtract multiple sets

func (*Client) Sdiffstore Uses

func (c *Client) Sdiffstore(destination string, keys ...string) (int64, error)

Subtract multiple sets and store the resulting set in a key

func (*Client) Select Uses

func (c *Client) Select(index int) error

Change the selected database for the current connection

func (*Client) Set Uses

func (c *Client) Set(key string, value interface{}) error

Set the string value of a key

func (*Client) Setbit Uses

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 (*Client) Setex Uses

func (c *Client) Setex(key string, seconds int64, value interface{}) error

Set the value and expiration of a key

func (*Client) Setnx Uses

func (c *Client) Setnx(key string, value interface{}) (bool, error)

Set the value of a key, only if the key does not exist

func (*Client) Setrange Uses

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 (*Client) Shutdown Uses

func (c *Client) Shutdown() error

Synchronously save the dataset to disk and then shut down the server

func (*Client) Sinter Uses

func (c *Client) Sinter(keys ...string) (*Reply, error)

Intersect multiple sets

func (*Client) Sinterstore Uses

func (c *Client) Sinterstore(destination string, keys ...string) (int64, error)

Intersect multiple sets and store the resulting set in a key

func (*Client) Sismember Uses

func (c *Client) Sismember(key string, member interface{}) (bool, error)

Determine if a given value is a member of a set

func (*Client) Slaveof Uses

func (c *Client) Slaveof(host string, port string) error

Change the replication settings of a slave on the fly

func (*Client) Smembers Uses

func (c *Client) Smembers(key string) (*Reply, error)

Get all the members in a set

func (*Client) Smove Uses

func (c *Client) Smove(source string, destination string, member interface{}) (bool, error)

Move a member from one set to another

func (*Client) Sort Uses

func (c *Client) Sort(key string, args ...string) (*Reply, error)

Sort the elements in a list, set or sorted set

func (*Client) Spop Uses

func (c *Client) Spop(key string) (Elem, error)

Remove and return a random member from a set

func (*Client) Srandmember Uses

func (c *Client) Srandmember(key string) (Elem, error)

Get a random member from a set

func (*Client) Srem Uses

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 (*Client) Strlen Uses

func (c *Client) Strlen(key string) (int64, error)

Get the length of the value stored in a key

func (*Client) Subscribe Uses

func (c *Client) Subscribe(channels ...string) (*Sub, error)

Listen for messages published to the given channels

func (*Client) Sunion Uses

func (c *Client) Sunion(keys ...string) (*Reply, error)

Add multiple sets

func (*Client) Sunionstore Uses

func (c *Client) Sunionstore(destination string, keys ...string) (int64, error)

Add multiple sets and store the resulting set in a key

func (*Client) Ttl Uses

func (c *Client) Ttl(key string) (int64, error)

Get the time to live for a key

func (*Client) Type Uses

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

Determine the type stored at key

func (*Client) Zadd Uses

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 (*Client) Zcard Uses

func (c *Client) Zcard(key string) (int64, error)

Get the number of members in a sorted set

func (*Client) Zcount Uses

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 (*Client) Zincrby Uses

func (c *Client) Zincrby(key string, increment float64, member interface{}) (float64, error)

Increment the score of a member in a sorted set

func (*Client) Zinterstore Uses

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 (*Client) Zrange Uses

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 (*Client) Zrangebyscore Uses

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 (*Client) Zrank Uses

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 (*Client) Zrem Uses

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 (*Client) Zremrangebyrank Uses

func (c *Client) Zremrangebyrank(key string, start int, stop int) (int64, error)

Remove all members in a sorted set within the given indexes

func (*Client) Zremrangebyscore Uses

func (c *Client) Zremrangebyscore(key string, min float64, max float64) (int64, error)

Remove all members in a sorted set within the given scores

func (*Client) Zrevrange Uses

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 (*Client) Zrevrangebyscore Uses

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 (*Client) Zrevrank Uses

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 (*Client) Zscore Uses

func (c *Client) Zscore(key string, member interface{}) (float64, error)

Get the score associated with the given member in a sorted set

func (*Client) Zunionstore Uses

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 Uses

type Elem []byte

func (Elem) Bytes Uses

func (e Elem) Bytes() []byte

func (Elem) Float64 Uses

func (e Elem) Float64() float64

func (Elem) Int64 Uses

func (e Elem) Int64() int64

func (Elem) String Uses

func (e Elem) String() string

type Message Uses

type Message struct {
    Channel string
    Elem    Elem
}

type Pipe Uses

type Pipe struct {
    *Sync
    // contains filtered or unexported fields
}

type PipeClient Uses

type PipeClient struct {
    *Client
}

func NewPipeClient Uses

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 Uses

func NewPipeClientFromClient(c *Client) *PipeClient

Uses the connection settings from a existing client to create a new PipeClient

func (*PipeClient) Exec Uses

func (pc *PipeClient) Exec() []*Reply

Execute all commands issued after EXEC or buffered in the current pipe. Returns a slice of Replies.

func (*PipeClient) Multi Uses

func (pc *PipeClient) Multi() error

Mark the start of a transaction block

func (*PipeClient) Unwatch Uses

func (pc *PipeClient) Unwatch() error

Forget about all watched keys

func (*PipeClient) Watch Uses

func (pc *PipeClient) Watch(keys ...string) error

Watch the given keys to determine execution of the MULTI/EXEC block

type ReaderWriter Uses

type ReaderWriter interface {
    // contains filtered or unexported methods
}

type Reply Uses

type Reply struct {
    Err   error
    Elem  Elem
    Elems []*Reply
    // contains filtered or unexported fields
}

func Send Uses

func Send(rw ReaderWriter, args ...[]byte) *Reply

writes a command a and returns single the Reply object

func SendIface Uses

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 Uses

func SendStr(rw ReaderWriter, name string, args ...string) *Reply

creates a bytestring of the name and args parameters, then calls Send()

func (*Reply) BytesArray Uses

func (r *Reply) BytesArray() [][]byte

func (*Reply) IntArray Uses

func (r *Reply) IntArray() []int64

func (*Reply) Message Uses

func (r *Reply) Message() *Message

func (*Reply) StringArray Uses

func (r *Reply) StringArray() []string

func (*Reply) StringMap Uses

func (r *Reply) StringMap() map[string]string

type Sub Uses

type Sub struct {
    Messages chan *Message
    // contains filtered or unexported fields
}

func NewSub Uses

func NewSub(addr string, db int, password string) *Sub

func (*Sub) Close Uses

func (s *Sub) Close()

Free the connection and close the chan

func (*Sub) Psubscribe Uses

func (s *Sub) Psubscribe(patterns ...string) error

Listen for messages published to channels matching the given patterns

func (*Sub) Punsubscribe Uses

func (s *Sub) Punsubscribe(patterns ...string) error

Stop listening for messages posted to channels matching the given patterns

func (*Sub) Subscribe Uses

func (s *Sub) Subscribe(channels ...string) error

Listen for messages published to the given channels

func (*Sub) Unsubscribe Uses

func (s *Sub) Unsubscribe(channels ...string) error

Stop listening for messages posted to the given channels

type Sync Uses

type Sync struct {
    Addr     string
    Db       int
    Password string
    // contains filtered or unexported fields
}

Directories

PathSynopsis
example

Package redis imports 9 packages (graph) and is imported by 12 packages. Updated 2016-07-25. Refresh now. Tools for package owners.