goredis

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2015 License: MIT, Apache-2.0 Imports: 11 Imported by: 0

README

goredis

GoDoc

redis client in golang

Go or Golang is an open source programming language that makes it easy to build simple, reliable, and efficient software.

Redis is an open source, BSD licensed, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.

  • Pure golang, and doesn't depend on any 3rd party libraries;
  • Hight test coverage and will continue to improve;
  • Tested under Go 1.2 and Redis 2.8.3;
  • Tested under Go 1.2.1 and Redis 2.8.4;

Features

Document

Simple Example

Connect:

client, err := Dial()
client, err := Dial(&DialConfig{Address: "127.0.0.1:6379"})
client, err := DialURL("tcp://auth:password@127.0.0.1:6379/0?timeout=10s&maxidle=1")

Try a redis command is simple too, let's do GET/SET:

err := client.Set("key", "value", 0, 0, false, false)
value, err := client.Get("key")

Or you can execute a custom command with Redis.ExecuteCommand method:

reply, err := client.ExecuteCommand("SET", "key", "value")
err := reply.OKValue()

And then a Reply struct which represent the redis response data is defined:

type Reply struct {
	Type    int
	Error   string
	Status  string
	Integer int64  // Support Redis 64bit integer
	Bulk    []byte // Support Redis Null Bulk Reply
	Multi   []*Reply
}

Reply.Type is defined as:

const (
	ErrorReply = iota
	StatusReply
	IntegerReply
	BulkReply
	MultiReply
)

Reply struct has many useful methods:

func (rp *Reply) IntegerValue() (int64, error)
func (rp *Reply) BoolValue() (bool, error)
func (rp *Reply) StatusValue() (string, error)
func (rp *Reply) OKValue() error
func (rp *Reply) BytesValue() ([]byte, error)
func (rp *Reply) StringValue() (string, error)
func (rp *Reply) MultiValue() ([]*Reply, error)
func (rp *Reply) HashValue() (map[string]string, error)
func (rp *Reply) ListValue() ([]string, error)
func (rp *Reply) BytesArrayValue() ([][]byte, error)
func (rp *Reply) BoolArrayValue() ([]bool, error)

You can find more examples in test files.

Run Test

normal test:

go test

coverage test:

go test -cover

coverage test with html result:

go test -coverprofile=cover.out
go tool cover -html=cover.out

Welcome to report issues :)

Run Benchmark

go test -test.run=none -test.bench="Benchmark.*"

At my virtualbox Ubuntu 13.04 with single CPU: Intel(R) Core(TM) i5-3450 CPU @ 3.10GHz, get result:

BenchmarkPing	   50000	     40100 ns/op
BenchmarkLPush	   50000	     34939 ns/op
BenchmarkLRange	   50000	     41420 ns/op
BenchmarkGet	   50000	     37948 ns/op
BenchmarkIncr	   50000	     44460 ns/op
BenchmarkSet	   50000	     41300 ns/op

Welcome to show your benchmark result :)

License

The MIT License (MIT) Copyright (c) 2013 xuyu

Documentation

Overview

Package goredis is another redis client with full features which writter in golang

Protocol Specification: http://redis.io/topics/protocol.

Redis reply has five types: status, error, integer, bulk, multi bulk. A Status Reply is in the form of a single line string starting with "+" terminated by "\r\n". Error Replies are very similar to Status Replies. The only difference is that the first byte is "-". Integer reply is just a CRLF terminated string representing an integer, prefixed by a ":" byte. Bulk replies are used by the server in order to return a single binary safe string up to 512 MB in length. A Multi bulk reply is used to return an array of other replies. Every element of a Multi Bulk Reply can be of any kind, including a nested Multi Bulk Reply. So five reply type is defined:

const (
	ErrorReply = iota
	StatusReply
	IntegerReply
	BulkReply
	MultiReply
)

And then a Reply struct which represent the redis response data is defined:

type Reply struct {
	Type    int
	Error   string
	Status  string
	Integer int64  // Support Redis 64bit integer
	Bulk    []byte // Support Redis Null Bulk Reply
	Multi   []*Reply
}

Reply struct has many useful methods:

func (rp *Reply) IntegerValue() (int64, error)
func (rp *Reply) BoolValue() (bool, error)
func (rp *Reply) StatusValue() (string, error)
func (rp *Reply) OKValue() error
func (rp *Reply) BytesValue() ([]byte, error)
func (rp *Reply) StringValue() (string, error)
func (rp *Reply) MultiValue() ([]*Reply, error)
func (rp *Reply) HashValue() (map[string]string, error)
func (rp *Reply) ListValue() ([]string, error)
func (rp *Reply) BytesArrayValue() ([][]byte, error)
func (rp *Reply) BoolArrayValue() ([]bool, error)

Connect redis has two function: Dial and DialURL, for example:

client, err := Dial()
client, err := Dial(&DialConfig{Address: "127.0.0.1:6379"})
client, err := Dial(&DialConfig{"tcp", "127.0.0.1:6379", 0, "", 10*time.Second, 10})
client, err := DialURL("tcp://auth:password@127.0.0.1:6379/0?timeout=10s&maxidle=1")

DialConfig can also take named options for connection config:

config := &DialConfig {
  Network:  "tcp",
  Address:  "127.0.0.1:6379",
  Database: 0,
  Password: "yourpasswordhere"
  Timeout:  10*time.Second,
  MaxIdle:  10
}

Try a redis command is simple too, let's do GET/SET:

err := client.Set("key", "value", 0, 0, false, false)
value, err := client.Get("key")

Or you can execute customer command with Redis.ExecuteCommand method:

reply, err := client.ExecuteCommand("SET", "key", "value")
err := reply.OKValue()

Redis Pipelining is defined as:

type Pipelined struct {
	redis *Redis
	conn  *Connection
	times int
}
func (p *Pipelined) Close()
func (p *Pipelined) Command(args ...interface{})
func (p *Pipelined) Receive() (*Reply, error)
func (p *Pipelined) ReceiveAll() ([]*Reply, error)

Transaction, Lua Eval, Publish/Subscribe, Monitor, Scan, Sort are also supported.

Index

Constants

View Source
const (
	// DefaultNetwork is the default value of network
	DefaultNetwork = "tcp"

	// DefaultAddress is the default value of address(host:port)
	DefaultAddress = ":6379"

	// DefaultTimeout is the default value of connect timeout
	DefaultTimeout = 15 * time.Second

	// DefaultMaxIdle is the default value of connection pool size
	DefaultMaxIdle = 1
)
View Source
const (
	ErrorReply = iota
	StatusReply
	IntegerReply
	BulkReply
	MultiReply
)

Reply Type: Status, Integer, Bulk, Multi Bulk Error Reply Type return error directly

Variables

This section is empty.

Functions

This section is empty.

Types

type DialConfig

type DialConfig struct {
	Network  string
	Address  string
	Database int
	Password string
	Timeout  time.Duration
	MaxIdle  int
}

DialConfig is redis client connect to server parameters

type MonitorCommand

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

MonitorCommand is a debugging command that streams back every command processed by the Redis server.

func (*MonitorCommand) Close

func (m *MonitorCommand) Close() error

Close closes current monitor command.

func (*MonitorCommand) Receive

func (m *MonitorCommand) Receive() (string, error)

Receive read from redis server and return the reply.

type Pipelined

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

Pipelined implements redis pipeline mode. A Request/Response server can be implemented so that it is able to process new requests even if the client didn't already read the old responses. This way it is possible to send multiple commands to the server without waiting for the replies at all, and finally read the replies in a single step.

func (*Pipelined) Close

func (p *Pipelined) Close()

Close closes current pipeline mode.

func (*Pipelined) Command

func (p *Pipelined) Command(args ...interface{}) error

Command send raw redis command and do not wait for response.

func (*Pipelined) Receive

func (p *Pipelined) Receive() (*Reply, error)

Receive wait for one the response.

func (*Pipelined) ReceiveAll

func (p *Pipelined) ReceiveAll() ([]*Reply, error)

ReceiveAll wait for all the responses before.

type PubSub

type PubSub struct {
	Patterns map[string]bool
	Channels map[string]bool
	// contains filtered or unexported fields
}

PubSub doc: http://redis.io/topics/pubsub

func (*PubSub) Close

func (p *PubSub) Close() error

Close closes current pubsub command.

func (*PubSub) PSubscribe

func (p *PubSub) PSubscribe(patterns ...string) error

PSubscribe pattern [pattern ...]

func (*PubSub) PUnSubscribe

func (p *PubSub) PUnSubscribe(patterns ...string) error

PUnSubscribe [pattern [pattern ...]]

func (*PubSub) Receive

func (p *PubSub) Receive() ([]string, error)

Receive returns the reply of pubsub command. A message is a Multi-bulk reply with three elements. The first element is the kind of message: 1) subscribe: means that we successfully subscribed to the channel given as the second element in the reply. The third argument represents the number of channels we are currently subscribed to. 2) unsubscribe: means that we successfully unsubscribed from the channel given as second element in the reply. third argument represents the number of channels we are currently subscribed to. When the last argument is zero, we are no longer subscribed to any channel, and the client can issue any kind of Redis command as we are outside the Pub/Sub state. 3) message: it is a message received as result of a PUBLISH command issued by another client. The second element is the name of the originating channel, and the third argument is the actual message payload.

func (*PubSub) Subscribe

func (p *PubSub) Subscribe(channels ...string) error

Subscribe channel [channel ...]

func (*PubSub) UnSubscribe

func (p *PubSub) UnSubscribe(channels ...string) error

UnSubscribe [channel [channel ...]]

type Redis

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

Redis client struct Containers connection parameters and connection pool

func Dial

func Dial(cfg *DialConfig) (*Redis, error)

Dial new a redis client with DialConfig

func DialURL

func DialURL(rawurl string) (*Redis, error)

DialURL new a redis client with URL-like argument

func (*Redis) Append

func (r *Redis) Append(key, value string) (int64, error)

Append appends the value at the end of the string which stored at key If key does not exist it is created and set as an empty string. Return integer reply: the length of the string after the append operation.

func (*Redis) BLPop

func (r *Redis) BLPop(keys []string, timeout int) ([]string, error)

BLPop is a blocking list pop primitive. It is the blocking version of LPOP because it blocks the connection when there are no elements to pop from any of the given lists. An element is popped from the head of the first list that is non-empty, with the given keys being checked in the order that they are given. A nil multi-bulk when no element could be popped and the timeout expired. A two-element multi-bulk with the first element being the name of the key where an element was popped and the second element being the value of the popped element.

func (*Redis) BRPop

func (r *Redis) BRPop(keys []string, timeout int) ([]string, error)

BRPop pops elements from the tail of a list instead of popping from the head.

func (*Redis) BRPopLPush

func (r *Redis) BRPopLPush(source, destination string, timeout int) ([]byte, error)

BRPopLPush is the blocking variant of RPOPLPUSH. When source contains elements, this command behaves exactly like RPOPLPUSH. When source is empty, Redis will block the connection until another client pushes to it or until timeout is reached. A timeout of zero can be used to block indefinitely. Bulk reply: the element being popped from source and pushed to destination. If timeout is reached, a Null multi-bulk reply is returned.

func (*Redis) BgRewriteAof

func (r *Redis) BgRewriteAof() error

BgRewriteAof Instruct Redis to start an Append Only File rewrite process. The rewrite will create a small optimized version of the current Append Only File.

func (*Redis) BgSave

func (r *Redis) BgSave() error

BgSave save the DB in background. The OK code is immediately returned. Redis forks, the parent continues to serve the clients, the child saves the DB on disk then exits. A client my be able to check if the operation succeeded using the LASTSAVE command.

func (*Redis) BitCount

func (r *Redis) BitCount(key string, start, end int) (int64, error)

BitCount counts the number of set bits (population counting) in a string.

func (*Redis) BitOp

func (r *Redis) BitOp(operation, destkey string, keys ...string) (int64, error)

BitOp performs a bitwise operation between multiple keys (containing string values) and store the result in the destination key. The BITOP command supports four bitwise operations: AND, OR, XOR and NOT, thus the valid forms to call the command are: BITOP AND destkey srckey1 srckey2 srckey3 ... srckeyN BITOP OR destkey srckey1 srckey2 srckey3 ... srckeyN BITOP XOR destkey srckey1 srckey2 srckey3 ... srckeyN BITOP NOT destkey srckey Return value: Integer reply The size of the string stored in the destination key, that is equal to the size of the longest input string.

func (*Redis) ClientGetName

func (r *Redis) ClientGetName() ([]byte, error)

ClientGetName returns the name of the current connection as set by CLIENT SETNAME. Since every new connection starts without an associated name, if no name was assigned a null bulk reply is returned.

func (*Redis) ClientKill

func (r *Redis) ClientKill(ip string, port int) error

ClientKill closes a given client connection identified by ip:port. Due to the single-treaded nature of Redis, it is not possible to kill a client connection while it is executing a command. However, the client will notice the connection has been closed only when the next command is sent (and results in network error). Status code reply: OK if the connection exists and has been closed

func (*Redis) ClientList

func (r *Redis) ClientList() (string, error)

ClientList returns information and statistics about the client connections server in a mostly human readable format. Bulk reply: a unique string, formatted as follows: One client connection per line (separated by LF) Each line is composed of a succession of property=value fields separated by a space character.

func (*Redis) ClientPause

func (r *Redis) ClientPause(timeout uint64) error

ClientPause stops the server processing commands from clients for some time.

func (*Redis) ClientSetName

func (r *Redis) ClientSetName(name string) error

ClientSetName assigns a name to the current connection.

func (*Redis) ClosePool

func (r *Redis) ClosePool()

ClosePool close the redis client under connection pool this will close all the connections which in the pool

func (*Redis) ConfigGet

func (r *Redis) ConfigGet(parameter string) (map[string]string, error)

ConfigGet is used to read the configuration parameters of a running Redis server. Not all the configuration parameters are supported in Redis 2.4, while Redis 2.6 can read the whole configuration of a server using this command. CONFIG GET takes a single argument, which is a glob-style pattern.

func (*Redis) ConfigResetStat

func (r *Redis) ConfigResetStat() error

ConfigResetStat resets the statistics reported by Redis using the INFO command. These are the counters that are reset: Keyspace hits Keyspace misses Number of commands processed Number of connections received Number of expired keys Number of rejected connections Latest fork(2) time The aof_delayed_fsync counter

func (*Redis) ConfigRewrite

func (r *Redis) ConfigRewrite() error

ConfigRewrite rewrites the redis.conf file the server was started with, applying the minimal changes needed to make it reflecting the configuration currently used by the server, that may be different compared to the original one because of the use of the CONFIG SET command. Available since 2.8.0.

func (*Redis) ConfigSet

func (r *Redis) ConfigSet(parameter, value string) error

ConfigSet is used in order to reconfigure the server at run time without the need to restart Redis. You can change both trivial parameters or switch from one to another persistence option using this command.

func (*Redis) DBSize

func (r *Redis) DBSize() (int64, error)

DBSize return the number of keys in the currently-selected database.

func (*Redis) DebugObject

func (r *Redis) DebugObject(key string) (string, error)

DebugObject is a debugging command that should not be used by clients.

func (*Redis) Decr

func (r *Redis) Decr(key string) (int64, error)

Decr decrements the number stored at key by one. If the key does not exist, it is set to 0 before performing the operation. An error is returned if the key contains a value of the wrong type or contains a string that can not be represented as integer. This operation is limited to 64 bit signed integers. Integer reply: the value of key after the decrement

func (*Redis) DecrBy

func (r *Redis) DecrBy(key string, decrement int) (int64, error)

DecrBy decrements the number stored at key by decrement.

func (*Redis) Del

func (r *Redis) Del(keys ...string) (int64, error)

Del removes the specified keys. A key is ignored if it does not exist. Integer reply: The number of keys that were removed.

func (*Redis) Dump

func (r *Redis) Dump(key string) ([]byte, error)

Dump serialize the value stored at key in a Redis-specific format and return it to the user. The returned value can be synthesized back into a Redis key using the RESTORE command. Return []byte for maybe big data

func (*Redis) Echo

func (r *Redis) Echo(message string) (string, error)

Echo command returns message.

func (*Redis) Eval

func (r *Redis) Eval(script string, keys []string, args []string) (*Reply, error)

Eval first argument of EVAL is a Lua 5.1 script. The script does not need to define a Lua function (and should not). It is just a Lua program that will run in the context of the Redis server. The second argument of EVAL is the number of arguments that follows the script (starting from the third argument) that represent Redis key names. This arguments can be accessed by Lua using the KEYS global variable in the form of a one-based array (so KEYS[1], KEYS[2], ...).

func (*Redis) EvalSha

func (r *Redis) EvalSha(sha1 string, keys []string, args []string) (*Reply, error)

EvalSha evaluates a script cached on the server side by its SHA1 digest. Scripts are cached on the server side using the SCRIPT LOAD command.

func (*Redis) ExecuteCommand

func (r *Redis) ExecuteCommand(args ...interface{}) (*Reply, error)

ExecuteCommand send any raw redis command and receive reply from redis server

func (*Redis) Exists

func (r *Redis) Exists(key string) (bool, error)

Exists returns true if key exists.

func (*Redis) Expire

func (r *Redis) Expire(key string, seconds int) (bool, error)

Expire set a second timeout on key. After the timeout has expired, the key will automatically be deleted. A key with an associated timeout is often said to be volatile in Redis terminology.

func (*Redis) ExpireAt

func (r *Redis) ExpireAt(key string, timestamp int64) (bool, error)

ExpireAt has the same effect and semantic as expire, but instead of specifying the number of seconds representing the TTL (time to live), it takes an absolute Unix timestamp (seconds since January 1, 1970).

func (*Redis) FlushAll

func (r *Redis) FlushAll() error

FlushAll delete all the keys of all the existing databases, not just the currently selected one. This command never fails.

func (*Redis) FlushDB

func (r *Redis) FlushDB() error

FlushDB delete all the keys of the currently selected DB. This command never fails.

func (*Redis) Get

func (r *Redis) Get(key string) ([]byte, error)

Get gets the value of key. If the key does not exist the special value nil is returned. An error is returned if the value stored at key is not a string, because GET only handles string values.

func (*Redis) GetBit

func (r *Redis) GetBit(key string, offset int) (int64, error)

GetBit returns the bit value at offset in the string value stored at key. When offset is beyond the string length, the string is assumed to be a contiguous space with 0 bits. When key does not exist it is assumed to be an empty string, so offset is always out of range and the value is also assumed to be a contiguous space with 0 bits.

func (*Redis) GetRange

func (r *Redis) GetRange(key string, start, end int) (string, error)

GetRange returns the substring of the string value stored at key, determined by the offsets start and end (both are inclusive). Negative offsets can be used in order to provide an offset starting from the end of the string. So -1 means the last character, -2 the penultimate and so forth. The function handles out of range requests by limiting the resulting range to the actual length of the string.

func (*Redis) GetSet

func (r *Redis) GetSet(key, value string) ([]byte, error)

GetSet atomically sets key to value and returns the old value stored at key. Returns an error when key exists but does not hold a string value.

func (*Redis) HDel

func (r *Redis) HDel(key string, fields ...string) (int64, error)

HDel command: Removes the specified fields from the hash stored at key. Specified fields that do not exist within this hash are ignored. If key does not exist, it is treated as an empty hash and this command returns 0.

func (*Redis) HExists

func (r *Redis) HExists(key, field string) (bool, error)

HExists command: Returns if field is an existing field in the hash stored at key.

func (*Redis) HGet

func (r *Redis) HGet(key, field string) ([]byte, error)

HGet command: Returns the value associated with field in the hash stored at key. Bulk reply: the value associated with field, or nil when field is not present in the hash or key does not exist.

func (*Redis) HGetAll

func (r *Redis) HGetAll(key string) (map[string]string, error)

HGetAll command: Returns all fields and values of the hash stored at key. In the returned value, every field name is followed by its value, so the length of the reply is twice the size of the hash.

func (*Redis) HIncrBy

func (r *Redis) HIncrBy(key, field string, increment int) (int64, error)

HIncrBy command: Increments the number stored at field in the hash stored at key by increment. If key does not exist, a new key holding a hash is created. If field does not exist the value is set to 0 before the operation is performed. Integer reply: the value at field after the increment operation.

func (*Redis) HIncrByFloat

func (r *Redis) HIncrByFloat(key, field string, increment float64) (float64, error)

HIncrByFloat command: Increment the specified field of an hash stored at key, and representing a floating point number, by the specified increment. If the field does not exist, it is set to 0 before performing the operation. An error is returned if one of the following conditions occur: The field contains a value of the wrong type (not a string). The current field content or the specified increment are not parsable as a double precision floating point number. Bulk reply: the value of field after the increment.

func (*Redis) HKeys

func (r *Redis) HKeys(key string) ([]string, error)

HKeys command: Returns all field names in the hash stored at key. Multi-bulk reply: list of fields in the hash, or an empty list when key does not exist.

func (*Redis) HLen

func (r *Redis) HLen(key string) (int64, error)

HLen command: Returns the number of fields contained in the hash stored at key. Integer reply: number of fields in the hash, or 0 when key does not exist.

func (*Redis) HMGet

func (r *Redis) HMGet(key string, fields ...string) ([][]byte, error)

HMGet command: Returns the values associated with the specified fields in the hash stored at key. For every field that does not exist in the hash, a nil value is returned. Because a non-existing keys are treated as empty hashes, running HMGET against a non-existing key will return a list of nil values. Multi-bulk reply: list of values associated with the given fields, in the same order as they are requested.

func (*Redis) HMSet

func (r *Redis) HMSet(key string, pairs map[string]string) error

HMSet command: Sets the specified fields to their respective values in the hash stored at key. This command overwrites any existing fields in the hash. If key does not exist, a new key holding a hash is created.

func (*Redis) HScan

func (r *Redis) HScan(key string, cursor uint64, pattern string, count int) (uint64, map[string]string, error)

HScan command: HSCAN key cursor [MATCH pattern] [COUNT count]

func (*Redis) HSet

func (r *Redis) HSet(key, field, value string) (bool, error)

HSet command: Sets field in the hash stored at key to value. If key does not exist, a new key holding a hash is created. If field already exists in the hash, it is overwritten.

func (*Redis) HSetnx

func (r *Redis) HSetnx(key, field, value string) (bool, error)

HSetnx command: Sets field in the hash stored at key to value, only if field does not yet exist. If key does not exist, a new key holding a hash is created. If field already exists, this operation has no effect.

func (*Redis) HVals

func (r *Redis) HVals(key string) ([]string, error)

HVals command: Returns all values in the hash stored at key. Multi-bulk reply: list of values in the hash, or an empty list when key does not exist.

func (*Redis) Incr

func (r *Redis) Incr(key string) (int64, error)

Incr increments the number stored at key by one. If the key does not exist, it is set to 0 before performing the operation. An error is returned if the key contains a value of the wrong type or contains a string that can not be represented as integer. Integer reply: the value of key after the increment

func (*Redis) IncrBy

func (r *Redis) IncrBy(key string, increment int) (int64, error)

IncrBy increments the number stored at key by increment. If the key does not exist, it is set to 0 before performing the operation. An error is returned if the key contains a value of the wrong type or contains a string that can not be represented as integer. Integer reply: the value of key after the increment

func (*Redis) IncrByFloat

func (r *Redis) IncrByFloat(key string, increment float64) (float64, error)

IncrByFloat increments the string representing a floating point number stored at key by the specified increment. If the key does not exist, it is set to 0 before performing the operation. An error is returned if one of the following conditions occur: The key contains a value of the wrong type (not a string). The current key content or the specified increment are not parsable as a double precision floating point number. Return bulk reply: the value of key after the increment.

func (*Redis) Info

func (r *Redis) Info(section string) (string, error)

Info returns information and statistics about the server in a format that is simple to parse by computers and easy to read by humans. format document at http://redis.io/commands/info

func (*Redis) Keys

func (r *Redis) Keys(pattern string) ([]string, error)

Keys returns all keys matching pattern.

func (*Redis) LIndex

func (r *Redis) LIndex(key string, index int) ([]byte, error)

LIndex returns the element at index index in the list stored at key. The index is zero-based, so 0 means the first element, 1 the second element and so on. Negative indices can be used to designate elements starting at the tail of the list. Here, -1 means the last element, -2 means the penultimate and so forth. When the value at key is not a list, an error is returned. Bulk reply: the requested element, or nil when index is out of range.

func (*Redis) LInsert

func (r *Redis) LInsert(key, position, pivot, value string) (int64, error)

LInsert inserts value in the list stored at key either before or after the reference value pivot. When key does not exist, it is considered an empty list and no operation is performed. An error is returned when key exists but does not hold a list value. Integer reply: the length of the list after the insert operation, or -1 when the value pivot was not found.

func (*Redis) LLen

func (r *Redis) LLen(key string) (int64, error)

LLen returns the length of the list stored at key. If key does not exist, it is interpreted as an empty list and 0 is returned. An error is returned when the value stored at key is not a list.

func (*Redis) LPop

func (r *Redis) LPop(key string) ([]byte, error)

LPop removes and returns the first element of the list stored at key. Bulk reply: the value of the first element, or nil when key does not exist.

func (*Redis) LPush

func (r *Redis) LPush(key string, values ...string) (int64, error)

LPush insert all the specified values at the head of the list stored at key. If key does not exist, it is created as empty list before performing the push operations. When key holds a value that is not a list, an error is returned. Integer reply: the length of the list after the push operations.

func (*Redis) LPushx

func (r *Redis) LPushx(key, value string) (int64, error)

LPushx inserts value at the head of the list stored at key, only if key already exists and holds a list. In contrary to LPUSH, no operation will be performed when key does not yet exist. Integer reply: the length of the list after the push operation.

func (*Redis) LRange

func (r *Redis) LRange(key string, start, end int) ([]string, error)

LRange returns the specified elements of the list stored at key. The offsets start and stop are zero-based indexes, with 0 being the first element of the list (the head of the list), 1 being the next element and so on. These offsets can also be negative numbers indicating offsets starting at the end of the list. For example, -1 is the last element of the list, -2 the penultimate, and so on.

Note that if you have a list of numbers from 0 to 100, LRANGE list 0 10 will return 11 elements, that is, the rightmost item is included. Out of range indexes will not produce an error. If start is larger than the end of the list, an empty list is returned. If stop is larger than the actual end of the list, Redis will treat it like the last element of the list. Multi-bulk reply: list of elements in the specified range.

func (*Redis) LRem

func (r *Redis) LRem(key string, count int, value string) (int64, error)

LRem removes the first count occurrences of elements equal to value from the list stored at key. The count argument influences the operation in the following ways: count > 0: Remove elements equal to value moving from head to tail. count < 0: Remove elements equal to value moving from tail to head. count = 0: Remove all elements equal to value. Integer reply: the number of removed elements.

func (*Redis) LSet

func (r *Redis) LSet(key string, index int, value string) error

LSet sets the list element at index to value. For more information on the index argument, see LINDEX. An error is returned for out of range indexes.

func (*Redis) LTrim

func (r *Redis) LTrim(key string, start, stop int) error

LTrim trim an existing list so that it will contain only the specified range of elements specified. Both start and stop are zero-based indexes, where 0 is the first element of the list (the head), 1 the next element and so on.

func (*Redis) LastSave

func (r *Redis) LastSave() (int64, error)

LastSave return the UNIX TIME of the last DB save executed with success. A client may check if a BGSAVE command succeeded reading the LASTSAVE value, then issuing a BGSAVE command and checking at regular intervals every N seconds if LASTSAVE changed. Integer reply: an UNIX time stamp.

func (*Redis) MGet

func (r *Redis) MGet(keys ...string) ([][]byte, error)

MGet returns the values of all specified keys. For every key that does not hold a string value or does not exist, the special value nil is returned. Because of this, the operation never fails. Multi-bulk reply: list of values at the specified keys.

func (*Redis) MSet

func (r *Redis) MSet(pairs map[string]string) error

MSet sets the given keys to their respective values. MSET replaces existing values with new values, just as regular SET. See MSETNX if you don't want to overwrite existing values.

func (*Redis) MSetnx

func (r *Redis) MSetnx(pairs map[string]string) (bool, error)

MSetnx sets the given keys to their respective values. MSETNX will not perform any operation at all even if just a single key already exists. True if the all the keys were set. False if no key was set (at least one key already existed).

func (*Redis) Monitor

func (r *Redis) Monitor() (*MonitorCommand, error)

Monitor sned MONITOR command to redis server.

func (*Redis) Move

func (r *Redis) Move(key string, db int) (bool, error)

Move moves key from the currently selected database (see SELECT) to the specified destination database. When key already exists in the destination database, or it does not exist in the source database, it does nothing.

func (*Redis) Object

func (r *Redis) Object(subcommand string, arguments ...string) (*Reply, error)

Object inspects the internals of Redis Objects associated with keys. It is useful for debugging or to understand if your keys are using the specially encoded data types to save space. Your application may also use the information reported by the OBJECT command to implement application level key eviction policies when using Redis as a Cache.

func (*Redis) PExpire

func (r *Redis) PExpire(key string, milliseconds int) (bool, error)

PExpire works exactly like EXPIRE but the time to live of the key is specified in milliseconds instead of seconds.

func (*Redis) PExpireAt

func (r *Redis) PExpireAt(key string, timestamp int64) (bool, error)

PExpireAt has the same effect and semantic as EXPIREAT, but the Unix time at which the key will expire is specified in milliseconds instead of seconds.

func (*Redis) PFAdd

func (r *Redis) PFAdd(key string, elements ...string) (int64, error)

PFAdd adds all the element arguments to the HyperLogLog data structure stored at the variable name specified as first argument.

func (*Redis) PFCount

func (r *Redis) PFCount(keys ...string) (int64, error)

PFCount returns the approximated cardinality computed by the HyperLogLog data structure stored at the specified variable, which is 0 if the variable does not exist. When called with multiple keys, returns the approximated cardinality of the union of the HyperLogLogs passed, by internally merging the HyperLogLogs stored at the provided keys into a temporary hyperLogLog.

func (*Redis) PFMerge

func (r *Redis) PFMerge(destkey string, sourcekeys ...string) error

PFMerge merges multiple HyperLogLog values into an unique value that will approximate the cardinality of the union of the observed Sets of the source HyperLogLog structures. The computed merged HyperLogLog is set to the destination variable, which is created if does not exist (defauling to an empty HyperLogLog).

func (*Redis) PSetex

func (r *Redis) PSetex(key string, milliseconds int, value string) error

PSetex works exactly like SETEX with the sole difference that the expire time is specified in milliseconds instead of seconds.

func (*Redis) PTTL

func (r *Redis) PTTL(key string) (int64, error)

PTTL returns the remaining time to live of a key that has an expire set, with the sole difference that TTL returns the amount of remaining time in seconds while PTTL returns it in milliseconds.

func (*Redis) Persist

func (r *Redis) Persist(key string) (bool, error)

Persist removes the existing timeout on key, turning the key from volatile (a key with an expire set) to persistent (a key that will never expire as no timeout is associated). True if the timeout was removed. False if key does not exist or does not have an associated timeout.

func (*Redis) Ping

func (r *Redis) Ping() error

Ping command returns PONG. This command is often used to test if a connection is still alive, or to measure latency.

func (*Redis) Pipelining

func (r *Redis) Pipelining() (*Pipelined, error)

Pipelining new a Pipelined from *redis.

func (*Redis) PubSub

func (r *Redis) PubSub() (*PubSub, error)

PubSub new a PubSub from *redis.

func (*Redis) Publish

func (r *Redis) Publish(channel, message string) (int64, error)

Publish posts a message to the given channel. Integer reply: the number of clients that received the message.

func (*Redis) RPop

func (r *Redis) RPop(key string) ([]byte, error)

RPop removes and returns the last element of the list stored at key. Bulk reply: the value of the last element, or nil when key does not exist.

func (*Redis) RPopLPush

func (r *Redis) RPopLPush(source, destination string) ([]byte, error)

RPopLPush atomically returns and removes the last element (tail) of the list stored at source, and pushes the element at the first element (head) of the list stored at destination.

If source does not exist, the value nil is returned and no operation is performed. If source and destination are the same, the operation is equivalent to removing the last element from the list and pushing it as first element of the list, so it can be considered as a list rotation command.

func (*Redis) RPush

func (r *Redis) RPush(key string, values ...string) (int64, error)

RPush insert all the specified values at the tail of the list stored at key. If key does not exist, it is created as empty list before performing the push operation. When key holds a value that is not a list, an error is returned.

func (*Redis) RPushx

func (r *Redis) RPushx(key, value string) (int64, error)

RPushx inserts value at the tail of the list stored at key, only if key already exists and holds a list. In contrary to RPUSH, no operation will be performed when key does not yet exist.

func (*Redis) RandomKey

func (r *Redis) RandomKey() ([]byte, error)

RandomKey returns a random key from the currently selected database. Bulk reply: the random key, or nil when the database is empty.

func (*Redis) Rename

func (r *Redis) Rename(key, newkey string) error

Rename renames key to newkey. It returns an error when the source and destination names are the same, or when key does not exist. If newkey already exists it is overwritten, when this happens RENAME executes an implicit DEL operation, so if the deleted key contains a very big value it may cause high latency even if RENAME itself is usually a constant-time operation.

func (*Redis) Renamenx

func (r *Redis) Renamenx(key, newkey string) (bool, error)

Renamenx renames key to newkey if newkey does not yet exist. It returns an error under the same conditions as RENAME.

func (*Redis) Restore

func (r *Redis) Restore(key string, ttl int, serialized string) error

Restore creates a key associated with a value that is obtained by deserializing the provided serialized value (obtained via DUMP). If ttl is 0 the key is created without any expire, otherwise the specified expire time (in milliseconds) is set. RESTORE checks the RDB version and data checksum. If they don't match an error is returned.

func (*Redis) SAdd

func (r *Redis) SAdd(key string, members ...string) (int64, error)

SAdd add the specified members to the set stored at key. Specified members that are already a member of this set are ignored. If key does not exist, a new set is created before adding the specified members. An error is returned when the value stored at key is not a set.

Integer reply: the number of elements that were added to the set, not including all the elements already present into the set.

func (*Redis) SCard

func (r *Redis) SCard(key string) (int64, error)

SCard returns the set cardinality (number of elements) of the set stored at key.

func (*Redis) SDiff

func (r *Redis) SDiff(keys ...string) ([]string, error)

SDiff returns the members of the set resulting from the difference between the first set and all the successive sets. Keys that do not exist are considered to be empty sets. Multi-bulk reply: list with members of the resulting set.

func (*Redis) SDiffStore

func (r *Redis) SDiffStore(destination string, keys ...string) (int64, error)

SDiffStore is equal to SDIFF, but instead of returning the resulting set, it is stored in destination. If destination already exists, it is overwritten. Integer reply: the number of elements in the resulting set.

func (*Redis) SInter

func (r *Redis) SInter(keys ...string) ([]string, error)

SInter returns the members of the set resulting from the intersection of all the given sets. Multi-bulk reply: list with members of the resulting set.

func (*Redis) SInterStore

func (r *Redis) SInterStore(destination string, keys ...string) (int64, error)

SInterStore is equal to SINTER, but instead of returning the resulting set, it is stored in destination. If destination already exists, it is overwritten. Integer reply: the number of elements in the resulting set.

func (*Redis) SIsMember

func (r *Redis) SIsMember(key, member string) (bool, error)

SIsMember returns if member is a member of the set stored at key.

func (*Redis) SMembers

func (r *Redis) SMembers(key string) ([]string, error)

SMembers returns all the members of the set value stored at key.

func (*Redis) SMove

func (r *Redis) SMove(source, destination, member string) (bool, error)

SMove moves member from the set at source to the set at destination. This operation is atomic. In every given moment the element will appear to be a member of source or destination for other clients.

func (*Redis) SPop

func (r *Redis) SPop(key string) ([]byte, error)

SPop removes and returns a random element from the set value stored at key. Bulk reply: the removed element, or nil when key does not exist.

func (*Redis) SRandMember

func (r *Redis) SRandMember(key string) ([]byte, error)

SRandMember returns a random element from the set value stored at key. Bulk reply: the command returns a Bulk Reply with the randomly selected element, or nil when key does not exist.

func (*Redis) SRandMemberCount

func (r *Redis) SRandMemberCount(key string, count int) ([]string, error)

SRandMemberCount returns an array of count distinct elements if count is positive. If called with a negative count the behavior changes and the command is allowed to return the same element multiple times. In this case the numer of returned elements is the absolute value of the specified count. returns an array of elements, or an empty array when key does not exist.

func (*Redis) SRem

func (r *Redis) SRem(key string, members ...string) (int64, error)

SRem remove the specified members from the set stored at key. Specified members that are not a member of this set are ignored. If key does not exist, it is treated as an empty set and this command returns 0. An error is returned when the value stored at key is not a set. Integer reply: the number of members that were removed from the set, not including non existing members.

func (*Redis) SScan

func (r *Redis) SScan(key string, cursor uint64, pattern string, count int) (uint64, []string, error)

SScan key cursor [MATCH pattern] [COUNT count]

func (*Redis) SUnion

func (r *Redis) SUnion(keys ...string) ([]string, error)

SUnion returns the members of the set resulting from the union of all the given sets. Multi-bulk reply: list with members of the resulting set.

func (*Redis) SUnionStore

func (r *Redis) SUnionStore(destination string, keys ...string) (int64, error)

SUnionStore is equal to SUnion. If destination already exists, it is overwritten. Integer reply: the number of elements in the resulting set.

func (*Redis) Save

func (r *Redis) Save() error

Save performs a synchronous save of the dataset producing a point in time snapshot of all the data inside the Redis instance, in the form of an RDB file. You almost never want to call SAVE in production environments where it will block all the other clients. Instead usually BGSAVE is used.

func (*Redis) Scan

func (r *Redis) Scan(cursor uint64, pattern string, count int) (uint64, []string, error)

Scan command: SCAN cursor [MATCH pattern] [COUNT count]

func (*Redis) ScriptExists

func (r *Redis) ScriptExists(scripts ...string) ([]bool, error)

ScriptExists returns information about the existence of the scripts in the script cache. Multi-bulk reply The command returns an array of integers that correspond to the specified SHA1 digest arguments. For every corresponding SHA1 digest of a script that actually exists in the script cache.

func (*Redis) ScriptFlush

func (r *Redis) ScriptFlush() error

ScriptFlush flush the Lua scripts cache. Please refer to the EVAL documentation for detailed information about Redis Lua scripting.

func (*Redis) ScriptKill

func (r *Redis) ScriptKill() error

ScriptKill kills the currently executing Lua script, assuming no write operation was yet performed by the script.

func (*Redis) ScriptLoad

func (r *Redis) ScriptLoad(script string) (string, error)

ScriptLoad Load a script into the scripts cache, without executing it. After the specified command is loaded into the script cache it will be callable using EVALSHA with the correct SHA1 digest of the script, exactly like after the first successful invocation of EVAL. Bulk reply This command returns the SHA1 digest of the script added into the script cache.

func (*Redis) Set

func (r *Redis) Set(key, value string, seconds, milliseconds int, mustExists, mustNotExists bool) error

Set sets key to hold the string value. If key already holds a value, it is overwritten, regardless of its type. Any previous time to live associated with the key is discarded on successful SET operation.

func (*Redis) SetBit

func (r *Redis) SetBit(key string, offset, value int) (int64, error)

SetBit sets or clears the bit at offset in the string value stored at key. Integer reply: the original bit value stored at offset.

func (*Redis) SetRange

func (r *Redis) SetRange(key string, offset int, value string) (int64, error)

SetRange overwrites part of the string stored at key, starting at the specified offset, for the entire length of value. Integer reply: the length of the string after it was modified by the command.

func (*Redis) Setex

func (r *Redis) Setex(key string, seconds int, value string) error

Setex sets key to hold the string value and set key to timeout after a given number of seconds.

func (*Redis) Setnx

func (r *Redis) Setnx(key, value string) (bool, error)

Setnx sets key to hold string value if key does not exist.

func (*Redis) Shutdown

func (r *Redis) Shutdown(save, noSave bool) error

Shutdown behavior is the following: Stop all the clients. Perform a blocking SAVE if at least one save point is configured. Flush the Append Only File if AOF is enabled. Quit the server.

func (*Redis) SimpleSet

func (r *Redis) SimpleSet(key, value string) error

SimpleSet do SET key value, no other arguments.

func (*Redis) SlaveOf

func (r *Redis) SlaveOf(host, port string) error

SlaveOf can change the replication settings of a slave on the fly. If a Redis server is already acting as slave, the command SLAVEOF NO ONE will turn off the replication, turning the Redis server into a MASTER. In the proper form SLAVEOF hostname port will make the server a slave of another server listening at the specified hostname and port.

If a server is already a slave of some master, SLAVEOF hostname port will stop the replication against the old server and start the synchronization against the new one, discarding the old dataset. The form SLAVEOF NO ONE will stop replication, turning the server into a MASTER, but will not discard the replication. So, if the old master stops working, it is possible to turn the slave into a master and set the application to use this new master in read/write. Later when the other Redis server is fixed, it can be reconfigured to work as a slave.

func (*Redis) SlowLogGet

func (r *Redis) SlowLogGet(n int) ([]*SlowLog, error)

SlowLogGet returns slow logs.

func (*Redis) SlowLogLen

func (r *Redis) SlowLogLen() (int64, error)

SlowLogLen Obtaining the current length of the slow log

func (*Redis) SlowLogReset

func (r *Redis) SlowLogReset() error

SlowLogReset resetting the slow log. Once deleted the information is lost forever.

func (*Redis) Sort

func (r *Redis) Sort(key string) *SortCommand

Sort doc: http://redis.io/commands/sort SORT key [BY pattern] [LIMIT offset count] [GET pattern [GET pattern ...]] [ASC|DESC] [ALPHA] [STORE destination]

func (*Redis) StrLen

func (r *Redis) StrLen(key string) (int64, error)

StrLen returns the length of the string value stored at key. An error is returned when key holds a non-string value. Integer reply: the length of the string at key, or 0 when key does not exist.

func (*Redis) TTL

func (r *Redis) TTL(key string) (int64, error)

TTL returns the remaining time to live of a key that has a timeout. Integer reply: TTL in seconds, or a negative value in order to signal an error (see the description above).

func (*Redis) Time

func (r *Redis) Time() ([]string, error)

Time returns a multi bulk reply containing two elements: unix time in seconds, microseconds.

func (*Redis) Transaction

func (r *Redis) Transaction() (*Transaction, error)

Transaction new a *transaction from *redis

func (*Redis) Type

func (r *Redis) Type(key string) (string, error)

Type returns the string representation of the type of the value stored at key. The different types that can be returned are: string, list, set, zset and hash. Status code reply: type of key, or none when key does not exist.

func (*Redis) ZAdd

func (r *Redis) ZAdd(key string, pairs map[string]float64) (int64, error)

ZAdd adds all the specified members with the specified scores to the sorted set stored at key. If a specified member is already a member of the sorted set, the score is updated and the element reinserted at the right position to ensure the correct ordering. If key does not exist, a new sorted set with the specified members as sole members is created, like if the sorted set was empty. If the key exists but does not hold a sorted set, an error is returned.

Return value: The number of elements added to the sorted sets, not including elements already existing for which the score was updated.

func (*Redis) ZCard

func (r *Redis) ZCard(key string) (int64, error)

ZCard returns the sorted set cardinality (number of elements) of the sorted set stored at key. Integer reply: the cardinality (number of elements) of the sorted set, or 0 if key does not exist.

func (*Redis) ZCount

func (r *Redis) ZCount(key, min, max string) (int64, error)

ZCount returns the number of elements in the sorted set at key with a score between min and max. The min and max arguments have the same semantic as described for ZRANGEBYSCORE. Integer reply: the number of elements in the specified score range.

func (*Redis) ZIncrBy

func (r *Redis) ZIncrBy(key string, increment float64, member string) (float64, error)

ZIncrBy increments the score of member in the sorted set stored at key by increment. If member does not exist in the sorted set, it is added with increment as its score (as if its previous score was 0.0). If key does not exist, a new sorted set with the specified member as its sole member is created. An error is returned when key exists but does not hold a sorted set. Bulk reply: the new score of member (a double precision floating point number), represented as string.

func (*Redis) ZInterStore

func (r *Redis) ZInterStore(destination string, keys []string, weights []int, aggregate string) (int64, error)

ZInterStore destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX]

func (*Redis) ZLexCount

func (r *Redis) ZLexCount(key, min, max string) (int64, error)

ZLexCount returns the number of elements in the sorted set at key with a value between min and max in order to force lexicographical ordering.

func (*Redis) ZRange

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

ZRange returns the specified range of elements in the sorted set stored at key. The elements are considered to be ordered from the lowest to the highest score. Lexicographical order is used for elements with equal score. Multi-bulk reply: list of elements in the specified range.(optionally with their scores). It is possible to pass the WITHSCORES option in order to return the scores of the elements together with the elements. The returned list will contain value1,score1,...,valueN,scoreN instead of value1,...,valueN.

func (*Redis) ZRangeByLex

func (r *Redis) ZRangeByLex(key, min, max string, limit bool, offset, count int) ([]string, error)

ZRangeByLex returns all the elements in the sorted set at key with a value between min and max in order to force lexicographical ordering.

func (*Redis) ZRangeByScore

func (r *Redis) ZRangeByScore(key, min, max string, withscores, limit bool, offset, count int) ([]string, error)

ZRangeByScore key min max [WITHSCORES] [LIMIT offset count]

func (*Redis) ZRank

func (r *Redis) ZRank(key, member string) (int64, error)

ZRank returns the rank of member in the sorted set stored at key, with the scores ordered from low to high. The rank (or index) is 0-based, which means that the member with the lowest score has rank 0.

If member exists in the sorted set, Integer reply: the rank of member. If member does not exist in the sorted set or key does not exist, Bulk reply: nil. -1 represent the nil bulk rely.

func (*Redis) ZRem

func (r *Redis) ZRem(key string, members ...string) (int64, error)

ZRem removes the specified members from the sorted set stored at key. Non existing members are ignored. An error is returned when key exists and does not hold a sorted set. Integer reply, specifically: The number of members removed from the sorted set, not including non existing members.

func (*Redis) ZRemRangeByLex

func (r *Redis) ZRemRangeByLex(key, min, max string) (int64, error)

ZRemRangeByLex removes all elements in the sorted set stored at key between the lexicographical range specified by min and max.

func (*Redis) ZRemRangeByRank

func (r *Redis) ZRemRangeByRank(key string, start, stop int) (int64, error)

ZRemRangeByRank removes all elements in the sorted set stored at key with rank between start and stop. Both start and stop are 0 -based indexes with 0 being the element with the lowest score. These indexes can be negative numbers, where they indicate offsets starting at the element with the highest score. For example: -1 is the element with the highest score, -2 the element with the second highest score and so forth. Integer reply: the number of elements removed.

func (*Redis) ZRemRangeByScore

func (r *Redis) ZRemRangeByScore(key, min, max string) (int64, error)

ZRemRangeByScore removes all elements in the sorted set stored at key with a score between min and max (inclusive). Integer reply: the number of elements removed.

func (*Redis) ZRevRange

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

ZRevRange returns the specified range of elements in the sorted set stored at key. The elements are considered to be ordered from the highest to the lowest score. Descending lexicographical order is used for elements with equal score. Multi-bulk reply: list of elements in the specified range (optionally with their scores).

func (*Redis) ZRevRangeByScore

func (r *Redis) ZRevRangeByScore(key, max, min string, withscores, limit bool, offset, count int) ([]string, error)

ZRevRangeByScore key max min [WITHSCORES] [LIMIT offset count]

func (*Redis) ZRevRank

func (r *Redis) ZRevRank(key, member string) (int64, error)

ZRevRank returns the rank of member in the sorted set stored at key, with the scores ordered from high to low. The rank (or index) is 0-based, which means that the member with the highest score has rank 0.

func (*Redis) ZScan

func (r *Redis) ZScan(key string, cursor uint64, pattern string, count int) (uint64, []string, error)

ZScan key cursor [MATCH pattern] [COUNT count]

func (*Redis) ZScore

func (r *Redis) ZScore(key, member string) ([]byte, error)

ZScore returns the score of member in the sorted set at key. If member does not exist in the sorted set, or key does not exist, nil is returned. Bulk reply: the score of member (a double precision floating point number), represented as string.

func (*Redis) ZUnionStore

func (r *Redis) ZUnionStore(destination string, keys []string, weights []int, aggregate string) (int64, error)

ZUnionStore destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX]

type Reply

type Reply struct {
	Type    int
	Error   string
	Status  string
	Integer int64  // Support Redis 64bit integer
	Bulk    []byte // Support Redis Null Bulk Reply
	Multi   []*Reply
}

Reply struct Represent Redis Reply

func (*Reply) BoolArrayValue

func (rp *Reply) BoolArrayValue() ([]bool, error)

BoolArrayValue indicates redis reply a multi value each bulk is an integer(bool)

func (*Reply) BoolValue

func (rp *Reply) BoolValue() (bool, error)

BoolValue returns redis reply integer which are also extensively used in order to return true or false. For instance commands like EXISTS or SISMEMBER will return 1 for true and 0 for false.

func (*Reply) BytesArrayValue

func (rp *Reply) BytesArrayValue() ([][]byte, error)

BytesArrayValue indicates redis reply a multi value which represent list, but item in the list maybe nil

func (*Reply) BytesValue

func (rp *Reply) BytesValue() ([]byte, error)

BytesValue indicates redis reply a bulk which maybe nil

func (*Reply) HashValue

func (rp *Reply) HashValue() (map[string]string, error)

HashValue indicates redis reply a multi value which represent hash map

func (*Reply) IntegerValue

func (rp *Reply) IntegerValue() (int64, error)

IntegerValue returns redis reply number value

func (*Reply) ListValue

func (rp *Reply) ListValue() ([]string, error)

ListValue indicates redis reply a multi value which represent list

func (*Reply) MultiValue

func (rp *Reply) MultiValue() ([]*Reply, error)

MultiValue indicates redis reply a multi bulk

func (*Reply) OKValue

func (rp *Reply) OKValue() error

OKValue indicates redis reply a OK status string

func (*Reply) StatusValue

func (rp *Reply) StatusValue() (string, error)

StatusValue indicates redis reply a status string

func (*Reply) StringValue

func (rp *Reply) StringValue() (string, error)

StringValue indicates redis reply a bulk which should not be nil

type SlowLog

type SlowLog struct {
	ID           int64
	Timestamp    int64
	Microseconds int64
	Command      []string
}

SlowLog is used in order to read and reset the Redis slow queries log.

type SortCommand

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

SortCommand represents a redis Sort command

func (*SortCommand) ASC

func (s *SortCommand) ASC() *SortCommand

ASC sets sort order to ASC.

func (*SortCommand) Alpha

func (s *SortCommand) Alpha(b bool) *SortCommand

Alpha sets ALPHA to sort command.

func (*SortCommand) By

func (s *SortCommand) By(pattern string) *SortCommand

By can also take a non-existent key, which causes SORT to skip the sorting operation.

func (*SortCommand) DESC

func (s *SortCommand) DESC() *SortCommand

DESC sets sort order to DESC.

func (*SortCommand) Get

func (s *SortCommand) Get(patterns ...string) *SortCommand

Get sets sort GET arguments.

func (*SortCommand) Limit

func (s *SortCommand) Limit(offset, count int) *SortCommand

Limit takes the offset and count argument, specifying the number of elements to skip and the count argument, specifying the number of elements to return from starting at offset.

func (*SortCommand) Run

func (s *SortCommand) Run() (*Reply, error)

Run performs redis sort command.

func (*SortCommand) Store

func (s *SortCommand) Store(destination string) *SortCommand

Store sets the sorted result store to.

type Transaction

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

Transaction doc: http://redis.io/topics/transactions MULTI, EXEC, DISCARD and WATCH are the foundation of transactions in Redis. A Redis script is transactional by definition, so everything you can do with a Redis transaction, you can also do with a script, and usually the script will be both simpler and faster.

func (*Transaction) Close

func (t *Transaction) Close()

Close closes the transaction, put the under connection back for reuse

func (*Transaction) Command

func (t *Transaction) Command(args ...interface{}) error

Command send raw redis command to redis server and redis will return QUEUED back

func (*Transaction) Discard

func (t *Transaction) Discard() error

Discard flushes all previously queued commands in a transaction and restores the connection state to normal. If WATCH was used, DISCARD unwatches all keys.

func (*Transaction) Exec

func (t *Transaction) Exec() ([]*Reply, error)

Exec executes all previously queued commands in a transaction and restores the connection state to normal. When using WATCH, EXEC will execute commands only if the watched keys were not modified, allowing for a check-and-set mechanism.

func (*Transaction) UnWatch

func (t *Transaction) UnWatch() error

UnWatch flushes all the previously watched keys for a transaction. If you call EXEC or DISCARD, there's no need to manually call UNWATCH.

func (*Transaction) Watch

func (t *Transaction) Watch(keys ...string) error

Watch marks the given keys to be watched for conditional execution of a transaction.

Jump to

Keyboard shortcuts

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