redis

package module
v6.15.9+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2020 License: BSD-2-Clause Imports: 25 Imported by: 0

README

Redis client for Golang

Build Status GoDoc Airbrake

Supports:

API docs: https://godoc.org/github.com/go-redis/redis. Examples: https://godoc.org/github.com/go-redis/redis#pkg-examples.

Installation

Install:

go get -u github.com/go-redis/redis

Import:

import "github.com/go-redis/redis"

Quickstart

func ExampleNewClient() {
	client := redis.NewClient(&redis.Options{
		Addr:     "localhost:6379",
		Password: "", // no password set
		DB:       0,  // use default DB
	})

	pong, err := client.Ping().Result()
	fmt.Println(pong, err)
	// Output: PONG <nil>
}

func ExampleClient() {
	err := client.Set("key", "value", 0).Err()
	if err != nil {
		panic(err)
	}

	val, err := client.Get("key").Result()
	if err != nil {
		panic(err)
	}
	fmt.Println("key", val)

	val2, err := client.Get("key2").Result()
	if err == redis.Nil {
		fmt.Println("key2 does not exist")
	} else if err != nil {
		panic(err)
	} else {
		fmt.Println("key2", val2)
	}
	// Output: key value
	// key2 does not exist
}

Howto

Please go through examples to get an idea how to use this package.

Look and feel

Some corner cases:

// SET key value EX 10 NX
set, err := client.SetNX("key", "value", 10*time.Second).Result()

// SORT list LIMIT 0 2 ASC
vals, err := client.Sort("list", redis.Sort{Offset: 0, Count: 2, Order: "ASC"}).Result()

// ZRANGEBYSCORE zset -inf +inf WITHSCORES LIMIT 0 2
vals, err := client.ZRangeByScoreWithScores("zset", redis.ZRangeBy{
	Min: "-inf",
	Max: "+inf",
	Offset: 0,
	Count: 2,
}).Result()

// ZINTERSTORE out 2 zset1 zset2 WEIGHTS 2 3 AGGREGATE SUM
vals, err := client.ZInterStore("out", redis.ZStore{Weights: []int64{2, 3}}, "zset1", "zset2").Result()

// EVAL "return {KEYS[1],ARGV[1]}" 1 "key" "hello"
vals, err := client.Eval("return {KEYS[1],ARGV[1]}", []string{"key"}, "hello").Result()

Benchmark

go-redis vs redigo:

BenchmarkSetGoRedis10Conns64Bytes-4 	  200000	      7621 ns/op	     210 B/op	       6 allocs/op
BenchmarkSetGoRedis100Conns64Bytes-4	  200000	      7554 ns/op	     210 B/op	       6 allocs/op
BenchmarkSetGoRedis10Conns1KB-4     	  200000	      7697 ns/op	     210 B/op	       6 allocs/op
BenchmarkSetGoRedis100Conns1KB-4    	  200000	      7688 ns/op	     210 B/op	       6 allocs/op
BenchmarkSetGoRedis10Conns10KB-4    	  200000	      9214 ns/op	     210 B/op	       6 allocs/op
BenchmarkSetGoRedis100Conns10KB-4   	  200000	      9181 ns/op	     210 B/op	       6 allocs/op
BenchmarkSetGoRedis10Conns1MB-4     	    2000	    583242 ns/op	    2337 B/op	       6 allocs/op
BenchmarkSetGoRedis100Conns1MB-4    	    2000	    583089 ns/op	    2338 B/op	       6 allocs/op
BenchmarkSetRedigo10Conns64Bytes-4  	  200000	      7576 ns/op	     208 B/op	       7 allocs/op
BenchmarkSetRedigo100Conns64Bytes-4 	  200000	      7782 ns/op	     208 B/op	       7 allocs/op
BenchmarkSetRedigo10Conns1KB-4      	  200000	      7958 ns/op	     208 B/op	       7 allocs/op
BenchmarkSetRedigo100Conns1KB-4     	  200000	      7725 ns/op	     208 B/op	       7 allocs/op
BenchmarkSetRedigo10Conns10KB-4     	  100000	     18442 ns/op	     208 B/op	       7 allocs/op
BenchmarkSetRedigo100Conns10KB-4    	  100000	     18818 ns/op	     208 B/op	       7 allocs/op
BenchmarkSetRedigo10Conns1MB-4      	    2000	    668829 ns/op	     226 B/op	       7 allocs/op
BenchmarkSetRedigo100Conns1MB-4     	    2000	    679542 ns/op	     226 B/op	       7 allocs/op

Redis Cluster:

BenchmarkRedisPing-4                	  200000	      6983 ns/op	     116 B/op	       4 allocs/op
BenchmarkRedisClusterPing-4         	  100000	     11535 ns/op	     117 B/op	       4 allocs/op

See also

Documentation

Overview

Package redis implements a Redis client.

Example (CustomCommand)
package main

import (
	"fmt"

	"github.com/go-redis/redis"
)

var redisdb *redis.Client

func main() {
	Get := func(redisdb *redis.Client, key string) *redis.StringCmd {
		cmd := redis.NewStringCmd("get", key)
		redisdb.Process(cmd)
		return cmd
	}

	v, err := Get(redisdb, "key_does_not_exist").Result()
	fmt.Printf("%q %s", v, err)
}
Output:

"" redis: nil
Example (CustomCommand2)
package main

import (
	"fmt"

	"github.com/go-redis/redis"
)

var redisdb *redis.Client

func main() {
	v, err := redisdb.Do("get", "key_does_not_exist").String()
	fmt.Printf("%q %s", v, err)
}
Output:

"" redis: nil
Example (Instrumentation)
package main

import (
	"fmt"

	"github.com/go-redis/redis"
)

func main() {
	redisdb := redis.NewClient(&redis.Options{
		Addr: ":6379",
	})
	redisdb.WrapProcess(func(old func(cmd redis.Cmder) error) func(cmd redis.Cmder) error {
		return func(cmd redis.Cmder) error {
			fmt.Printf("starting processing: <%s>\n", cmd)
			err := old(cmd)
			fmt.Printf("finished processing: <%s>\n", cmd)
			return err
		}
	})

	redisdb.Ping()
}
Output:

starting processing: <ping: >
finished processing: <ping: PONG>

Index

Examples

Constants

View Source
const Nil = proto.Nil

Nil reply Redis returns when key does not exist.

View Source
const TxFailedErr = proto.RedisError("redis: transaction failed")

TxFailedErr transaction redis failed.

Variables

This section is empty.

Functions

func SetLogger

func SetLogger(logger *log.Logger)

Types

type BitCount

type BitCount struct {
	Start, End int64
}

type BoolCmd

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

func NewBoolCmd

func NewBoolCmd(args ...interface{}) *BoolCmd

func NewBoolResult

func NewBoolResult(val bool, err error) *BoolCmd

NewBoolResult returns a BoolCmd initialised with val and err for testing

func (*BoolCmd) Args

func (cmd *BoolCmd) Args() []interface{}

func (*BoolCmd) Err

func (cmd *BoolCmd) Err() error

func (*BoolCmd) Name

func (cmd *BoolCmd) Name() string

func (*BoolCmd) Result

func (cmd *BoolCmd) Result() (bool, error)

func (*BoolCmd) String

func (cmd *BoolCmd) String() string

func (*BoolCmd) Val

func (cmd *BoolCmd) Val() bool

type BoolSliceCmd

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

func NewBoolSliceCmd

func NewBoolSliceCmd(args ...interface{}) *BoolSliceCmd

func NewBoolSliceResult

func NewBoolSliceResult(val []bool, err error) *BoolSliceCmd

NewBoolSliceResult returns a BoolSliceCmd initialised with val and err for testing

func (*BoolSliceCmd) Args

func (cmd *BoolSliceCmd) Args() []interface{}

func (*BoolSliceCmd) Err

func (cmd *BoolSliceCmd) Err() error

func (*BoolSliceCmd) Name

func (cmd *BoolSliceCmd) Name() string

func (*BoolSliceCmd) Result

func (cmd *BoolSliceCmd) Result() ([]bool, error)

func (*BoolSliceCmd) String

func (cmd *BoolSliceCmd) String() string

func (*BoolSliceCmd) Val

func (cmd *BoolSliceCmd) Val() []bool

type Client

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

Client is a Redis client representing a pool of zero or more underlying connections. It's safe for concurrent use by multiple goroutines.

Example
package main

import (
	"fmt"

	"github.com/go-redis/redis"
)

var redisdb *redis.Client

func main() {
	err := redisdb.Set("key", "value", 0).Err()
	if err != nil {
		panic(err)
	}

	val, err := redisdb.Get("key").Result()
	if err != nil {
		panic(err)
	}
	fmt.Println("key", val)

	val2, err := redisdb.Get("missing_key").Result()
	if err == redis.Nil {
		fmt.Println("missing_key does not exist")
	} else if err != nil {
		panic(err)
	} else {
		fmt.Println("missing_key", val2)
	}
}
Output:

key value
missing_key does not exist

func NewClient

func NewClient(opt *Options) *Client

NewClient returns a client to the Redis Server specified by Options.

Example
package main

import (
	"fmt"

	"github.com/go-redis/redis"
)

func main() {
	redisdb := redis.NewClient(&redis.Options{
		Addr:     "localhost:6379", // use default Addr
		Password: "",               // no password set
		DB:       0,                // use default DB
	})

	pong, err := redisdb.Ping().Result()
	fmt.Println(pong, err)
}
Output:

PONG <nil>

func NewFailoverClient

func NewFailoverClient(failoverOpt *FailoverOptions) *Client

NewFailoverClient returns a Redis client that uses Redis Sentinel for automatic failover. It's safe for concurrent use by multiple goroutines.

Example
package main

import (
	"github.com/go-redis/redis"
)

func main() {
	// See http://redis.io/topics/sentinel for instructions how to
	// setup Redis Sentinel.
	redisdb := redis.NewFailoverClient(&redis.FailoverOptions{
		MasterName:    "master",
		SentinelAddrs: []string{":26379"},
	})
	redisdb.Ping()
}
Output:

func (*Client) Append

func (c *Client) Append(key, value string) *IntCmd

func (*Client) BLPop

func (c *Client) BLPop(timeout time.Duration, keys ...string) *StringSliceCmd
Example
package main

import (
	"fmt"
	"time"

	"github.com/go-redis/redis"
)

var redisdb *redis.Client

func main() {
	if err := redisdb.RPush("queue", "message").Err(); err != nil {
		panic(err)
	}

	// use `redisdb.BLPop(0, "queue")` for infinite waiting time
	result, err := redisdb.BLPop(1*time.Second, "queue").Result()
	if err != nil {
		panic(err)
	}

	fmt.Println(result[0], result[1])
}
Output:

queue message

func (*Client) BRPop

func (c *Client) BRPop(timeout time.Duration, keys ...string) *StringSliceCmd

func (*Client) BRPopLPush

func (c *Client) BRPopLPush(source, destination string, timeout time.Duration) *StringCmd

func (*Client) BZPopMax

func (c *Client) BZPopMax(timeout time.Duration, keys ...string) *ZWithKeyCmd

Redis `BZPOPMAX key [key ...] timeout` command.

func (*Client) BZPopMin

func (c *Client) BZPopMin(timeout time.Duration, keys ...string) *ZWithKeyCmd

Redis `BZPOPMIN key [key ...] timeout` command.

func (*Client) BgRewriteAOF

func (c *Client) BgRewriteAOF() *StatusCmd

func (*Client) BgSave

func (c *Client) BgSave() *StatusCmd

func (*Client) BitCount

func (c *Client) BitCount(key string, bitCount *BitCount) *IntCmd

func (*Client) BitOpAnd

func (c *Client) BitOpAnd(destKey string, keys ...string) *IntCmd

func (*Client) BitOpNot

func (c *Client) BitOpNot(destKey string, key string) *IntCmd

func (*Client) BitOpOr

func (c *Client) BitOpOr(destKey string, keys ...string) *IntCmd

func (*Client) BitOpXor

func (c *Client) BitOpXor(destKey string, keys ...string) *IntCmd

func (*Client) BitPos

func (c *Client) BitPos(key string, bit int64, pos ...int64) *IntCmd

func (*Client) ClientGetName

func (c *Client) ClientGetName() *StringCmd

ClientGetName returns the name of the connection.

func (*Client) ClientID

func (c *Client) ClientID() *IntCmd

func (*Client) ClientKill

func (c *Client) ClientKill(ipPort string) *StatusCmd

func (*Client) ClientKillByFilter

func (c *Client) ClientKillByFilter(keys ...string) *IntCmd

ClientKillByFilter is new style synx, while the ClientKill is old CLIENT KILL <option> [value] ... <option> [value]

func (*Client) ClientList

func (c *Client) ClientList() *StringCmd

func (*Client) ClientPause

func (c *Client) ClientPause(dur time.Duration) *BoolCmd

func (*Client) ClientUnblock

func (c *Client) ClientUnblock(id int64) *IntCmd

func (*Client) ClientUnblockWithError

func (c *Client) ClientUnblockWithError(id int64) *IntCmd

func (*Client) Close

func (c *Client) Close() error

Close closes the client, releasing any open resources.

It is rare to Close a Client, as the Client is meant to be long-lived and shared between many goroutines.

func (*Client) ClusterAddSlots

func (c *Client) ClusterAddSlots(slots ...int) *StatusCmd

func (*Client) ClusterAddSlotsRange

func (c *Client) ClusterAddSlotsRange(min, max int) *StatusCmd

func (*Client) ClusterCountFailureReports

func (c *Client) ClusterCountFailureReports(nodeID string) *IntCmd

func (*Client) ClusterCountKeysInSlot

func (c *Client) ClusterCountKeysInSlot(slot int) *IntCmd

func (*Client) ClusterDelSlots

func (c *Client) ClusterDelSlots(slots ...int) *StatusCmd

func (*Client) ClusterDelSlotsRange

func (c *Client) ClusterDelSlotsRange(min, max int) *StatusCmd

func (*Client) ClusterFailover

func (c *Client) ClusterFailover() *StatusCmd

func (*Client) ClusterForget

func (c *Client) ClusterForget(nodeID string) *StatusCmd

func (*Client) ClusterGetKeysInSlot

func (c *Client) ClusterGetKeysInSlot(slot int, count int) *StringSliceCmd

func (*Client) ClusterInfo

func (c *Client) ClusterInfo() *StringCmd

func (*Client) ClusterKeySlot

func (c *Client) ClusterKeySlot(key string) *IntCmd

func (*Client) ClusterMeet

func (c *Client) ClusterMeet(host, port string) *StatusCmd

func (*Client) ClusterNodes

func (c *Client) ClusterNodes() *StringCmd

func (*Client) ClusterReplicate

func (c *Client) ClusterReplicate(nodeID string) *StatusCmd

func (*Client) ClusterResetHard

func (c *Client) ClusterResetHard() *StatusCmd

func (*Client) ClusterResetSoft

func (c *Client) ClusterResetSoft() *StatusCmd

func (*Client) ClusterSaveConfig

func (c *Client) ClusterSaveConfig() *StatusCmd

func (*Client) ClusterSlaves

func (c *Client) ClusterSlaves(nodeID string) *StringSliceCmd

func (*Client) ClusterSlots

func (c *Client) ClusterSlots() *ClusterSlotsCmd

func (*Client) Command

func (c *Client) Command() *CommandsInfoCmd

func (*Client) ConfigGet

func (c *Client) ConfigGet(parameter string) *SliceCmd

func (*Client) ConfigResetStat

func (c *Client) ConfigResetStat() *StatusCmd

func (*Client) ConfigRewrite

func (c *Client) ConfigRewrite() *StatusCmd

func (*Client) ConfigSet

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

func (*Client) Context

func (c *Client) Context() context.Context

func (*Client) DBSize

func (c *Client) DBSize() *IntCmd

func (*Client) DbSize

func (c *Client) DbSize() *IntCmd

Deperecated. Use DBSize instead.

func (*Client) DebugObject

func (c *Client) DebugObject(key string) *StringCmd

func (*Client) Decr

func (c *Client) Decr(key string) *IntCmd

func (*Client) DecrBy

func (c *Client) DecrBy(key string, decrement int64) *IntCmd

func (*Client) Del

func (c *Client) Del(keys ...string) *IntCmd

func (*Client) Do

func (c *Client) Do(args ...interface{}) *Cmd

Do creates a Cmd from the args and processes the cmd.

func (*Client) Dump

func (c *Client) Dump(key string) *StringCmd

func (*Client) Echo

func (c *Client) Echo(message interface{}) *StringCmd

func (*Client) Eval

func (c *Client) Eval(script string, keys []string, args ...interface{}) *Cmd

func (*Client) EvalSha

func (c *Client) EvalSha(sha1 string, keys []string, args ...interface{}) *Cmd

func (*Client) Exists

func (c *Client) Exists(keys ...string) *IntCmd

func (*Client) Expire

func (c *Client) Expire(key string, expiration time.Duration) *BoolCmd

func (*Client) ExpireAt

func (c *Client) ExpireAt(key string, tm time.Time) *BoolCmd

func (*Client) FlushAll

func (c *Client) FlushAll() *StatusCmd

func (*Client) FlushAllAsync

func (c *Client) FlushAllAsync() *StatusCmd

func (*Client) FlushDB

func (c *Client) FlushDB() *StatusCmd

func (*Client) FlushDBAsync

func (c *Client) FlushDBAsync() *StatusCmd

func (*Client) FlushDb

func (c *Client) FlushDb() *StatusCmd

Deprecated. Use FlushDB instead.

func (*Client) GeoAdd

func (c *Client) GeoAdd(key string, geoLocation ...*GeoLocation) *IntCmd

func (*Client) GeoDist

func (c *Client) GeoDist(key string, member1, member2, unit string) *FloatCmd

func (*Client) GeoHash

func (c *Client) GeoHash(key string, members ...string) *StringSliceCmd

func (*Client) GeoPos

func (c *Client) GeoPos(key string, members ...string) *GeoPosCmd

func (*Client) GeoRadius

func (c *Client) GeoRadius(key string, longitude, latitude float64, query *GeoRadiusQuery) *GeoLocationCmd

func (*Client) GeoRadiusByMember

func (c *Client) GeoRadiusByMember(key, member string, query *GeoRadiusQuery) *GeoLocationCmd

func (*Client) GeoRadiusByMemberRO

func (c *Client) GeoRadiusByMemberRO(key, member string, query *GeoRadiusQuery) *GeoLocationCmd

func (*Client) GeoRadiusRO

func (c *Client) GeoRadiusRO(key string, longitude, latitude float64, query *GeoRadiusQuery) *GeoLocationCmd

func (*Client) Get

func (c *Client) Get(key string) *StringCmd

Redis `GET key` command. It returns redis.Nil error when key does not exist.

func (*Client) GetBit

func (c *Client) GetBit(key string, offset int64) *IntCmd

func (*Client) GetRange

func (c *Client) GetRange(key string, start, end int64) *StringCmd

func (*Client) GetSet

func (c *Client) GetSet(key string, value interface{}) *StringCmd

func (*Client) HDel

func (c *Client) HDel(key string, fields ...string) *IntCmd

func (*Client) HExists

func (c *Client) HExists(key, field string) *BoolCmd

func (*Client) HGet

func (c *Client) HGet(key, field string) *StringCmd

func (*Client) HGetAll

func (c *Client) HGetAll(key string) *StringStringMapCmd

func (*Client) HIncrBy

func (c *Client) HIncrBy(key, field string, incr int64) *IntCmd

func (*Client) HIncrByFloat

func (c *Client) HIncrByFloat(key, field string, incr float64) *FloatCmd

func (*Client) HKeys

func (c *Client) HKeys(key string) *StringSliceCmd

func (*Client) HLen

func (c *Client) HLen(key string) *IntCmd

func (*Client) HMGet

func (c *Client) HMGet(key string, fields ...string) *SliceCmd

func (*Client) HMSet

func (c *Client) HMSet(key string, fields map[string]interface{}) *StatusCmd

func (*Client) HScan

func (c *Client) HScan(key string, cursor uint64, match string, count int64) *ScanCmd

func (*Client) HSet

func (c *Client) HSet(key, field string, value interface{}) *BoolCmd

func (*Client) HSetNX

func (c *Client) HSetNX(key, field string, value interface{}) *BoolCmd

func (*Client) HVals

func (c *Client) HVals(key string) *StringSliceCmd

func (*Client) Incr

func (c *Client) Incr(key string) *IntCmd
Example
package main

import (
	"fmt"

	"github.com/go-redis/redis"
)

var redisdb *redis.Client

func main() {
	result, err := redisdb.Incr("counter").Result()
	if err != nil {
		panic(err)
	}

	fmt.Println(result)
}
Output:

1

func (*Client) IncrBy

func (c *Client) IncrBy(key string, value int64) *IntCmd

func (*Client) IncrByFloat

func (c *Client) IncrByFloat(key string, value float64) *FloatCmd

func (*Client) Info

func (c *Client) Info(section ...string) *StringCmd

func (*Client) Keys

func (c *Client) Keys(pattern string) *StringSliceCmd

func (*Client) LIndex

func (c *Client) LIndex(key string, index int64) *StringCmd

func (*Client) LInsert

func (c *Client) LInsert(key, op string, pivot, value interface{}) *IntCmd

func (*Client) LInsertAfter

func (c *Client) LInsertAfter(key string, pivot, value interface{}) *IntCmd

func (*Client) LInsertBefore

func (c *Client) LInsertBefore(key string, pivot, value interface{}) *IntCmd

func (*Client) LLen

func (c *Client) LLen(key string) *IntCmd

func (*Client) LPop

func (c *Client) LPop(key string) *StringCmd

func (*Client) LPush

func (c *Client) LPush(key string, values ...interface{}) *IntCmd

func (*Client) LPushX

func (c *Client) LPushX(key string, value interface{}) *IntCmd

func (*Client) LRange

func (c *Client) LRange(key string, start, stop int64) *StringSliceCmd

func (*Client) LRem

func (c *Client) LRem(key string, count int64, value interface{}) *IntCmd

func (*Client) LSet

func (c *Client) LSet(key string, index int64, value interface{}) *StatusCmd

func (*Client) LTrim

func (c *Client) LTrim(key string, start, stop int64) *StatusCmd

func (*Client) LastSave

func (c *Client) LastSave() *IntCmd

func (*Client) MGet

func (c *Client) MGet(keys ...string) *SliceCmd

func (*Client) MSet

func (c *Client) MSet(pairs ...interface{}) *StatusCmd

func (*Client) MSetNX

func (c *Client) MSetNX(pairs ...interface{}) *BoolCmd

func (*Client) MemoryUsage

func (c *Client) MemoryUsage(key string, samples ...int) *IntCmd

func (*Client) Migrate

func (c *Client) Migrate(host, port, key string, db int64, timeout time.Duration) *StatusCmd

func (*Client) Move

func (c *Client) Move(key string, db int64) *BoolCmd

func (*Client) ObjectEncoding

func (c *Client) ObjectEncoding(key string) *StringCmd

func (*Client) ObjectIdleTime

func (c *Client) ObjectIdleTime(key string) *DurationCmd

func (*Client) ObjectRefCount

func (c *Client) ObjectRefCount(key string) *IntCmd

func (*Client) Options

func (c *Client) Options() *Options

Options returns read-only Options that were used to create the client.

func (*Client) PExpire

func (c *Client) PExpire(key string, expiration time.Duration) *BoolCmd

func (*Client) PExpireAt

func (c *Client) PExpireAt(key string, tm time.Time) *BoolCmd

func (*Client) PFAdd

func (c *Client) PFAdd(key string, els ...interface{}) *IntCmd

func (*Client) PFCount

func (c *Client) PFCount(keys ...string) *IntCmd

func (*Client) PFMerge

func (c *Client) PFMerge(dest string, keys ...string) *StatusCmd

func (*Client) PSubscribe

func (c *Client) PSubscribe(channels ...string) *PubSub

PSubscribe subscribes the client to the given patterns. Patterns can be omitted to create empty subscription.

func (*Client) PTTL

func (c *Client) PTTL(key string) *DurationCmd

func (*Client) Persist

func (c *Client) Persist(key string) *BoolCmd

func (*Client) Ping

func (c *Client) Ping() *StatusCmd

func (*Client) Pipeline

func (c *Client) Pipeline() Pipeliner
Example
package main

import (
	"fmt"
	"time"

	"github.com/go-redis/redis"
)

var redisdb *redis.Client

func main() {
	pipe := redisdb.Pipeline()

	incr := pipe.Incr("pipeline_counter")
	pipe.Expire("pipeline_counter", time.Hour)

	// Execute
	//
	//     INCR pipeline_counter
	//     EXPIRE pipeline_counts 3600
	//
	// using one redisdb-server roundtrip.
	_, err := pipe.Exec()
	fmt.Println(incr.Val(), err)
}
Output:

1 <nil>

func (*Client) Pipelined

func (c *Client) Pipelined(fn func(Pipeliner) error) ([]Cmder, error)
Example
package main

import (
	"fmt"
	"time"

	"github.com/go-redis/redis"
)

var redisdb *redis.Client

func main() {
	var incr *redis.IntCmd
	_, err := redisdb.Pipelined(func(pipe redis.Pipeliner) error {
		incr = pipe.Incr("pipelined_counter")
		pipe.Expire("pipelined_counter", time.Hour)
		return nil
	})
	fmt.Println(incr.Val(), err)
}
Output:

1 <nil>

func (*Client) PoolStats

func (c *Client) PoolStats() *PoolStats

PoolStats returns connection pool stats.

func (*Client) Process

func (c *Client) Process(cmd Cmder) error

func (*Client) PubSubChannels

func (c *Client) PubSubChannels(pattern string) *StringSliceCmd

func (*Client) PubSubNumPat

func (c *Client) PubSubNumPat() *IntCmd

func (*Client) PubSubNumSub

func (c *Client) PubSubNumSub(channels ...string) *StringIntMapCmd

func (*Client) Publish

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

Publish posts the message to the channel.

func (*Client) Quit

func (c *Client) Quit() *StatusCmd

func (*Client) RPop

func (c *Client) RPop(key string) *StringCmd

func (*Client) RPopLPush

func (c *Client) RPopLPush(source, destination string) *StringCmd

func (*Client) RPush

func (c *Client) RPush(key string, values ...interface{}) *IntCmd

func (*Client) RPushX

func (c *Client) RPushX(key string, value interface{}) *IntCmd

func (*Client) RandomKey

func (c *Client) RandomKey() *StringCmd

func (*Client) ReadOnly

func (c *Client) ReadOnly() *StatusCmd

func (*Client) ReadWrite

func (c *Client) ReadWrite() *StatusCmd

func (*Client) Rename

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

func (*Client) RenameNX

func (c *Client) RenameNX(key, newkey string) *BoolCmd

func (*Client) Restore

func (c *Client) Restore(key string, ttl time.Duration, value string) *StatusCmd

func (*Client) RestoreReplace

func (c *Client) RestoreReplace(key string, ttl time.Duration, value string) *StatusCmd

func (*Client) SAdd

func (c *Client) SAdd(key string, members ...interface{}) *IntCmd

func (*Client) SCard

func (c *Client) SCard(key string) *IntCmd

func (*Client) SDiff

func (c *Client) SDiff(keys ...string) *StringSliceCmd

func (*Client) SDiffStore

func (c *Client) SDiffStore(destination string, keys ...string) *IntCmd

func (*Client) SInter

func (c *Client) SInter(keys ...string) *StringSliceCmd

func (*Client) SInterStore

func (c *Client) SInterStore(destination string, keys ...string) *IntCmd

func (*Client) SIsMember

func (c *Client) SIsMember(key string, member interface{}) *BoolCmd

func (*Client) SMembers

func (c *Client) SMembers(key string) *StringSliceCmd

Redis `SMEMBERS key` command output as a slice

func (*Client) SMembersMap

func (c *Client) SMembersMap(key string) *StringStructMapCmd

Redis `SMEMBERS key` command output as a map

func (*Client) SMove

func (c *Client) SMove(source, destination string, member interface{}) *BoolCmd

func (*Client) SPop

func (c *Client) SPop(key string) *StringCmd

Redis `SPOP key` command.

func (*Client) SPopN

func (c *Client) SPopN(key string, count int64) *StringSliceCmd

Redis `SPOP key count` command.

func (*Client) SRandMember

func (c *Client) SRandMember(key string) *StringCmd

Redis `SRANDMEMBER key` command.

func (*Client) SRandMemberN

func (c *Client) SRandMemberN(key string, count int64) *StringSliceCmd

Redis `SRANDMEMBER key count` command.

func (*Client) SRem

func (c *Client) SRem(key string, members ...interface{}) *IntCmd

func (*Client) SScan

func (c *Client) SScan(key string, cursor uint64, match string, count int64) *ScanCmd

func (*Client) SUnion

func (c *Client) SUnion(keys ...string) *StringSliceCmd

func (*Client) SUnionStore

func (c *Client) SUnionStore(destination string, keys ...string) *IntCmd

func (*Client) Save

func (c *Client) Save() *StatusCmd

func (*Client) Scan

func (c *Client) Scan(cursor uint64, match string, count int64) *ScanCmd
Example
package main

import (
	"fmt"

	"github.com/go-redis/redis"
)

var redisdb *redis.Client

func main() {
	redisdb.FlushDB()
	for i := 0; i < 33; i++ {
		err := redisdb.Set(fmt.Sprintf("key%d", i), "value", 0).Err()
		if err != nil {
			panic(err)
		}
	}

	var cursor uint64
	var n int
	for {
		var keys []string
		var err error
		keys, cursor, err = redisdb.Scan(cursor, "key*", 10).Result()
		if err != nil {
			panic(err)
		}
		n += len(keys)
		if cursor == 0 {
			break
		}
	}

	fmt.Printf("found %d keys\n", n)
}
Output:

found 33 keys

func (*Client) ScriptExists

func (c *Client) ScriptExists(hashes ...string) *BoolSliceCmd

func (*Client) ScriptFlush

func (c *Client) ScriptFlush() *StatusCmd

func (*Client) ScriptKill

func (c *Client) ScriptKill() *StatusCmd

func (*Client) ScriptLoad

func (c *Client) ScriptLoad(script string) *StringCmd

func (*Client) Set

func (c *Client) Set(key string, value interface{}, expiration time.Duration) *StatusCmd

Redis `SET key value [expiration]` command.

Use expiration for `SETEX`-like behavior. Zero expiration means the key has no expiration time.

Example
package main

import (
	"time"

	"github.com/go-redis/redis"
)

var redisdb *redis.Client

func main() {
	// Last argument is expiration. Zero means the key has no
	// expiration time.
	err := redisdb.Set("key", "value", 0).Err()
	if err != nil {
		panic(err)
	}

	// key2 will expire in an hour.
	err = redisdb.Set("key2", "value", time.Hour).Err()
	if err != nil {
		panic(err)
	}
}
Output:

func (*Client) SetBit

func (c *Client) SetBit(key string, offset int64, value int) *IntCmd

func (*Client) SetLimiter

func (c *Client) SetLimiter(l Limiter) *Client

func (*Client) SetNX

func (c *Client) SetNX(key string, value interface{}, expiration time.Duration) *BoolCmd

Redis `SET key value [expiration] NX` command.

Zero expiration means the key has no expiration time.

func (*Client) SetRange

func (c *Client) SetRange(key string, offset int64, value string) *IntCmd

func (*Client) SetXX

func (c *Client) SetXX(key string, value interface{}, expiration time.Duration) *BoolCmd

Redis `SET key value [expiration] XX` command.

Zero expiration means the key has no expiration time.

func (*Client) Shutdown

func (c *Client) Shutdown() *StatusCmd

func (*Client) ShutdownNoSave

func (c *Client) ShutdownNoSave() *StatusCmd

func (*Client) ShutdownSave

func (c *Client) ShutdownSave() *StatusCmd

func (*Client) SlaveOf

func (c *Client) SlaveOf(host, port string) *StatusCmd

func (*Client) SlowLog

func (c *Client) SlowLog()

func (*Client) Sort

func (c *Client) Sort(key string, sort *Sort) *StringSliceCmd

func (*Client) SortInterfaces

func (c *Client) SortInterfaces(key string, sort *Sort) *SliceCmd

func (*Client) SortStore

func (c *Client) SortStore(key, store string, sort *Sort) *IntCmd

func (*Client) StrLen

func (c *Client) StrLen(key string) *IntCmd

func (*Client) String

func (c *Client) String() string

func (*Client) Subscribe

func (c *Client) Subscribe(channels ...string) *PubSub

Subscribe subscribes the client to the specified channels. Channels can be omitted to create empty subscription. Note that this method does not wait on a response from Redis, so the subscription may not be active immediately. To force the connection to wait, you may call the Receive() method on the returned *PubSub like so:

sub := client.Subscribe(queryResp)
iface, err := sub.Receive()
if err != nil {
    // handle error
}

// Should be *Subscription, but others are possible if other actions have been
// taken on sub since it was created.
switch iface.(type) {
case *Subscription:
    // subscribe succeeded
case *Message:
    // received first message
case *Pong:
    // pong received
default:
    // handle error
}

ch := sub.Channel()

func (*Client) Sync

func (c *Client) Sync()

func (*Client) TTL

func (c *Client) TTL(key string) *DurationCmd

func (*Client) Time

func (c *Client) Time() *TimeCmd

func (*Client) Touch

func (c *Client) Touch(keys ...string) *IntCmd

func (*Client) TxPipeline

func (c *Client) TxPipeline() Pipeliner

TxPipeline acts like Pipeline, but wraps queued commands with MULTI/EXEC.

Example
package main

import (
	"fmt"
	"time"

	"github.com/go-redis/redis"
)

var redisdb *redis.Client

func main() {
	pipe := redisdb.TxPipeline()

	incr := pipe.Incr("tx_pipeline_counter")
	pipe.Expire("tx_pipeline_counter", time.Hour)

	// Execute
	//
	//     MULTI
	//     INCR pipeline_counter
	//     EXPIRE pipeline_counts 3600
	//     EXEC
	//
	// using one redisdb-server roundtrip.
	_, err := pipe.Exec()
	fmt.Println(incr.Val(), err)
}
Output:

1 <nil>

func (*Client) TxPipelined

func (c *Client) TxPipelined(fn func(Pipeliner) error) ([]Cmder, error)
Example
package main

import (
	"fmt"
	"time"

	"github.com/go-redis/redis"
)

var redisdb *redis.Client

func main() {
	var incr *redis.IntCmd
	_, err := redisdb.TxPipelined(func(pipe redis.Pipeliner) error {
		incr = pipe.Incr("tx_pipelined_counter")
		pipe.Expire("tx_pipelined_counter", time.Hour)
		return nil
	})
	fmt.Println(incr.Val(), err)
}
Output:

1 <nil>

func (*Client) Type

func (c *Client) Type(key string) *StatusCmd
func (c *Client) Unlink(keys ...string) *IntCmd

func (*Client) Wait

func (c *Client) Wait(numSlaves int, timeout time.Duration) *IntCmd

func (*Client) Watch

func (c *Client) Watch(fn func(*Tx) error, keys ...string) error

Watch prepares a transaction and marks the keys to be watched for conditional execution if there are any keys.

The transaction is automatically closed when fn exits.

Example
package main

import (
	"errors"
	"fmt"
	"sync"
	"time"

	"github.com/go-redis/redis"
)

var redisdb *redis.Client

func init() {
	redisdb = redis.NewClient(&redis.Options{
		Addr:         ":6379",
		DialTimeout:  10 * time.Second,
		ReadTimeout:  30 * time.Second,
		WriteTimeout: 30 * time.Second,
		PoolSize:     10,
		PoolTimeout:  30 * time.Second,
	})
}

func main() {
	const routineCount = 100

	// Transactionally increments key using GET and SET commands.
	increment := func(key string) error {
		txf := func(tx *redis.Tx) error {
			// get current value or zero
			n, err := tx.Get(key).Int()
			if err != nil && err != redis.Nil {
				return err
			}

			// actual opperation (local in optimistic lock)
			n++

			// runs only if the watched keys remain unchanged
			_, err = tx.Pipelined(func(pipe redis.Pipeliner) error {
				// pipe handles the error case
				pipe.Set(key, n, 0)
				return nil
			})
			return err
		}

		for retries := routineCount; retries > 0; retries-- {
			err := redisdb.Watch(txf, key)
			if err != redis.TxFailedErr {
				return err
			}
			// optimistic lock lost
		}
		return errors.New("increment reached maximum number of retries")
	}

	var wg sync.WaitGroup
	wg.Add(routineCount)
	for i := 0; i < routineCount; i++ {
		go func() {
			defer wg.Done()

			if err := increment("counter3"); err != nil {
				fmt.Println("increment error:", err)
			}
		}()
	}
	wg.Wait()

	n, err := redisdb.Get("counter3").Int()
	fmt.Println("ended with", n, err)
}
Output:

ended with 100 <nil>

func (*Client) WithContext

func (c *Client) WithContext(ctx context.Context) *Client

func (*Client) WrapProcess

func (c *Client) WrapProcess(
	fn func(oldProcess func(cmd Cmder) error) func(cmd Cmder) error,
)

WrapProcess wraps function that processes Redis commands.

func (*Client) WrapProcessPipeline

func (c *Client) WrapProcessPipeline(
	fn func(oldProcess func([]Cmder) error) func([]Cmder) error,
)

func (*Client) XAck

func (c *Client) XAck(stream, group string, ids ...string) *IntCmd

func (*Client) XAdd

func (c *Client) XAdd(a *XAddArgs) *StringCmd

func (*Client) XClaim

func (c *Client) XClaim(a *XClaimArgs) *XMessageSliceCmd

func (*Client) XClaimJustID

func (c *Client) XClaimJustID(a *XClaimArgs) *StringSliceCmd

func (*Client) XDel

func (c *Client) XDel(stream string, ids ...string) *IntCmd

func (*Client) XGroupCreate

func (c *Client) XGroupCreate(stream, group, start string) *StatusCmd

func (*Client) XGroupCreateMkStream

func (c *Client) XGroupCreateMkStream(stream, group, start string) *StatusCmd

func (*Client) XGroupDelConsumer

func (c *Client) XGroupDelConsumer(stream, group, consumer string) *IntCmd

func (*Client) XGroupDestroy

func (c *Client) XGroupDestroy(stream, group string) *IntCmd

func (*Client) XGroupSetID

func (c *Client) XGroupSetID(stream, group, start string) *StatusCmd

func (*Client) XLen

func (c *Client) XLen(stream string) *IntCmd

func (*Client) XPending

func (c *Client) XPending(stream, group string) *XPendingCmd

func (*Client) XPendingExt

func (c *Client) XPendingExt(a *XPendingExtArgs) *XPendingExtCmd

func (*Client) XRange

func (c *Client) XRange(stream, start, stop string) *XMessageSliceCmd

func (*Client) XRangeN

func (c *Client) XRangeN(stream, start, stop string, count int64) *XMessageSliceCmd

func (*Client) XRead

func (c *Client) XRead(a *XReadArgs) *XStreamSliceCmd

func (*Client) XReadGroup

func (c *Client) XReadGroup(a *XReadGroupArgs) *XStreamSliceCmd

func (*Client) XReadStreams

func (c *Client) XReadStreams(streams ...string) *XStreamSliceCmd

func (*Client) XRevRange

func (c *Client) XRevRange(stream, start, stop string) *XMessageSliceCmd

func (*Client) XRevRangeN

func (c *Client) XRevRangeN(stream, start, stop string, count int64) *XMessageSliceCmd

func (*Client) XTrim

func (c *Client) XTrim(key string, maxLen int64) *IntCmd

func (*Client) XTrimApprox

func (c *Client) XTrimApprox(key string, maxLen int64) *IntCmd

func (*Client) ZAdd

func (c *Client) ZAdd(key string, members ...Z) *IntCmd

Redis `ZADD key score member [score member ...]` command.

func (*Client) ZAddCh

func (c *Client) ZAddCh(key string, members ...Z) *IntCmd

Redis `ZADD key CH score member [score member ...]` command.

func (*Client) ZAddNX

func (c *Client) ZAddNX(key string, members ...Z) *IntCmd

Redis `ZADD key NX score member [score member ...]` command.

func (*Client) ZAddNXCh

func (c *Client) ZAddNXCh(key string, members ...Z) *IntCmd

Redis `ZADD key NX CH score member [score member ...]` command.

func (*Client) ZAddXX

func (c *Client) ZAddXX(key string, members ...Z) *IntCmd

Redis `ZADD key XX score member [score member ...]` command.

func (*Client) ZAddXXCh

func (c *Client) ZAddXXCh(key string, members ...Z) *IntCmd

Redis `ZADD key XX CH score member [score member ...]` command.

func (*Client) ZCard

func (c *Client) ZCard(key string) *IntCmd

func (*Client) ZCount

func (c *Client) ZCount(key, min, max string) *IntCmd

func (*Client) ZIncr

func (c *Client) ZIncr(key string, member Z) *FloatCmd

Redis `ZADD key INCR score member` command.

func (*Client) ZIncrBy

func (c *Client) ZIncrBy(key string, increment float64, member string) *FloatCmd

func (*Client) ZIncrNX

func (c *Client) ZIncrNX(key string, member Z) *FloatCmd

Redis `ZADD key NX INCR score member` command.

func (*Client) ZIncrXX

func (c *Client) ZIncrXX(key string, member Z) *FloatCmd

Redis `ZADD key XX INCR score member` command.

func (*Client) ZInterStore

func (c *Client) ZInterStore(destination string, store ZStore, keys ...string) *IntCmd

func (*Client) ZLexCount

func (c *Client) ZLexCount(key, min, max string) *IntCmd

func (*Client) ZPopMax

func (c *Client) ZPopMax(key string, count ...int64) *ZSliceCmd

func (*Client) ZPopMin

func (c *Client) ZPopMin(key string, count ...int64) *ZSliceCmd

func (*Client) ZRange

func (c *Client) ZRange(key string, start, stop int64) *StringSliceCmd

func (*Client) ZRangeByLex

func (c *Client) ZRangeByLex(key string, opt ZRangeBy) *StringSliceCmd

func (*Client) ZRangeByScore

func (c *Client) ZRangeByScore(key string, opt ZRangeBy) *StringSliceCmd

func (*Client) ZRangeByScoreWithScores

func (c *Client) ZRangeByScoreWithScores(key string, opt ZRangeBy) *ZSliceCmd

func (*Client) ZRangeWithScores

func (c *Client) ZRangeWithScores(key string, start, stop int64) *ZSliceCmd

func (*Client) ZRank

func (c *Client) ZRank(key, member string) *IntCmd

func (*Client) ZRem

func (c *Client) ZRem(key string, members ...interface{}) *IntCmd

func (*Client) ZRemRangeByLex

func (c *Client) ZRemRangeByLex(key, min, max string) *IntCmd

func (*Client) ZRemRangeByRank

func (c *Client) ZRemRangeByRank(key string, start, stop int64) *IntCmd

func (*Client) ZRemRangeByScore

func (c *Client) ZRemRangeByScore(key, min, max string) *IntCmd

func (*Client) ZRevRange

func (c *Client) ZRevRange(key string, start, stop int64) *StringSliceCmd

func (*Client) ZRevRangeByLex

func (c *Client) ZRevRangeByLex(key string, opt ZRangeBy) *StringSliceCmd

func (*Client) ZRevRangeByScore

func (c *Client) ZRevRangeByScore(key string, opt ZRangeBy) *StringSliceCmd

func (*Client) ZRevRangeByScoreWithScores

func (c *Client) ZRevRangeByScoreWithScores(key string, opt ZRangeBy) *ZSliceCmd

func (*Client) ZRevRangeWithScores

func (c *Client) ZRevRangeWithScores(key string, start, stop int64) *ZSliceCmd

func (*Client) ZRevRank

func (c *Client) ZRevRank(key, member string) *IntCmd

func (*Client) ZScan

func (c *Client) ZScan(key string, cursor uint64, match string, count int64) *ScanCmd

func (*Client) ZScore

func (c *Client) ZScore(key, member string) *FloatCmd

func (*Client) ZUnionStore

func (c *Client) ZUnionStore(dest string, store ZStore, keys ...string) *IntCmd

type ClusterClient

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

ClusterClient is a Redis Cluster client representing a pool of zero or more underlying connections. It's safe for concurrent use by multiple goroutines.

func NewClusterClient

func NewClusterClient(opt *ClusterOptions) *ClusterClient

NewClusterClient returns a Redis Cluster client as described in http://redis.io/topics/cluster-spec.

Example
package main

import (
	"github.com/go-redis/redis"
)

func main() {
	// See http://redis.io/topics/cluster-tutorial for instructions
	// how to setup Redis Cluster.
	redisdb := redis.NewClusterClient(&redis.ClusterOptions{
		Addrs: []string{":7000", ":7001", ":7002", ":7003", ":7004", ":7005"},
	})
	redisdb.Ping()
}
Output:

Example (ManualSetup)

Following example creates a cluster from 2 master nodes and 2 slave nodes without using cluster mode or Redis Sentinel.

package main

import (
	"github.com/go-redis/redis"
)

func main() {
	// clusterSlots returns cluster slots information.
	// It can use service like ZooKeeper to maintain configuration information
	// and Cluster.ReloadState to manually trigger state reloading.
	clusterSlots := func() ([]redis.ClusterSlot, error) {
		slots := []redis.ClusterSlot{
			// First node with 1 master and 1 slave.
			{
				Start: 0,
				End:   8191,
				Nodes: []redis.ClusterNode{{
					Addr: ":7000", // master
				}, {
					Addr: ":8000", // 1st slave
				}},
			},
			// Second node with 1 master and 1 slave.
			{
				Start: 8192,
				End:   16383,
				Nodes: []redis.ClusterNode{{
					Addr: ":7001", // master
				}, {
					Addr: ":8001", // 1st slave
				}},
			},
		}
		return slots, nil
	}

	redisdb := redis.NewClusterClient(&redis.ClusterOptions{
		ClusterSlots:  clusterSlots,
		RouteRandomly: true,
	})
	redisdb.Ping()

	// ReloadState reloads cluster state. It calls ClusterSlots func
	// to get cluster slots information.
	err := redisdb.ReloadState()
	if err != nil {
		panic(err)
	}
}
Output:

func (*ClusterClient) Append

func (c *ClusterClient) Append(key, value string) *IntCmd

func (*ClusterClient) BLPop

func (c *ClusterClient) BLPop(timeout time.Duration, keys ...string) *StringSliceCmd

func (*ClusterClient) BRPop

func (c *ClusterClient) BRPop(timeout time.Duration, keys ...string) *StringSliceCmd

func (*ClusterClient) BRPopLPush

func (c *ClusterClient) BRPopLPush(source, destination string, timeout time.Duration) *StringCmd

func (*ClusterClient) BZPopMax

func (c *ClusterClient) BZPopMax(timeout time.Duration, keys ...string) *ZWithKeyCmd

Redis `BZPOPMAX key [key ...] timeout` command.

func (*ClusterClient) BZPopMin

func (c *ClusterClient) BZPopMin(timeout time.Duration, keys ...string) *ZWithKeyCmd

Redis `BZPOPMIN key [key ...] timeout` command.

func (*ClusterClient) BgRewriteAOF

func (c *ClusterClient) BgRewriteAOF() *StatusCmd

func (*ClusterClient) BgSave

func (c *ClusterClient) BgSave() *StatusCmd

func (*ClusterClient) BitCount

func (c *ClusterClient) BitCount(key string, bitCount *BitCount) *IntCmd

func (*ClusterClient) BitOpAnd

func (c *ClusterClient) BitOpAnd(destKey string, keys ...string) *IntCmd

func (*ClusterClient) BitOpNot

func (c *ClusterClient) BitOpNot(destKey string, key string) *IntCmd

func (*ClusterClient) BitOpOr

func (c *ClusterClient) BitOpOr(destKey string, keys ...string) *IntCmd

func (*ClusterClient) BitOpXor

func (c *ClusterClient) BitOpXor(destKey string, keys ...string) *IntCmd

func (*ClusterClient) BitPos

func (c *ClusterClient) BitPos(key string, bit int64, pos ...int64) *IntCmd

func (*ClusterClient) ClientGetName

func (c *ClusterClient) ClientGetName() *StringCmd

ClientGetName returns the name of the connection.

func (*ClusterClient) ClientID

func (c *ClusterClient) ClientID() *IntCmd

func (*ClusterClient) ClientKill

func (c *ClusterClient) ClientKill(ipPort string) *StatusCmd

func (*ClusterClient) ClientKillByFilter

func (c *ClusterClient) ClientKillByFilter(keys ...string) *IntCmd

ClientKillByFilter is new style synx, while the ClientKill is old CLIENT KILL <option> [value] ... <option> [value]

func (*ClusterClient) ClientList

func (c *ClusterClient) ClientList() *StringCmd

func (*ClusterClient) ClientPause

func (c *ClusterClient) ClientPause(dur time.Duration) *BoolCmd

func (*ClusterClient) ClientUnblock

func (c *ClusterClient) ClientUnblock(id int64) *IntCmd

func (*ClusterClient) ClientUnblockWithError

func (c *ClusterClient) ClientUnblockWithError(id int64) *IntCmd

func (*ClusterClient) Close

func (c *ClusterClient) Close() error

Close closes the cluster client, releasing any open resources.

It is rare to Close a ClusterClient, as the ClusterClient is meant to be long-lived and shared between many goroutines.

func (*ClusterClient) ClusterAddSlots

func (c *ClusterClient) ClusterAddSlots(slots ...int) *StatusCmd

func (*ClusterClient) ClusterAddSlotsRange

func (c *ClusterClient) ClusterAddSlotsRange(min, max int) *StatusCmd

func (*ClusterClient) ClusterCountFailureReports

func (c *ClusterClient) ClusterCountFailureReports(nodeID string) *IntCmd

func (*ClusterClient) ClusterCountKeysInSlot

func (c *ClusterClient) ClusterCountKeysInSlot(slot int) *IntCmd

func (*ClusterClient) ClusterDelSlots

func (c *ClusterClient) ClusterDelSlots(slots ...int) *StatusCmd

func (*ClusterClient) ClusterDelSlotsRange

func (c *ClusterClient) ClusterDelSlotsRange(min, max int) *StatusCmd

func (*ClusterClient) ClusterFailover

func (c *ClusterClient) ClusterFailover() *StatusCmd

func (*ClusterClient) ClusterForget

func (c *ClusterClient) ClusterForget(nodeID string) *StatusCmd

func (*ClusterClient) ClusterGetKeysInSlot

func (c *ClusterClient) ClusterGetKeysInSlot(slot int, count int) *StringSliceCmd

func (*ClusterClient) ClusterInfo

func (c *ClusterClient) ClusterInfo() *StringCmd

func (*ClusterClient) ClusterKeySlot

func (c *ClusterClient) ClusterKeySlot(key string) *IntCmd

func (*ClusterClient) ClusterMeet

func (c *ClusterClient) ClusterMeet(host, port string) *StatusCmd

func (*ClusterClient) ClusterNodes

func (c *ClusterClient) ClusterNodes() *StringCmd

func (*ClusterClient) ClusterReplicate

func (c *ClusterClient) ClusterReplicate(nodeID string) *StatusCmd

func (*ClusterClient) ClusterResetHard

func (c *ClusterClient) ClusterResetHard() *StatusCmd

func (*ClusterClient) ClusterResetSoft

func (c *ClusterClient) ClusterResetSoft() *StatusCmd

func (*ClusterClient) ClusterSaveConfig

func (c *ClusterClient) ClusterSaveConfig() *StatusCmd

func (*ClusterClient) ClusterSlaves

func (c *ClusterClient) ClusterSlaves(nodeID string) *StringSliceCmd

func (*ClusterClient) ClusterSlots

func (c *ClusterClient) ClusterSlots() *ClusterSlotsCmd

func (*ClusterClient) Command

func (c *ClusterClient) Command() *CommandsInfoCmd

func (*ClusterClient) ConfigGet

func (c *ClusterClient) ConfigGet(parameter string) *SliceCmd

func (*ClusterClient) ConfigResetStat

func (c *ClusterClient) ConfigResetStat() *StatusCmd

func (*ClusterClient) ConfigRewrite

func (c *ClusterClient) ConfigRewrite() *StatusCmd

func (*ClusterClient) ConfigSet

func (c *ClusterClient) ConfigSet(parameter, value string) *StatusCmd

func (*ClusterClient) Context

func (c *ClusterClient) Context() context.Context

func (*ClusterClient) DBSize

func (c *ClusterClient) DBSize() *IntCmd

func (*ClusterClient) DbSize

func (c *ClusterClient) DbSize() *IntCmd

Deperecated. Use DBSize instead.

func (*ClusterClient) DebugObject

func (c *ClusterClient) DebugObject(key string) *StringCmd

func (*ClusterClient) Decr

func (c *ClusterClient) Decr(key string) *IntCmd

func (*ClusterClient) DecrBy

func (c *ClusterClient) DecrBy(key string, decrement int64) *IntCmd

func (*ClusterClient) Del

func (c *ClusterClient) Del(keys ...string) *IntCmd

func (*ClusterClient) Do

func (c *ClusterClient) Do(args ...interface{}) *Cmd

Do creates a Cmd from the args and processes the cmd.

func (*ClusterClient) Dump

func (c *ClusterClient) Dump(key string) *StringCmd

func (*ClusterClient) Echo

func (c *ClusterClient) Echo(message interface{}) *StringCmd

func (*ClusterClient) Eval

func (c *ClusterClient) Eval(script string, keys []string, args ...interface{}) *Cmd

func (*ClusterClient) EvalSha

func (c *ClusterClient) EvalSha(sha1 string, keys []string, args ...interface{}) *Cmd

func (*ClusterClient) Exists

func (c *ClusterClient) Exists(keys ...string) *IntCmd

func (*ClusterClient) Expire

func (c *ClusterClient) Expire(key string, expiration time.Duration) *BoolCmd

func (*ClusterClient) ExpireAt

func (c *ClusterClient) ExpireAt(key string, tm time.Time) *BoolCmd

func (*ClusterClient) FlushAll

func (c *ClusterClient) FlushAll() *StatusCmd

func (*ClusterClient) FlushAllAsync

func (c *ClusterClient) FlushAllAsync() *StatusCmd

func (*ClusterClient) FlushDB

func (c *ClusterClient) FlushDB() *StatusCmd

func (*ClusterClient) FlushDBAsync

func (c *ClusterClient) FlushDBAsync() *StatusCmd

func (*ClusterClient) FlushDb

func (c *ClusterClient) FlushDb() *StatusCmd

Deprecated. Use FlushDB instead.

func (*ClusterClient) ForEachMaster

func (c *ClusterClient) ForEachMaster(fn func(client *Client) error) error

ForEachMaster concurrently calls the fn on each master node in the cluster. It returns the first error if any.

func (*ClusterClient) ForEachNode

func (c *ClusterClient) ForEachNode(fn func(client *Client) error) error

ForEachNode concurrently calls the fn on each known node in the cluster. It returns the first error if any.

func (*ClusterClient) ForEachSlave

func (c *ClusterClient) ForEachSlave(fn func(client *Client) error) error

ForEachSlave concurrently calls the fn on each slave node in the cluster. It returns the first error if any.

func (*ClusterClient) GeoAdd

func (c *ClusterClient) GeoAdd(key string, geoLocation ...*GeoLocation) *IntCmd

func (*ClusterClient) GeoDist

func (c *ClusterClient) GeoDist(key string, member1, member2, unit string) *FloatCmd

func (*ClusterClient) GeoHash

func (c *ClusterClient) GeoHash(key string, members ...string) *StringSliceCmd

func (*ClusterClient) GeoPos

func (c *ClusterClient) GeoPos(key string, members ...string) *GeoPosCmd

func (*ClusterClient) GeoRadius

func (c *ClusterClient) GeoRadius(key string, longitude, latitude float64, query *GeoRadiusQuery) *GeoLocationCmd

func (*ClusterClient) GeoRadiusByMember

func (c *ClusterClient) GeoRadiusByMember(key, member string, query *GeoRadiusQuery) *GeoLocationCmd

func (*ClusterClient) GeoRadiusByMemberRO

func (c *ClusterClient) GeoRadiusByMemberRO(key, member string, query *GeoRadiusQuery) *GeoLocationCmd

func (*ClusterClient) GeoRadiusRO

func (c *ClusterClient) GeoRadiusRO(key string, longitude, latitude float64, query *GeoRadiusQuery) *GeoLocationCmd

func (*ClusterClient) Get

func (c *ClusterClient) Get(key string) *StringCmd

Redis `GET key` command. It returns redis.Nil error when key does not exist.

func (*ClusterClient) GetBit

func (c *ClusterClient) GetBit(key string, offset int64) *IntCmd

func (*ClusterClient) GetRange

func (c *ClusterClient) GetRange(key string, start, end int64) *StringCmd

func (*ClusterClient) GetSet

func (c *ClusterClient) GetSet(key string, value interface{}) *StringCmd

func (*ClusterClient) HDel

func (c *ClusterClient) HDel(key string, fields ...string) *IntCmd

func (*ClusterClient) HExists

func (c *ClusterClient) HExists(key, field string) *BoolCmd

func (*ClusterClient) HGet

func (c *ClusterClient) HGet(key, field string) *StringCmd

func (*ClusterClient) HGetAll

func (c *ClusterClient) HGetAll(key string) *StringStringMapCmd

func (*ClusterClient) HIncrBy

func (c *ClusterClient) HIncrBy(key, field string, incr int64) *IntCmd

func (*ClusterClient) HIncrByFloat

func (c *ClusterClient) HIncrByFloat(key, field string, incr float64) *FloatCmd

func (*ClusterClient) HKeys

func (c *ClusterClient) HKeys(key string) *StringSliceCmd

func (*ClusterClient) HLen

func (c *ClusterClient) HLen(key string) *IntCmd

func (*ClusterClient) HMGet

func (c *ClusterClient) HMGet(key string, fields ...string) *SliceCmd

func (*ClusterClient) HMSet

func (c *ClusterClient) HMSet(key string, fields map[string]interface{}) *StatusCmd

func (*ClusterClient) HScan

func (c *ClusterClient) HScan(key string, cursor uint64, match string, count int64) *ScanCmd

func (*ClusterClient) HSet

func (c *ClusterClient) HSet(key, field string, value interface{}) *BoolCmd

func (*ClusterClient) HSetNX

func (c *ClusterClient) HSetNX(key, field string, value interface{}) *BoolCmd

func (*ClusterClient) HVals

func (c *ClusterClient) HVals(key string) *StringSliceCmd

func (*ClusterClient) Incr

func (c *ClusterClient) Incr(key string) *IntCmd

func (*ClusterClient) IncrBy

func (c *ClusterClient) IncrBy(key string, value int64) *IntCmd

func (*ClusterClient) IncrByFloat

func (c *ClusterClient) IncrByFloat(key string, value float64) *FloatCmd

func (*ClusterClient) Info

func (c *ClusterClient) Info(section ...string) *StringCmd

func (*ClusterClient) Keys

func (c *ClusterClient) Keys(pattern string) *StringSliceCmd

func (*ClusterClient) LIndex

func (c *ClusterClient) LIndex(key string, index int64) *StringCmd

func (*ClusterClient) LInsert

func (c *ClusterClient) LInsert(key, op string, pivot, value interface{}) *IntCmd

func (*ClusterClient) LInsertAfter

func (c *ClusterClient) LInsertAfter(key string, pivot, value interface{}) *IntCmd

func (*ClusterClient) LInsertBefore

func (c *ClusterClient) LInsertBefore(key string, pivot, value interface{}) *IntCmd

func (*ClusterClient) LLen

func (c *ClusterClient) LLen(key string) *IntCmd

func (*ClusterClient) LPop

func (c *ClusterClient) LPop(key string) *StringCmd

func (*ClusterClient) LPush

func (c *ClusterClient) LPush(key string, values ...interface{}) *IntCmd

func (*ClusterClient) LPushX

func (c *ClusterClient) LPushX(key string, value interface{}) *IntCmd

func (*ClusterClient) LRange

func (c *ClusterClient) LRange(key string, start, stop int64) *StringSliceCmd

func (*ClusterClient) LRem

func (c *ClusterClient) LRem(key string, count int64, value interface{}) *IntCmd

func (*ClusterClient) LSet

func (c *ClusterClient) LSet(key string, index int64, value interface{}) *StatusCmd

func (*ClusterClient) LTrim

func (c *ClusterClient) LTrim(key string, start, stop int64) *StatusCmd

func (*ClusterClient) LastSave

func (c *ClusterClient) LastSave() *IntCmd

func (*ClusterClient) MGet

func (c *ClusterClient) MGet(keys ...string) *SliceCmd

func (*ClusterClient) MSet

func (c *ClusterClient) MSet(pairs ...interface{}) *StatusCmd

func (*ClusterClient) MSetNX

func (c *ClusterClient) MSetNX(pairs ...interface{}) *BoolCmd

func (*ClusterClient) MemoryUsage

func (c *ClusterClient) MemoryUsage(key string, samples ...int) *IntCmd

func (*ClusterClient) Migrate

func (c *ClusterClient) Migrate(host, port, key string, db int64, timeout time.Duration) *StatusCmd

func (*ClusterClient) Move

func (c *ClusterClient) Move(key string, db int64) *BoolCmd

func (*ClusterClient) ObjectEncoding

func (c *ClusterClient) ObjectEncoding(key string) *StringCmd

func (*ClusterClient) ObjectIdleTime

func (c *ClusterClient) ObjectIdleTime(key string) *DurationCmd

func (*ClusterClient) ObjectRefCount

func (c *ClusterClient) ObjectRefCount(key string) *IntCmd

func (*ClusterClient) Options

func (c *ClusterClient) Options() *ClusterOptions

Options returns read-only Options that were used to create the client.

func (*ClusterClient) PExpire

func (c *ClusterClient) PExpire(key string, expiration time.Duration) *BoolCmd

func (*ClusterClient) PExpireAt

func (c *ClusterClient) PExpireAt(key string, tm time.Time) *BoolCmd

func (*ClusterClient) PFAdd

func (c *ClusterClient) PFAdd(key string, els ...interface{}) *IntCmd

func (*ClusterClient) PFCount

func (c *ClusterClient) PFCount(keys ...string) *IntCmd

func (*ClusterClient) PFMerge

func (c *ClusterClient) PFMerge(dest string, keys ...string) *StatusCmd

func (*ClusterClient) PSubscribe

func (c *ClusterClient) PSubscribe(channels ...string) *PubSub

PSubscribe subscribes the client to the given patterns. Patterns can be omitted to create empty subscription.

func (*ClusterClient) PTTL

func (c *ClusterClient) PTTL(key string) *DurationCmd

func (*ClusterClient) Persist

func (c *ClusterClient) Persist(key string) *BoolCmd

func (*ClusterClient) Ping

func (c *ClusterClient) Ping() *StatusCmd

func (*ClusterClient) Pipeline

func (c *ClusterClient) Pipeline() Pipeliner

func (*ClusterClient) Pipelined

func (c *ClusterClient) Pipelined(fn func(Pipeliner) error) ([]Cmder, error)

func (*ClusterClient) PoolStats

func (c *ClusterClient) PoolStats() *PoolStats

PoolStats returns accumulated connection pool stats.

func (*ClusterClient) Process

func (c *ClusterClient) Process(cmd Cmder) error

func (*ClusterClient) PubSubChannels

func (c *ClusterClient) PubSubChannels(pattern string) *StringSliceCmd

func (*ClusterClient) PubSubNumPat

func (c *ClusterClient) PubSubNumPat() *IntCmd

func (*ClusterClient) PubSubNumSub

func (c *ClusterClient) PubSubNumSub(channels ...string) *StringIntMapCmd

func (*ClusterClient) Publish

func (c *ClusterClient) Publish(channel string, message interface{}) *IntCmd

Publish posts the message to the channel.

func (*ClusterClient) Quit

func (c *ClusterClient) Quit() *StatusCmd

func (*ClusterClient) RPop

func (c *ClusterClient) RPop(key string) *StringCmd

func (*ClusterClient) RPopLPush

func (c *ClusterClient) RPopLPush(source, destination string) *StringCmd

func (*ClusterClient) RPush

func (c *ClusterClient) RPush(key string, values ...interface{}) *IntCmd

func (*ClusterClient) RPushX

func (c *ClusterClient) RPushX(key string, value interface{}) *IntCmd

func (*ClusterClient) RandomKey

func (c *ClusterClient) RandomKey() *StringCmd

func (*ClusterClient) ReadOnly

func (c *ClusterClient) ReadOnly() *StatusCmd

func (*ClusterClient) ReadWrite

func (c *ClusterClient) ReadWrite() *StatusCmd

func (*ClusterClient) ReloadState

func (c *ClusterClient) ReloadState() error

ReloadState reloads cluster state. If available it calls ClusterSlots func to get cluster slots information.

func (*ClusterClient) Rename

func (c *ClusterClient) Rename(key, newkey string) *StatusCmd

func (*ClusterClient) RenameNX

func (c *ClusterClient) RenameNX(key, newkey string) *BoolCmd

func (*ClusterClient) Restore

func (c *ClusterClient) Restore(key string, ttl time.Duration, value string) *StatusCmd

func (*ClusterClient) RestoreReplace

func (c *ClusterClient) RestoreReplace(key string, ttl time.Duration, value string) *StatusCmd

func (*ClusterClient) SAdd

func (c *ClusterClient) SAdd(key string, members ...interface{}) *IntCmd

func (*ClusterClient) SCard

func (c *ClusterClient) SCard(key string) *IntCmd

func (*ClusterClient) SDiff

func (c *ClusterClient) SDiff(keys ...string) *StringSliceCmd

func (*ClusterClient) SDiffStore

func (c *ClusterClient) SDiffStore(destination string, keys ...string) *IntCmd

func (*ClusterClient) SInter

func (c *ClusterClient) SInter(keys ...string) *StringSliceCmd

func (*ClusterClient) SInterStore

func (c *ClusterClient) SInterStore(destination string, keys ...string) *IntCmd

func (*ClusterClient) SIsMember

func (c *ClusterClient) SIsMember(key string, member interface{}) *BoolCmd

func (*ClusterClient) SMembers

func (c *ClusterClient) SMembers(key string) *StringSliceCmd

Redis `SMEMBERS key` command output as a slice

func (*ClusterClient) SMembersMap

func (c *ClusterClient) SMembersMap(key string) *StringStructMapCmd

Redis `SMEMBERS key` command output as a map

func (*ClusterClient) SMove

func (c *ClusterClient) SMove(source, destination string, member interface{}) *BoolCmd

func (*ClusterClient) SPop

func (c *ClusterClient) SPop(key string) *StringCmd

Redis `SPOP key` command.

func (*ClusterClient) SPopN

func (c *ClusterClient) SPopN(key string, count int64) *StringSliceCmd

Redis `SPOP key count` command.

func (*ClusterClient) SRandMember

func (c *ClusterClient) SRandMember(key string) *StringCmd

Redis `SRANDMEMBER key` command.

func (*ClusterClient) SRandMemberN

func (c *ClusterClient) SRandMemberN(key string, count int64) *StringSliceCmd

Redis `SRANDMEMBER key count` command.

func (*ClusterClient) SRem

func (c *ClusterClient) SRem(key string, members ...interface{}) *IntCmd

func (*ClusterClient) SScan

func (c *ClusterClient) SScan(key string, cursor uint64, match string, count int64) *ScanCmd

func (*ClusterClient) SUnion

func (c *ClusterClient) SUnion(keys ...string) *StringSliceCmd

func (*ClusterClient) SUnionStore

func (c *ClusterClient) SUnionStore(destination string, keys ...string) *IntCmd

func (*ClusterClient) Save

func (c *ClusterClient) Save() *StatusCmd

func (*ClusterClient) Scan

func (c *ClusterClient) Scan(cursor uint64, match string, count int64) *ScanCmd

func (*ClusterClient) ScriptExists

func (c *ClusterClient) ScriptExists(hashes ...string) *BoolSliceCmd

func (*ClusterClient) ScriptFlush

func (c *ClusterClient) ScriptFlush() *StatusCmd

func (*ClusterClient) ScriptKill

func (c *ClusterClient) ScriptKill() *StatusCmd

func (*ClusterClient) ScriptLoad

func (c *ClusterClient) ScriptLoad(script string) *StringCmd

func (*ClusterClient) Set

func (c *ClusterClient) Set(key string, value interface{}, expiration time.Duration) *StatusCmd

Redis `SET key value [expiration]` command.

Use expiration for `SETEX`-like behavior. Zero expiration means the key has no expiration time.

func (*ClusterClient) SetBit

func (c *ClusterClient) SetBit(key string, offset int64, value int) *IntCmd

func (*ClusterClient) SetNX

func (c *ClusterClient) SetNX(key string, value interface{}, expiration time.Duration) *BoolCmd

Redis `SET key value [expiration] NX` command.

Zero expiration means the key has no expiration time.

func (*ClusterClient) SetRange

func (c *ClusterClient) SetRange(key string, offset int64, value string) *IntCmd

func (*ClusterClient) SetXX

func (c *ClusterClient) SetXX(key string, value interface{}, expiration time.Duration) *BoolCmd

Redis `SET key value [expiration] XX` command.

Zero expiration means the key has no expiration time.

func (*ClusterClient) Shutdown

func (c *ClusterClient) Shutdown() *StatusCmd

func (*ClusterClient) ShutdownNoSave

func (c *ClusterClient) ShutdownNoSave() *StatusCmd

func (*ClusterClient) ShutdownSave

func (c *ClusterClient) ShutdownSave() *StatusCmd

func (*ClusterClient) SlaveOf

func (c *ClusterClient) SlaveOf(host, port string) *StatusCmd

func (*ClusterClient) SlowLog

func (c *ClusterClient) SlowLog()

func (*ClusterClient) Sort

func (c *ClusterClient) Sort(key string, sort *Sort) *StringSliceCmd

func (*ClusterClient) SortInterfaces

func (c *ClusterClient) SortInterfaces(key string, sort *Sort) *SliceCmd

func (*ClusterClient) SortStore

func (c *ClusterClient) SortStore(key, store string, sort *Sort) *IntCmd

func (*ClusterClient) StrLen

func (c *ClusterClient) StrLen(key string) *IntCmd

func (*ClusterClient) Subscribe

func (c *ClusterClient) Subscribe(channels ...string) *PubSub

Subscribe subscribes the client to the specified channels. Channels can be omitted to create empty subscription.

func (*ClusterClient) Sync

func (c *ClusterClient) Sync()

func (*ClusterClient) TTL

func (c *ClusterClient) TTL(key string) *DurationCmd

func (*ClusterClient) Time

func (c *ClusterClient) Time() *TimeCmd

func (*ClusterClient) Touch

func (c *ClusterClient) Touch(keys ...string) *IntCmd

func (*ClusterClient) TxPipeline

func (c *ClusterClient) TxPipeline() Pipeliner

TxPipeline acts like Pipeline, but wraps queued commands with MULTI/EXEC.

func (*ClusterClient) TxPipelined

func (c *ClusterClient) TxPipelined(fn func(Pipeliner) error) ([]Cmder, error)

func (*ClusterClient) Type

func (c *ClusterClient) Type(key string) *StatusCmd
func (c *ClusterClient) Unlink(keys ...string) *IntCmd

func (*ClusterClient) Wait

func (c *ClusterClient) Wait(numSlaves int, timeout time.Duration) *IntCmd

func (*ClusterClient) Watch

func (c *ClusterClient) Watch(fn func(*Tx) error, keys ...string) error

func (*ClusterClient) WithContext

func (c *ClusterClient) WithContext(ctx context.Context) *ClusterClient

func (*ClusterClient) WrapProcess

func (c *ClusterClient) WrapProcess(
	fn func(oldProcess func(Cmder) error) func(Cmder) error,
)

func (*ClusterClient) WrapProcessPipeline

func (c *ClusterClient) WrapProcessPipeline(
	fn func(oldProcess func([]Cmder) error) func([]Cmder) error,
)

func (*ClusterClient) XAck

func (c *ClusterClient) XAck(stream, group string, ids ...string) *IntCmd

func (*ClusterClient) XAdd

func (c *ClusterClient) XAdd(a *XAddArgs) *StringCmd

func (*ClusterClient) XClaim

func (c *ClusterClient) XClaim(a *XClaimArgs) *XMessageSliceCmd

func (*ClusterClient) XClaimJustID

func (c *ClusterClient) XClaimJustID(a *XClaimArgs) *StringSliceCmd

func (*ClusterClient) XDel

func (c *ClusterClient) XDel(stream string, ids ...string) *IntCmd

func (*ClusterClient) XGroupCreate

func (c *ClusterClient) XGroupCreate(stream, group, start string) *StatusCmd

func (*ClusterClient) XGroupCreateMkStream

func (c *ClusterClient) XGroupCreateMkStream(stream, group, start string) *StatusCmd

func (*ClusterClient) XGroupDelConsumer

func (c *ClusterClient) XGroupDelConsumer(stream, group, consumer string) *IntCmd

func (*ClusterClient) XGroupDestroy

func (c *ClusterClient) XGroupDestroy(stream, group string) *IntCmd

func (*ClusterClient) XGroupSetID

func (c *ClusterClient) XGroupSetID(stream, group, start string) *StatusCmd

func (*ClusterClient) XLen

func (c *ClusterClient) XLen(stream string) *IntCmd

func (*ClusterClient) XPending

func (c *ClusterClient) XPending(stream, group string) *XPendingCmd

func (*ClusterClient) XPendingExt

func (c *ClusterClient) XPendingExt(a *XPendingExtArgs) *XPendingExtCmd

func (*ClusterClient) XRange

func (c *ClusterClient) XRange(stream, start, stop string) *XMessageSliceCmd

func (*ClusterClient) XRangeN

func (c *ClusterClient) XRangeN(stream, start, stop string, count int64) *XMessageSliceCmd

func (*ClusterClient) XRead

func (c *ClusterClient) XRead(a *XReadArgs) *XStreamSliceCmd

func (*ClusterClient) XReadGroup

func (c *ClusterClient) XReadGroup(a *XReadGroupArgs) *XStreamSliceCmd

func (*ClusterClient) XReadStreams

func (c *ClusterClient) XReadStreams(streams ...string) *XStreamSliceCmd

func (*ClusterClient) XRevRange

func (c *ClusterClient) XRevRange(stream, start, stop string) *XMessageSliceCmd

func (*ClusterClient) XRevRangeN

func (c *ClusterClient) XRevRangeN(stream, start, stop string, count int64) *XMessageSliceCmd

func (*ClusterClient) XTrim

func (c *ClusterClient) XTrim(key string, maxLen int64) *IntCmd

func (*ClusterClient) XTrimApprox

func (c *ClusterClient) XTrimApprox(key string, maxLen int64) *IntCmd

func (*ClusterClient) ZAdd

func (c *ClusterClient) ZAdd(key string, members ...Z) *IntCmd

Redis `ZADD key score member [score member ...]` command.

func (*ClusterClient) ZAddCh

func (c *ClusterClient) ZAddCh(key string, members ...Z) *IntCmd

Redis `ZADD key CH score member [score member ...]` command.

func (*ClusterClient) ZAddNX

func (c *ClusterClient) ZAddNX(key string, members ...Z) *IntCmd

Redis `ZADD key NX score member [score member ...]` command.

func (*ClusterClient) ZAddNXCh

func (c *ClusterClient) ZAddNXCh(key string, members ...Z) *IntCmd

Redis `ZADD key NX CH score member [score member ...]` command.

func (*ClusterClient) ZAddXX

func (c *ClusterClient) ZAddXX(key string, members ...Z) *IntCmd

Redis `ZADD key XX score member [score member ...]` command.

func (*ClusterClient) ZAddXXCh

func (c *ClusterClient) ZAddXXCh(key string, members ...Z) *IntCmd

Redis `ZADD key XX CH score member [score member ...]` command.

func (*ClusterClient) ZCard

func (c *ClusterClient) ZCard(key string) *IntCmd

func (*ClusterClient) ZCount

func (c *ClusterClient) ZCount(key, min, max string) *IntCmd

func (*ClusterClient) ZIncr

func (c *ClusterClient) ZIncr(key string, member Z) *FloatCmd

Redis `ZADD key INCR score member` command.

func (*ClusterClient) ZIncrBy

func (c *ClusterClient) ZIncrBy(key string, increment float64, member string) *FloatCmd

func (*ClusterClient) ZIncrNX

func (c *ClusterClient) ZIncrNX(key string, member Z) *FloatCmd

Redis `ZADD key NX INCR score member` command.

func (*ClusterClient) ZIncrXX

func (c *ClusterClient) ZIncrXX(key string, member Z) *FloatCmd

Redis `ZADD key XX INCR score member` command.

func (*ClusterClient) ZInterStore

func (c *ClusterClient) ZInterStore(destination string, store ZStore, keys ...string) *IntCmd

func (*ClusterClient) ZLexCount

func (c *ClusterClient) ZLexCount(key, min, max string) *IntCmd

func (*ClusterClient) ZPopMax

func (c *ClusterClient) ZPopMax(key string, count ...int64) *ZSliceCmd

func (*ClusterClient) ZPopMin

func (c *ClusterClient) ZPopMin(key string, count ...int64) *ZSliceCmd

func (*ClusterClient) ZRange

func (c *ClusterClient) ZRange(key string, start, stop int64) *StringSliceCmd

func (*ClusterClient) ZRangeByLex

func (c *ClusterClient) ZRangeByLex(key string, opt ZRangeBy) *StringSliceCmd

func (*ClusterClient) ZRangeByScore

func (c *ClusterClient) ZRangeByScore(key string, opt ZRangeBy) *StringSliceCmd

func (*ClusterClient) ZRangeByScoreWithScores

func (c *ClusterClient) ZRangeByScoreWithScores(key string, opt ZRangeBy) *ZSliceCmd

func (*ClusterClient) ZRangeWithScores

func (c *ClusterClient) ZRangeWithScores(key string, start, stop int64) *ZSliceCmd

func (*ClusterClient) ZRank

func (c *ClusterClient) ZRank(key, member string) *IntCmd

func (*ClusterClient) ZRem

func (c *ClusterClient) ZRem(key string, members ...interface{}) *IntCmd

func (*ClusterClient) ZRemRangeByLex

func (c *ClusterClient) ZRemRangeByLex(key, min, max string) *IntCmd

func (*ClusterClient) ZRemRangeByRank

func (c *ClusterClient) ZRemRangeByRank(key string, start, stop int64) *IntCmd

func (*ClusterClient) ZRemRangeByScore

func (c *ClusterClient) ZRemRangeByScore(key, min, max string) *IntCmd

func (*ClusterClient) ZRevRange

func (c *ClusterClient) ZRevRange(key string, start, stop int64) *StringSliceCmd

func (*ClusterClient) ZRevRangeByLex

func (c *ClusterClient) ZRevRangeByLex(key string, opt ZRangeBy) *StringSliceCmd

func (*ClusterClient) ZRevRangeByScore

func (c *ClusterClient) ZRevRangeByScore(key string, opt ZRangeBy) *StringSliceCmd

func (*ClusterClient) ZRevRangeByScoreWithScores

func (c *ClusterClient) ZRevRangeByScoreWithScores(key string, opt ZRangeBy) *ZSliceCmd

func (*ClusterClient) ZRevRangeWithScores

func (c *ClusterClient) ZRevRangeWithScores(key string, start, stop int64) *ZSliceCmd

func (*ClusterClient) ZRevRank

func (c *ClusterClient) ZRevRank(key, member string) *IntCmd

func (*ClusterClient) ZScan

func (c *ClusterClient) ZScan(key string, cursor uint64, match string, count int64) *ScanCmd

func (*ClusterClient) ZScore

func (c *ClusterClient) ZScore(key, member string) *FloatCmd

func (*ClusterClient) ZUnionStore

func (c *ClusterClient) ZUnionStore(dest string, store ZStore, keys ...string) *IntCmd

type ClusterNode

type ClusterNode struct {
	Id   string
	Addr string
}

type ClusterOptions

type ClusterOptions struct {
	// A seed list of host:port addresses of cluster nodes.
	Addrs []string

	// The maximum number of retries before giving up. Command is retried
	// on network errors and MOVED/ASK redirects.
	// Default is 8 retries.
	MaxRedirects int

	// Enables read-only commands on slave nodes.
	ReadOnly bool
	// Allows routing read-only commands to the closest master or slave node.
	// It automatically enables ReadOnly.
	RouteByLatency bool
	// Allows routing read-only commands to the random master or slave node.
	// It automatically enables ReadOnly.
	RouteRandomly bool

	// Optional function that returns cluster slots information.
	// It is useful to manually create cluster of standalone Redis servers
	// and load-balance read/write operations between master and slaves.
	// It can use service like ZooKeeper to maintain configuration information
	// and Cluster.ReloadState to manually trigger state reloading.
	ClusterSlots func() ([]ClusterSlot, error)

	// Optional hook that is called when a new node is created.
	OnNewNode func(*Client)

	OnConnect func(*Conn) error

	Password string

	MaxRetries      int
	MinRetryBackoff time.Duration
	MaxRetryBackoff time.Duration

	DialTimeout  time.Duration
	ReadTimeout  time.Duration
	WriteTimeout time.Duration

	// PoolSize applies per cluster node and not for the whole cluster.
	PoolSize           int
	MinIdleConns       int
	MaxConnAge         time.Duration
	PoolTimeout        time.Duration
	IdleTimeout        time.Duration
	IdleCheckFrequency time.Duration

	TLSConfig *tls.Config
}

ClusterOptions are used to configure a cluster client and should be passed to NewClusterClient.

type ClusterSlot

type ClusterSlot struct {
	Start int
	End   int
	Nodes []ClusterNode
}

type ClusterSlotsCmd

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

func NewClusterSlotsCmd

func NewClusterSlotsCmd(args ...interface{}) *ClusterSlotsCmd

func NewClusterSlotsCmdResult

func NewClusterSlotsCmdResult(val []ClusterSlot, err error) *ClusterSlotsCmd

NewClusterSlotsCmdResult returns a ClusterSlotsCmd initialised with val and err for testing

func (*ClusterSlotsCmd) Args

func (cmd *ClusterSlotsCmd) Args() []interface{}

func (*ClusterSlotsCmd) Err

func (cmd *ClusterSlotsCmd) Err() error

func (*ClusterSlotsCmd) Name

func (cmd *ClusterSlotsCmd) Name() string

func (*ClusterSlotsCmd) Result

func (cmd *ClusterSlotsCmd) Result() ([]ClusterSlot, error)

func (*ClusterSlotsCmd) String

func (cmd *ClusterSlotsCmd) String() string

func (*ClusterSlotsCmd) Val

func (cmd *ClusterSlotsCmd) Val() []ClusterSlot

type Cmd

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

func NewCmd

func NewCmd(args ...interface{}) *Cmd

func NewCmdResult

func NewCmdResult(val interface{}, err error) *Cmd

NewCmdResult returns a Cmd initialised with val and err for testing

func (*Cmd) Args

func (cmd *Cmd) Args() []interface{}

func (*Cmd) Bool

func (cmd *Cmd) Bool() (bool, error)

func (*Cmd) Err

func (cmd *Cmd) Err() error

func (*Cmd) Float32

func (cmd *Cmd) Float32() (float32, error)

func (*Cmd) Float64

func (cmd *Cmd) Float64() (float64, error)

func (*Cmd) Int

func (cmd *Cmd) Int() (int, error)

func (*Cmd) Int64

func (cmd *Cmd) Int64() (int64, error)

func (*Cmd) Name

func (cmd *Cmd) Name() string

func (*Cmd) Result

func (cmd *Cmd) Result() (interface{}, error)

func (*Cmd) String

func (cmd *Cmd) String() (string, error)

func (*Cmd) Uint64

func (cmd *Cmd) Uint64() (uint64, error)

func (*Cmd) Val

func (cmd *Cmd) Val() interface{}

type Cmdable

type Cmdable interface {
	Pipeline() Pipeliner
	Pipelined(fn func(Pipeliner) error) ([]Cmder, error)

	TxPipelined(fn func(Pipeliner) error) ([]Cmder, error)
	TxPipeline() Pipeliner

	Command() *CommandsInfoCmd
	ClientGetName() *StringCmd
	Echo(message interface{}) *StringCmd
	Ping() *StatusCmd
	Quit() *StatusCmd
	Del(keys ...string) *IntCmd
	Unlink(keys ...string) *IntCmd
	Dump(key string) *StringCmd
	Exists(keys ...string) *IntCmd
	Expire(key string, expiration time.Duration) *BoolCmd
	ExpireAt(key string, tm time.Time) *BoolCmd
	Keys(pattern string) *StringSliceCmd
	Migrate(host, port, key string, db int64, timeout time.Duration) *StatusCmd
	Move(key string, db int64) *BoolCmd
	ObjectRefCount(key string) *IntCmd
	ObjectEncoding(key string) *StringCmd
	ObjectIdleTime(key string) *DurationCmd
	Persist(key string) *BoolCmd
	PExpire(key string, expiration time.Duration) *BoolCmd
	PExpireAt(key string, tm time.Time) *BoolCmd
	PTTL(key string) *DurationCmd
	RandomKey() *StringCmd
	Rename(key, newkey string) *StatusCmd
	RenameNX(key, newkey string) *BoolCmd
	Restore(key string, ttl time.Duration, value string) *StatusCmd
	RestoreReplace(key string, ttl time.Duration, value string) *StatusCmd
	Sort(key string, sort *Sort) *StringSliceCmd
	SortStore(key, store string, sort *Sort) *IntCmd
	SortInterfaces(key string, sort *Sort) *SliceCmd
	Touch(keys ...string) *IntCmd
	TTL(key string) *DurationCmd
	Type(key string) *StatusCmd
	Scan(cursor uint64, match string, count int64) *ScanCmd
	SScan(key string, cursor uint64, match string, count int64) *ScanCmd
	HScan(key string, cursor uint64, match string, count int64) *ScanCmd
	ZScan(key string, cursor uint64, match string, count int64) *ScanCmd
	Append(key, value string) *IntCmd
	BitCount(key string, bitCount *BitCount) *IntCmd
	BitOpAnd(destKey string, keys ...string) *IntCmd
	BitOpOr(destKey string, keys ...string) *IntCmd
	BitOpXor(destKey string, keys ...string) *IntCmd
	BitOpNot(destKey string, key string) *IntCmd
	BitPos(key string, bit int64, pos ...int64) *IntCmd
	Decr(key string) *IntCmd
	DecrBy(key string, decrement int64) *IntCmd
	Get(key string) *StringCmd
	GetBit(key string, offset int64) *IntCmd
	GetRange(key string, start, end int64) *StringCmd
	GetSet(key string, value interface{}) *StringCmd
	Incr(key string) *IntCmd
	IncrBy(key string, value int64) *IntCmd
	IncrByFloat(key string, value float64) *FloatCmd
	MGet(keys ...string) *SliceCmd
	MSet(pairs ...interface{}) *StatusCmd
	MSetNX(pairs ...interface{}) *BoolCmd
	Set(key string, value interface{}, expiration time.Duration) *StatusCmd
	SetBit(key string, offset int64, value int) *IntCmd
	SetNX(key string, value interface{}, expiration time.Duration) *BoolCmd
	SetXX(key string, value interface{}, expiration time.Duration) *BoolCmd
	SetRange(key string, offset int64, value string) *IntCmd
	StrLen(key string) *IntCmd
	HDel(key string, fields ...string) *IntCmd
	HExists(key, field string) *BoolCmd
	HGet(key, field string) *StringCmd
	HGetAll(key string) *StringStringMapCmd
	HIncrBy(key, field string, incr int64) *IntCmd
	HIncrByFloat(key, field string, incr float64) *FloatCmd
	HKeys(key string) *StringSliceCmd
	HLen(key string) *IntCmd
	HMGet(key string, fields ...string) *SliceCmd
	HMSet(key string, fields map[string]interface{}) *StatusCmd
	HSet(key, field string, value interface{}) *BoolCmd
	HSetNX(key, field string, value interface{}) *BoolCmd
	HVals(key string) *StringSliceCmd
	BLPop(timeout time.Duration, keys ...string) *StringSliceCmd
	BRPop(timeout time.Duration, keys ...string) *StringSliceCmd
	BRPopLPush(source, destination string, timeout time.Duration) *StringCmd
	LIndex(key string, index int64) *StringCmd
	LInsert(key, op string, pivot, value interface{}) *IntCmd
	LInsertBefore(key string, pivot, value interface{}) *IntCmd
	LInsertAfter(key string, pivot, value interface{}) *IntCmd
	LLen(key string) *IntCmd
	LPop(key string) *StringCmd
	LPush(key string, values ...interface{}) *IntCmd
	LPushX(key string, value interface{}) *IntCmd
	LRange(key string, start, stop int64) *StringSliceCmd
	LRem(key string, count int64, value interface{}) *IntCmd
	LSet(key string, index int64, value interface{}) *StatusCmd
	LTrim(key string, start, stop int64) *StatusCmd
	RPop(key string) *StringCmd
	RPopLPush(source, destination string) *StringCmd
	RPush(key string, values ...interface{}) *IntCmd
	RPushX(key string, value interface{}) *IntCmd
	SAdd(key string, members ...interface{}) *IntCmd
	SCard(key string) *IntCmd
	SDiff(keys ...string) *StringSliceCmd
	SDiffStore(destination string, keys ...string) *IntCmd
	SInter(keys ...string) *StringSliceCmd
	SInterStore(destination string, keys ...string) *IntCmd
	SIsMember(key string, member interface{}) *BoolCmd
	SMembers(key string) *StringSliceCmd
	SMembersMap(key string) *StringStructMapCmd
	SMove(source, destination string, member interface{}) *BoolCmd
	SPop(key string) *StringCmd
	SPopN(key string, count int64) *StringSliceCmd
	SRandMember(key string) *StringCmd
	SRandMemberN(key string, count int64) *StringSliceCmd
	SRem(key string, members ...interface{}) *IntCmd
	SUnion(keys ...string) *StringSliceCmd
	SUnionStore(destination string, keys ...string) *IntCmd
	XAdd(a *XAddArgs) *StringCmd
	XDel(stream string, ids ...string) *IntCmd
	XLen(stream string) *IntCmd
	XRange(stream, start, stop string) *XMessageSliceCmd
	XRangeN(stream, start, stop string, count int64) *XMessageSliceCmd
	XRevRange(stream string, start, stop string) *XMessageSliceCmd
	XRevRangeN(stream string, start, stop string, count int64) *XMessageSliceCmd
	XRead(a *XReadArgs) *XStreamSliceCmd
	XReadStreams(streams ...string) *XStreamSliceCmd
	XGroupCreate(stream, group, start string) *StatusCmd
	XGroupCreateMkStream(stream, group, start string) *StatusCmd
	XGroupSetID(stream, group, start string) *StatusCmd
	XGroupDestroy(stream, group string) *IntCmd
	XGroupDelConsumer(stream, group, consumer string) *IntCmd
	XReadGroup(a *XReadGroupArgs) *XStreamSliceCmd
	XAck(stream, group string, ids ...string) *IntCmd
	XPending(stream, group string) *XPendingCmd
	XPendingExt(a *XPendingExtArgs) *XPendingExtCmd
	XClaim(a *XClaimArgs) *XMessageSliceCmd
	XClaimJustID(a *XClaimArgs) *StringSliceCmd
	XTrim(key string, maxLen int64) *IntCmd
	XTrimApprox(key string, maxLen int64) *IntCmd
	BZPopMax(timeout time.Duration, keys ...string) *ZWithKeyCmd
	BZPopMin(timeout time.Duration, keys ...string) *ZWithKeyCmd
	ZAdd(key string, members ...Z) *IntCmd
	ZAddNX(key string, members ...Z) *IntCmd
	ZAddXX(key string, members ...Z) *IntCmd
	ZAddCh(key string, members ...Z) *IntCmd
	ZAddNXCh(key string, members ...Z) *IntCmd
	ZAddXXCh(key string, members ...Z) *IntCmd
	ZIncr(key string, member Z) *FloatCmd
	ZIncrNX(key string, member Z) *FloatCmd
	ZIncrXX(key string, member Z) *FloatCmd
	ZCard(key string) *IntCmd
	ZCount(key, min, max string) *IntCmd
	ZLexCount(key, min, max string) *IntCmd
	ZIncrBy(key string, increment float64, member string) *FloatCmd
	ZInterStore(destination string, store ZStore, keys ...string) *IntCmd
	ZPopMax(key string, count ...int64) *ZSliceCmd
	ZPopMin(key string, count ...int64) *ZSliceCmd
	ZRange(key string, start, stop int64) *StringSliceCmd
	ZRangeWithScores(key string, start, stop int64) *ZSliceCmd
	ZRangeByScore(key string, opt ZRangeBy) *StringSliceCmd
	ZRangeByLex(key string, opt ZRangeBy) *StringSliceCmd
	ZRangeByScoreWithScores(key string, opt ZRangeBy) *ZSliceCmd
	ZRank(key, member string) *IntCmd
	ZRem(key string, members ...interface{}) *IntCmd
	ZRemRangeByRank(key string, start, stop int64) *IntCmd
	ZRemRangeByScore(key, min, max string) *IntCmd
	ZRemRangeByLex(key, min, max string) *IntCmd
	ZRevRange(key string, start, stop int64) *StringSliceCmd
	ZRevRangeWithScores(key string, start, stop int64) *ZSliceCmd
	ZRevRangeByScore(key string, opt ZRangeBy) *StringSliceCmd
	ZRevRangeByLex(key string, opt ZRangeBy) *StringSliceCmd
	ZRevRangeByScoreWithScores(key string, opt ZRangeBy) *ZSliceCmd
	ZRevRank(key, member string) *IntCmd
	ZScore(key, member string) *FloatCmd
	ZUnionStore(dest string, store ZStore, keys ...string) *IntCmd
	PFAdd(key string, els ...interface{}) *IntCmd
	PFCount(keys ...string) *IntCmd
	PFMerge(dest string, keys ...string) *StatusCmd
	BgRewriteAOF() *StatusCmd
	BgSave() *StatusCmd
	ClientKill(ipPort string) *StatusCmd
	ClientKillByFilter(keys ...string) *IntCmd
	ClientList() *StringCmd
	ClientPause(dur time.Duration) *BoolCmd
	ClientID() *IntCmd
	ConfigGet(parameter string) *SliceCmd
	ConfigResetStat() *StatusCmd
	ConfigSet(parameter, value string) *StatusCmd
	ConfigRewrite() *StatusCmd
	DBSize() *IntCmd
	FlushAll() *StatusCmd
	FlushAllAsync() *StatusCmd
	FlushDB() *StatusCmd
	FlushDBAsync() *StatusCmd
	Info(section ...string) *StringCmd
	LastSave() *IntCmd
	Save() *StatusCmd
	Shutdown() *StatusCmd
	ShutdownSave() *StatusCmd
	ShutdownNoSave() *StatusCmd
	SlaveOf(host, port string) *StatusCmd
	Time() *TimeCmd
	Eval(script string, keys []string, args ...interface{}) *Cmd
	EvalSha(sha1 string, keys []string, args ...interface{}) *Cmd
	ScriptExists(hashes ...string) *BoolSliceCmd
	ScriptFlush() *StatusCmd
	ScriptKill() *StatusCmd
	ScriptLoad(script string) *StringCmd
	DebugObject(key string) *StringCmd
	Publish(channel string, message interface{}) *IntCmd
	PubSubChannels(pattern string) *StringSliceCmd
	PubSubNumSub(channels ...string) *StringIntMapCmd
	PubSubNumPat() *IntCmd
	ClusterSlots() *ClusterSlotsCmd
	ClusterNodes() *StringCmd
	ClusterMeet(host, port string) *StatusCmd
	ClusterForget(nodeID string) *StatusCmd
	ClusterReplicate(nodeID string) *StatusCmd
	ClusterResetSoft() *StatusCmd
	ClusterResetHard() *StatusCmd
	ClusterInfo() *StringCmd
	ClusterKeySlot(key string) *IntCmd
	ClusterGetKeysInSlot(slot int, count int) *StringSliceCmd
	ClusterCountFailureReports(nodeID string) *IntCmd
	ClusterCountKeysInSlot(slot int) *IntCmd
	ClusterDelSlots(slots ...int) *StatusCmd
	ClusterDelSlotsRange(min, max int) *StatusCmd
	ClusterSaveConfig() *StatusCmd
	ClusterSlaves(nodeID string) *StringSliceCmd
	ClusterFailover() *StatusCmd
	ClusterAddSlots(slots ...int) *StatusCmd
	ClusterAddSlotsRange(min, max int) *StatusCmd
	GeoAdd(key string, geoLocation ...*GeoLocation) *IntCmd
	GeoPos(key string, members ...string) *GeoPosCmd
	GeoRadius(key string, longitude, latitude float64, query *GeoRadiusQuery) *GeoLocationCmd
	GeoRadiusRO(key string, longitude, latitude float64, query *GeoRadiusQuery) *GeoLocationCmd
	GeoRadiusByMember(key, member string, query *GeoRadiusQuery) *GeoLocationCmd
	GeoRadiusByMemberRO(key, member string, query *GeoRadiusQuery) *GeoLocationCmd
	GeoDist(key string, member1, member2, unit string) *FloatCmd
	GeoHash(key string, members ...string) *StringSliceCmd
	ReadOnly() *StatusCmd
	ReadWrite() *StatusCmd
	MemoryUsage(key string, samples ...int) *IntCmd
}

type Cmder

type Cmder interface {
	Name() string
	Args() []interface{}

	Err() error
	// contains filtered or unexported methods
}

type CommandInfo

type CommandInfo struct {
	Name        string
	Arity       int8
	Flags       []string
	FirstKeyPos int8
	LastKeyPos  int8
	StepCount   int8
	ReadOnly    bool
}

type CommandsInfoCmd

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

func NewCommandsInfoCmd

func NewCommandsInfoCmd(args ...interface{}) *CommandsInfoCmd

func NewCommandsInfoCmdResult

func NewCommandsInfoCmdResult(val map[string]*CommandInfo, err error) *CommandsInfoCmd

NewCommandsInfoCmdResult returns a CommandsInfoCmd initialised with val and err for testing

func (*CommandsInfoCmd) Args

func (cmd *CommandsInfoCmd) Args() []interface{}

func (*CommandsInfoCmd) Err

func (cmd *CommandsInfoCmd) Err() error

func (*CommandsInfoCmd) Name

func (cmd *CommandsInfoCmd) Name() string

func (*CommandsInfoCmd) Result

func (cmd *CommandsInfoCmd) Result() (map[string]*CommandInfo, error)

func (*CommandsInfoCmd) String

func (cmd *CommandsInfoCmd) String() string

func (*CommandsInfoCmd) Val

func (cmd *CommandsInfoCmd) Val() map[string]*CommandInfo

type Conn

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

Conn is like Client, but its pool contains single connection.

func (*Conn) Auth

func (c *Conn) Auth(password string) *StatusCmd

func (*Conn) ClientSetName

func (c *Conn) ClientSetName(name string) *BoolCmd

ClientSetName assigns a name to the connection.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the client, releasing any open resources.

It is rare to Close a Client, as the Client is meant to be long-lived and shared between many goroutines.

func (*Conn) Do

func (c *Conn) Do(args ...interface{}) *Cmd

Do creates a Cmd from the args and processes the cmd.

func (*Conn) Pipeline

func (c *Conn) Pipeline() Pipeliner

func (*Conn) Pipelined

func (c *Conn) Pipelined(fn func(Pipeliner) error) ([]Cmder, error)

func (*Conn) Process

func (c *Conn) Process(cmd Cmder) error

func (*Conn) Select

func (c *Conn) Select(index int) *StatusCmd

func (*Conn) String

func (c *Conn) String() string

func (*Conn) SwapDB

func (c *Conn) SwapDB(index1, index2 int) *StatusCmd

func (*Conn) TxPipeline

func (c *Conn) TxPipeline() Pipeliner

TxPipeline acts like Pipeline, but wraps queued commands with MULTI/EXEC.

func (*Conn) TxPipelined

func (c *Conn) TxPipelined(fn func(Pipeliner) error) ([]Cmder, error)

func (*Conn) WrapProcess

func (c *Conn) WrapProcess(
	fn func(oldProcess func(cmd Cmder) error) func(cmd Cmder) error,
)

WrapProcess wraps function that processes Redis commands.

func (*Conn) WrapProcessPipeline

func (c *Conn) WrapProcessPipeline(
	fn func(oldProcess func([]Cmder) error) func([]Cmder) error,
)

type DurationCmd

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

func NewDurationCmd

func NewDurationCmd(precision time.Duration, args ...interface{}) *DurationCmd

func NewDurationResult

func NewDurationResult(val time.Duration, err error) *DurationCmd

NewDurationResult returns a DurationCmd initialised with val and err for testing

func (*DurationCmd) Args

func (cmd *DurationCmd) Args() []interface{}

func (*DurationCmd) Err

func (cmd *DurationCmd) Err() error

func (*DurationCmd) Name

func (cmd *DurationCmd) Name() string

func (*DurationCmd) Result

func (cmd *DurationCmd) Result() (time.Duration, error)

func (*DurationCmd) String

func (cmd *DurationCmd) String() string

func (*DurationCmd) Val

func (cmd *DurationCmd) Val() time.Duration

type FailoverOptions

type FailoverOptions struct {
	// The master name.
	MasterName string
	// A seed list of host:port addresses of sentinel nodes.
	SentinelAddrs []string

	OnConnect func(*Conn) error

	Password string
	DB       int

	MaxRetries      int
	MinRetryBackoff time.Duration
	MaxRetryBackoff time.Duration

	DialTimeout  time.Duration
	ReadTimeout  time.Duration
	WriteTimeout time.Duration

	PoolSize           int
	MinIdleConns       int
	MaxConnAge         time.Duration
	PoolTimeout        time.Duration
	IdleTimeout        time.Duration
	IdleCheckFrequency time.Duration

	TLSConfig *tls.Config
}

FailoverOptions are used to configure a failover client and should be passed to NewFailoverClient.

type FloatCmd

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

func NewFloatCmd

func NewFloatCmd(args ...interface{}) *FloatCmd

func NewFloatResult

func NewFloatResult(val float64, err error) *FloatCmd

NewFloatResult returns a FloatCmd initialised with val and err for testing

func (*FloatCmd) Args

func (cmd *FloatCmd) Args() []interface{}

func (*FloatCmd) Err

func (cmd *FloatCmd) Err() error

func (*FloatCmd) Name

func (cmd *FloatCmd) Name() string

func (*FloatCmd) Result

func (cmd *FloatCmd) Result() (float64, error)

func (*FloatCmd) String

func (cmd *FloatCmd) String() string

func (*FloatCmd) Val

func (cmd *FloatCmd) Val() float64

type GeoLocation

type GeoLocation struct {
	Name                      string
	Longitude, Latitude, Dist float64
	GeoHash                   int64
}

GeoLocation is used with GeoAdd to add geospatial location.

type GeoLocationCmd

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

func NewGeoLocationCmd

func NewGeoLocationCmd(q *GeoRadiusQuery, args ...interface{}) *GeoLocationCmd

func NewGeoLocationCmdResult

func NewGeoLocationCmdResult(val []GeoLocation, err error) *GeoLocationCmd

NewGeoLocationCmdResult returns a GeoLocationCmd initialised with val and err for testing

func (*GeoLocationCmd) Args

func (cmd *GeoLocationCmd) Args() []interface{}

func (*GeoLocationCmd) Err

func (cmd *GeoLocationCmd) Err() error

func (*GeoLocationCmd) Name

func (cmd *GeoLocationCmd) Name() string

func (*GeoLocationCmd) Result

func (cmd *GeoLocationCmd) Result() ([]GeoLocation, error)

func (*GeoLocationCmd) String

func (cmd *GeoLocationCmd) String() string

func (*GeoLocationCmd) Val

func (cmd *GeoLocationCmd) Val() []GeoLocation

type GeoPos

type GeoPos struct {
	Longitude, Latitude float64
}

type GeoPosCmd

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

func NewGeoPosCmd

func NewGeoPosCmd(args ...interface{}) *GeoPosCmd

func (*GeoPosCmd) Args

func (cmd *GeoPosCmd) Args() []interface{}

func (*GeoPosCmd) Err

func (cmd *GeoPosCmd) Err() error

func (*GeoPosCmd) Name

func (cmd *GeoPosCmd) Name() string

func (*GeoPosCmd) Result

func (cmd *GeoPosCmd) Result() ([]*GeoPos, error)

func (*GeoPosCmd) String

func (cmd *GeoPosCmd) String() string

func (*GeoPosCmd) Val

func (cmd *GeoPosCmd) Val() []*GeoPos

type GeoRadiusQuery

type GeoRadiusQuery struct {
	Radius float64
	// Can be m, km, ft, or mi. Default is km.
	Unit        string
	WithCoord   bool
	WithDist    bool
	WithGeoHash bool
	Count       int
	// Can be ASC or DESC. Default is no sort order.
	Sort      string
	Store     string
	StoreDist string
}

GeoRadiusQuery is used with GeoRadius to query geospatial index.

type Hash

type Hash consistenthash.Hash

Hash is type of hash function used in consistent hash.

type IntCmd

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

func NewIntCmd

func NewIntCmd(args ...interface{}) *IntCmd

func NewIntResult

func NewIntResult(val int64, err error) *IntCmd

NewIntResult returns an IntCmd initialised with val and err for testing

func (*IntCmd) Args

func (cmd *IntCmd) Args() []interface{}

func (*IntCmd) Err

func (cmd *IntCmd) Err() error

func (*IntCmd) Name

func (cmd *IntCmd) Name() string

func (*IntCmd) Result

func (cmd *IntCmd) Result() (int64, error)

func (*IntCmd) String

func (cmd *IntCmd) String() string

func (*IntCmd) Val

func (cmd *IntCmd) Val() int64

type Limiter

type Limiter interface {
	// Allow returns a nil if operation is allowed or an error otherwise.
	// If operation is allowed client must report the result of operation
	// whether is a success or a failure.
	Allow() error
	// ReportResult reports the result of previously allowed operation.
	// nil indicates a success, non-nil error indicates a failure.
	ReportResult(result error)
}

Limiter is the interface of a rate limiter or a circuit breaker.

type Message

type Message struct {
	Channel string
	Pattern string
	Payload string
}

Message received as result of a PUBLISH command issued by another client.

func (*Message) String

func (m *Message) String() string

type Options

type Options struct {
	// The network type, either tcp or unix.
	// Default is tcp.
	Network string
	// host:port address.
	Addr string

	// Dialer creates new network connection and has priority over
	// Network and Addr options.
	Dialer func() (net.Conn, error)

	// Hook that is called when new connection is established.
	OnConnect func(*Conn) error

	// Optional password. Must match the password specified in the
	// requirepass server configuration option.
	Password string
	// Database to be selected after connecting to the server.
	DB int

	// Maximum number of retries before giving up.
	// Default is to not retry failed commands.
	MaxRetries int
	// Minimum backoff between each retry.
	// Default is 8 milliseconds; -1 disables backoff.
	MinRetryBackoff time.Duration
	// Maximum backoff between each retry.
	// Default is 512 milliseconds; -1 disables backoff.
	MaxRetryBackoff time.Duration

	// Dial timeout for establishing new connections.
	// Default is 5 seconds.
	DialTimeout time.Duration
	// Timeout for socket reads. If reached, commands will fail
	// with a timeout instead of blocking. Use value -1 for no timeout and 0 for default.
	// Default is 3 seconds.
	ReadTimeout time.Duration
	// Timeout for socket writes. If reached, commands will fail
	// with a timeout instead of blocking.
	// Default is ReadTimeout.
	WriteTimeout time.Duration

	// Maximum number of socket connections.
	// Default is 10 connections per every CPU as reported by runtime.NumCPU.
	PoolSize int
	// Minimum number of idle connections which is useful when establishing
	// new connection is slow.
	MinIdleConns int
	// Connection age at which client retires (closes) the connection.
	// Default is to not close aged connections.
	MaxConnAge time.Duration
	// Amount of time client waits for connection if all connections
	// are busy before returning an error.
	// Default is ReadTimeout + 1 second.
	PoolTimeout time.Duration
	// Amount of time after which client closes idle connections.
	// Should be less than server's timeout.
	// Default is 5 minutes. -1 disables idle timeout check.
	IdleTimeout time.Duration
	// Frequency of idle checks made by idle connections reaper.
	// Default is 1 minute. -1 disables idle connections reaper,
	// but idle connections are still discarded by the client
	// if IdleTimeout is set.
	IdleCheckFrequency time.Duration

	// TLS Config to use. When set TLS will be negotiated.
	TLSConfig *tls.Config
	// contains filtered or unexported fields
}

func ParseURL

func ParseURL(redisURL string) (*Options, error)

ParseURL parses an URL into Options that can be used to connect to Redis.

Example
package main

import (
	"fmt"
	"time"

	"github.com/go-redis/redis"
)

var redisdb *redis.Client

func init() {
	redisdb = redis.NewClient(&redis.Options{
		Addr:         ":6379",
		DialTimeout:  10 * time.Second,
		ReadTimeout:  30 * time.Second,
		WriteTimeout: 30 * time.Second,
		PoolSize:     10,
		PoolTimeout:  30 * time.Second,
	})
}

func main() {
	opt, err := redis.ParseURL("redis://:qwerty@localhost:6379/1")
	if err != nil {
		panic(err)
	}
	fmt.Println("addr is", opt.Addr)
	fmt.Println("db is", opt.DB)
	fmt.Println("password is", opt.Password)

	// Create client as usually.
	_ = redis.NewClient(opt)

}
Output:

addr is localhost:6379
db is 1
password is qwerty

type Pipeline

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

Pipeline implements pipelining as described in http://redis.io/topics/pipelining. It's safe for concurrent use by multiple goroutines.

Example (Instrumentation)
package main

import (
	"fmt"

	"github.com/go-redis/redis"
)

func main() {
	redisdb := redis.NewClient(&redis.Options{
		Addr: ":6379",
	})

	redisdb.WrapProcessPipeline(func(old func([]redis.Cmder) error) func([]redis.Cmder) error {
		return func(cmds []redis.Cmder) error {
			fmt.Printf("pipeline starting processing: %v\n", cmds)
			err := old(cmds)
			fmt.Printf("pipeline finished processing: %v\n", cmds)
			return err
		}
	})

	redisdb.Pipelined(func(pipe redis.Pipeliner) error {
		pipe.Ping()
		pipe.Ping()
		return nil
	})
}
Output:

pipeline starting processing: [ping:  ping: ]
pipeline finished processing: [ping: PONG ping: PONG]

func (*Pipeline) Auth

func (c *Pipeline) Auth(password string) *StatusCmd

func (*Pipeline) ClientSetName

func (c *Pipeline) ClientSetName(name string) *BoolCmd

ClientSetName assigns a name to the connection.

func (*Pipeline) Close

func (c *Pipeline) Close() error

Close closes the pipeline, releasing any open resources.

func (*Pipeline) Discard

func (c *Pipeline) Discard() error

Discard resets the pipeline and discards queued commands.

func (*Pipeline) Do

func (c *Pipeline) Do(args ...interface{}) *Cmd

func (*Pipeline) Exec

func (c *Pipeline) Exec() ([]Cmder, error)

Exec executes all previously queued commands using one client-server roundtrip.

Exec always returns list of commands and error of the first failed command if any.

func (*Pipeline) Pipeline

func (c *Pipeline) Pipeline() Pipeliner

func (*Pipeline) Pipelined

func (c *Pipeline) Pipelined(fn func(Pipeliner) error) ([]Cmder, error)

func (*Pipeline) Process

func (c *Pipeline) Process(cmd Cmder) error

Process queues the cmd for later execution.

func (*Pipeline) Select

func (c *Pipeline) Select(index int) *StatusCmd

func (*Pipeline) SwapDB

func (c *Pipeline) SwapDB(index1, index2 int) *StatusCmd

func (*Pipeline) TxPipeline

func (c *Pipeline) TxPipeline() Pipeliner

func (*Pipeline) TxPipelined

func (c *Pipeline) TxPipelined(fn func(Pipeliner) error) ([]Cmder, error)

type Pipeliner

type Pipeliner interface {
	StatefulCmdable
	Do(args ...interface{}) *Cmd
	Process(cmd Cmder) error
	Close() error
	Discard() error
	Exec() ([]Cmder, error)
}

Pipeliner is an mechanism to realise Redis Pipeline technique.

Pipelining is a technique to extremely speed up processing by packing operations to batches, send them at once to Redis and read a replies in a singe step. See https://redis.io/topics/pipelining

Pay attention, that Pipeline is not a transaction, so you can get unexpected results in case of big pipelines and small read/write timeouts. Redis client has retransmission logic in case of timeouts, pipeline can be retransmitted and commands can be executed more then once. To avoid this: it is good idea to use reasonable bigger read/write timeouts depends of your batch size and/or use TxPipeline.

type Pong

type Pong struct {
	Payload string
}

Pong received as result of a PING command issued by another client.

func (*Pong) String

func (p *Pong) String() string

type PoolStats

type PoolStats pool.Stats

type PubSub

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

PubSub implements Pub/Sub commands as described in http://redis.io/topics/pubsub. Message receiving is NOT safe for concurrent use by multiple goroutines.

PubSub automatically reconnects to Redis Server and resubscribes to the channels in case of network errors.