Documentation ¶
Overview ¶
Package redis of the Tideland Go Library provides a very powerful as well as convenient client for the Redis database.
After opening the database with Open() a pooled connection can be retrieved using db.Connection(). It has be returnded to the pool with with conn.Return(), optimally done using a defer after retrieving. The connection provides a conn.Do() method to execute any command. It returns a result set with helpers to access the returned values and convert them into Go types. For typical returnings there are conn.DoXxx() methods.
All conn.Do() methods work atomically and are able to run all commands except subscriptions. Also the execution of scripts is possible that way. Additionally the execution of commands can be pipelined. The pipeline can be retrieved db.Pipeline(). It provides a ppl.Do() method for the execution of individual commands. Their results can be collected with ppl.Collect(), which returns a sice of result sets containing the responses of the commands.
Due to the nature of the subscription the client provides an own type which can be retrieved with db.Subscription(). Here channels, in the sense of the Redis Pub/Sub, can be subscribed or unsubscribed. Published values can be retrieved with sub.Pop(). If the subscription is not needed anymore it can be closed using sub.Close().
Index ¶
- Constants
- type Connection
- func (conn *Connection) Do(cmd string, args ...interface{}) (*ResultSet, error)
- func (conn *Connection) DoBool(cmd string, args ...interface{}) (bool, error)
- func (conn *Connection) DoHash(cmd string, args ...interface{}) (Hash, error)
- func (conn *Connection) DoInt(cmd string, args ...interface{}) (int, error)
- func (conn *Connection) DoKeyValues(cmd string, args ...interface{}) (KeyValues, error)
- func (conn *Connection) DoOK(cmd string, args ...interface{}) (bool, error)
- func (conn *Connection) DoScan(cmd string, args ...interface{}) (int, *ResultSet, error)
- func (conn *Connection) DoScoredValues(cmd string, args ...interface{}) (ScoredValues, error)
- func (conn *Connection) DoString(cmd string, args ...interface{}) (string, error)
- func (conn *Connection) DoStrings(cmd string, args ...interface{}) ([]string, error)
- func (conn *Connection) DoValue(cmd string, args ...interface{}) (Value, error)
- func (conn *Connection) Return() error
- type Database
- type Hash
- func (h Hash) Bool(key string) (bool, error)
- func (h Hash) Bytes(key string) []byte
- func (h Hash) Float64(key string) (float64, error)
- func (h Hash) Int(key string) (int, error)
- func (h Hash) Int64(key string) (int64, error)
- func (h Hash) Len() int
- func (h Hash) Set(key string, value interface{}) Hash
- func (h Hash) String(key string) (string, error)
- func (h Hash) StringMap(key string) map[string]string
- func (h Hash) StringSlice(key string) []string
- func (h Hash) Uint64(key string) (uint64, error)
- type Hashable
- type KeyValue
- type KeyValues
- type Option
- type Options
- type Pipeline
- type PublishedValue
- type ResultSet
- func (rs *ResultSet) BoolAt(index int) (bool, error)
- func (rs *ResultSet) Hash() (Hash, error)
- func (rs *ResultSet) IntAt(index int) (int, error)
- func (rs *ResultSet) KeyValues() (KeyValues, error)
- func (rs *ResultSet) Len() int
- func (rs *ResultSet) ResultSetAt(index int) (*ResultSet, error)
- func (rs *ResultSet) Scanned() (int, *ResultSet, error)
- func (rs *ResultSet) ScoredValues(withscores bool) (ScoredValues, error)
- func (rs *ResultSet) String() string
- func (rs *ResultSet) StringAt(index int) (string, error)
- func (rs *ResultSet) Strings() []string
- func (rs *ResultSet) ValueAt(index int) (Value, error)
- func (rs *ResultSet) Values() Values
- type ScoredValue
- type ScoredValues
- type Subscription
- type Value
- func (v Value) Bool() (bool, error)
- func (v Value) Bytes() []byte
- func (v Value) Float64() (float64, error)
- func (v Value) Int() (int, error)
- func (v Value) Int64() (int64, error)
- func (v Value) IsNil() bool
- func (v Value) IsOK() bool
- func (v Value) String() string
- func (v Value) StringMap() map[string]string
- func (v Value) StringSlice() []string
- func (v Value) Uint64() (uint64, error)
- func (v Value) Unpack() Value
- type Values
Constants ¶
const ( ErrInvalidConfiguration = iota ErrPoolLimitReached ErrConnectionEstablishing ErrConnectionBroken ErrInvalidResponse ErrServerResponse ErrTimeout ErrAuthenticate ErrSelectDatabase ErrUseSubscription ErrInvalidType ErrInvalidKey ErrIllegalItemIndex ErrIllegalItemType )
Error codes.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection manages one connection to a Redis database.
func (*Connection) Do ¶
func (conn *Connection) Do(cmd string, args ...interface{}) (*ResultSet, error)
Do executes one Redis command and returns the result as result set.
func (*Connection) DoBool ¶
func (conn *Connection) DoBool(cmd string, args ...interface{}) (bool, error)
DoBool executes one Redis command and interpretes the result as bool value.
func (*Connection) DoHash ¶
func (conn *Connection) DoHash(cmd string, args ...interface{}) (Hash, error)
DoHash executes on Redis command and interpretes the result as a hash.
func (*Connection) DoInt ¶
func (conn *Connection) DoInt(cmd string, args ...interface{}) (int, error)
DoInt executes one Redis command and interpretes the result as int value.
func (*Connection) DoKeyValues ¶
func (conn *Connection) DoKeyValues(cmd string, args ...interface{}) (KeyValues, error)
DoKeyValues executes on Redis command and interpretes the result as a list of keys and values.
func (*Connection) DoOK ¶
func (conn *Connection) DoOK(cmd string, args ...interface{}) (bool, error)
DoOK executes one Redis command and checks if it returns the OK string.
func (*Connection) DoScan ¶
func (conn *Connection) DoScan(cmd string, args ...interface{}) (int, *ResultSet, error)
DoScan executes one Redis command which should be one of the scan commands. It returns the cursor and the result set containing the key, values or scored values depending on the scan command.
func (*Connection) DoScoredValues ¶
func (conn *Connection) DoScoredValues(cmd string, args ...interface{}) (ScoredValues, error)
DoScoredValues executes on Redis command and interpretes the result as scored values.
func (*Connection) DoString ¶
func (conn *Connection) DoString(cmd string, args ...interface{}) (string, error)
DoString executes one Redis command and interpretes the result as string value.
func (*Connection) DoStrings ¶
func (conn *Connection) DoStrings(cmd string, args ...interface{}) ([]string, error)
DoStrings executes one Redis command and interpretes the result as a slice of strings.
func (*Connection) DoValue ¶
func (conn *Connection) DoValue(cmd string, args ...interface{}) (Value, error)
DoValue executes one Redis command and returns a single value.
func (*Connection) Return ¶
func (conn *Connection) Return() error
Return passes the connection back into the database pool.
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database provides access to a Redis database.
func (*Database) Connection ¶
func (db *Database) Connection() (*Connection, error)
Connection returns one of the pooled connections to the Redis server. It has to be returned with conn.Return() after usage.
func (*Database) Pipeline ¶
Pipeline returns one of the pooled connections to the Redis server running in pipeline mode. Calling ppl.Collect() collects all results and returns the connection.
func (*Database) Subscription ¶
func (db *Database) Subscription() (*Subscription, error)
Subscription returns a subscription with a connection to the Redis server. It has to be closed with sub.Close() after usage.
type Hash ¶
Hash maps multiple fields of a hash to the according result values.
func NewFilledHash ¶
NewFilledHash creates a hash with the passed keys and values.
func (Hash) StringSlice ¶
StringSlice returns the value of a key as string slice.
type KeyValues ¶
type KeyValues []KeyValue
KeyValues is a set of KeyValues.
type Option ¶
Option defines a function setting an option.
func Index ¶
Index selects the database and sets the authentication. The default database is the 0, the default password is empty.
func Monitoring ¶
Monitoring sets logging and monitoring, logging and monitoring are switched off by default.
func TcpConnection ¶
TcpConnection sets the connection to use TCP/IP. The default address is "127.0.0.1:6379". The default timeout to connect are 30 seconds.
type Options ¶
type Options struct { Address string Network string Timeout time.Duration Index int Password string PoolSize int Logging bool Monitoring bool }
Options is returned when calling Options() on Database to provide information about the database configuration.
type Pipeline ¶
type Pipeline struct {
// contains filtered or unexported fields
}
Pipeline manages a Redis connection executing pipelined commands.
type PublishedValue ¶
PublishedValue contains a published value and its channel channel pattern.
type ResultSet ¶
type ResultSet struct {
// contains filtered or unexported fields
}
ResultSet contains a number of values or nested result sets.
func (*ResultSet) BoolAt ¶
BoolAt returns the value at index as bool. This is a convenience method as the bool is needed very often.
func (*ResultSet) IntAt ¶
IntAt returns the value at index as int. This is a convenience method as the integer is needed very often.
func (*ResultSet) ResultSetAt ¶
ResultSetAt returns the nested result set at index.
func (*ResultSet) ScoredValues ¶
func (rs *ResultSet) ScoredValues(withscores bool) (ScoredValues, error)
ScoredValues returns the alternating values as scored values slice. If withscores is false the result set contains no scores and so they are set to 0.0 in the returned scored values.
func (*ResultSet) StringAt ¶
StringAt returns the value at index as string. This is a convenience method as the string is needed very often.
type ScoredValue ¶
ScoredValue helps to add a set member together with its score.
func (ScoredValue) String ¶
func (sv ScoredValue) String() string
String returs the scored value as string.
type ScoredValues ¶
type ScoredValues []ScoredValue
ScoredValues is a set of ScoreValues.
func (ScoredValues) Len ¶
func (svs ScoredValues) Len() int
Len returns the number of scored values in the set.
func (ScoredValues) String ¶
func (svs ScoredValues) String() string
String returs the scored values as string.
type Subscription ¶
type Subscription struct {
// contains filtered or unexported fields
}
Subscription manages a subscription to Redis channels and allows to subscribe and unsubscribe from channels.
func (*Subscription) Pop ¶
func (sub *Subscription) Pop() (*PublishedValue, error)
Pop waits for a published value and returns it.
func (*Subscription) Subscribe ¶
func (sub *Subscription) Subscribe(channels ...string) error
Subscribe adds one or more channels to the subscription.
func (*Subscription) Unsubscribe ¶
func (sub *Subscription) Unsubscribe(channels ...string) error
Unsubscribe removes one or more channels from the subscription.
type Value ¶
type Value []byte
Value is simply a byte slice.
func NewValue ¶
func NewValue(value interface{}) Value
NewValue creates a value out of the passed data.
func (Value) StringMap ¶
StringMap returns the value as a map of strings when separated by CRLF and colons between key and value.
func (Value) StringSlice ¶
StringSlice returns the value as slice of strings when separated by CRLF.