redis

package module
v8.4.5 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2021 License: BSD-2-Clause Imports: 27 Imported by: 0

README

Redis client for Golang

Build Status PkgGoDev Documentation Chat

Uptrace.dev - distributed traces, logs, and errors in one place

Ecosystem

Features

Installation

go-redis supports 2 last Go versions and requires a Go version with modules support. So make sure to initialize a Go module:

go mod init github.com/my/repo

And then install go-redis/v8 (note v8 in the import; omitting it is a popular mistake):

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

Quickstart

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

var ctx = context.Background()

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

    err := rdb.Set(ctx, "key", "value", 0).Err()
    if err != nil {
        panic(err)
    }

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

    val2, err := rdb.Get(ctx, "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
}

Look and feel

Some corner cases:

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

// SET key value keepttl NX
set, err := rdb.SetNX(ctx, "key", "value", redis.KeepTTL).Result()

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

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

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

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

// custom command
res, err := rdb.Do(ctx, "set", "key", "value").Result()

Run the test

go-redis will start a redis-server and run the test cases.

The paths of redis-server bin file and redis config file are definded in main_test.go:

var (
	redisServerBin, _  = filepath.Abs(filepath.Join("testdata", "redis", "src", "redis-server"))
	redisServerConf, _ = filepath.Abs(filepath.Join("testdata", "redis", "redis.conf"))
)

For local testing, you can change the variables to refer to your local files, or create a soft link to the corresponding folder for redis-server and copy the config file to testdata/redis/:

ln -s /usr/bin/redis-server ./go-redis/testdata/redis/src
cp ./go-redis/testdata/redis.conf ./go-redis/testdata/redis/

Lastly, run:

go test

See also

Documentation

Overview

Package redis implements a Redis client.

Example (CustomCommand)
Get := func(ctx context.Context, rdb *redis.Client, key string) *redis.StringCmd {
	cmd := redis.NewStringCmd(ctx, "get", key)
	rdb.Process(ctx, cmd)
	return cmd
}

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

"" redis: nil
Example (CustomCommand2)
v, err := rdb.Do(ctx, "get", "key_does_not_exist").Text()
fmt.Printf("%q %s", v, err)
Output:

"" redis: nil
Example (Instrumentation)
rdb := redis.NewClient(&redis.Options{
	Addr: ":6379",
})
rdb.AddHook(redisHook{})

rdb.Ping(ctx)
Output:

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

Index

Examples

Constants

View Source
const KeepTTL = -1

KeepTTL is an option for Set command to keep key's existing TTL. For example:

rdb.Set(ctx, key, value, redis.KeepTTL)
View Source
const Nil = proto.Nil

Nil reply returned by Redis when key does not exist.

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

TxFailedErr transaction redis failed.

Variables

View Source
var ErrClosed = pool.ErrClosed

Functions

func SetLogger

func SetLogger(logger internal.Logging)

Types

type BitCount

type BitCount struct {
	Start, End int64
}

type BoolCmd

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

func NewBoolCmd

func NewBoolCmd(ctx context.Context, 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) FullName

func (cmd *BoolCmd) FullName() string

func (*BoolCmd) Name

func (cmd *BoolCmd) Name() string

func (*BoolCmd) Result

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

func (*BoolCmd) SetErr

func (cmd *BoolCmd) SetErr(e 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(ctx context.Context, 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) FullName

func (cmd *BoolSliceCmd) FullName() string

func (*BoolSliceCmd) Name

func (cmd *BoolSliceCmd) Name() string

func (*BoolSliceCmd) Result

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

func (*BoolSliceCmd) SetErr

func (cmd *BoolSliceCmd) SetErr(e 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
err := rdb.Set(ctx, "key", "value", 0).Err()
if err != nil {
	panic(err)
}

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

val2, err := rdb.Get(ctx, "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
rdb := redis.NewClient(&redis.Options{
	Addr:     "localhost:6379", // use default Addr
	Password: "",               // no password set
	DB:       0,                // use default DB
})

pong, err := rdb.Ping(ctx).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
// See http://redis.io/topics/sentinel for instructions how to
// setup Redis Sentinel.
rdb := redis.NewFailoverClient(&redis.FailoverOptions{
	MasterName:    "master",
	SentinelAddrs: []string{":26379"},
})
rdb.Ping(ctx)
Output:

func (*Client) AddHook

func (hs *Client) AddHook(hook Hook)

func (Client) Append

func (c Client) Append(ctx context.Context, key, value string) *IntCmd

func (Client) BLPop

func (c Client) BLPop(ctx context.Context, timeout time.Duration, keys ...string) *StringSliceCmd
Example
if err := rdb.RPush(ctx, "queue", "message").Err(); err != nil {
	panic(err)
}

// use `rdb.BLPop(0, "queue")` for infinite waiting time
result, err := rdb.BLPop(ctx, 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(ctx context.Context, timeout time.Duration, keys ...string) *StringSliceCmd

func (Client) BRPopLPush

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

func (Client) BZPopMax

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

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

func (Client) BZPopMin

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

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

func (Client) BgRewriteAOF

func (c Client) BgRewriteAOF(ctx context.Context) *StatusCmd

func (Client) BgSave

func (c Client) BgSave(ctx context.Context) *StatusCmd

func (Client) BitCount

func (c Client) BitCount(ctx context.Context, key string, bitCount *BitCount) *IntCmd

func (Client) BitField

func (c Client) BitField(ctx context.Context, key string, args ...interface{}) *IntSliceCmd

func (Client) BitOpAnd

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

func (Client) BitOpNot

func (c Client) BitOpNot(ctx context.Context, destKey string, key string) *IntCmd

func (Client) BitOpOr

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

func (Client) BitOpXor

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

func (Client) BitPos

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

func (Client) ClientGetName

func (c Client) ClientGetName(ctx context.Context) *StringCmd

ClientGetName returns the name of the connection.

func (Client) ClientID

func (c Client) ClientID(ctx context.Context) *IntCmd

func (Client) ClientKill

func (c Client) ClientKill(ctx context.Context, ipPort string) *StatusCmd

func (Client) ClientKillByFilter

func (c Client) ClientKillByFilter(ctx context.Context, keys ...string) *IntCmd

ClientKillByFilter is new style syntax, while the ClientKill is old

CLIENT KILL <option> [value] ... <option> [value]

func (Client) ClientList

func (c Client) ClientList(ctx context.Context) *StringCmd

func (Client) ClientPause

func (c Client) ClientPause(ctx context.Context, dur time.Duration) *BoolCmd

func (Client) ClientUnblock

func (c Client) ClientUnblock(ctx context.Context, id int64) *IntCmd

func (Client) ClientUnblockWithError

func (c Client) ClientUnblockWithError(ctx context.Context, 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(ctx context.Context, slots ...int) *StatusCmd

func (Client) ClusterAddSlotsRange

func (c Client) ClusterAddSlotsRange(ctx context.Context, min, max int) *StatusCmd

func (Client) ClusterCountFailureReports

func (c Client) ClusterCountFailureReports(ctx context.Context, nodeID string) *IntCmd

func (Client) ClusterCountKeysInSlot

func (c Client) ClusterCountKeysInSlot(ctx context.Context, slot int) *IntCmd

func (Client) ClusterDelSlots

func (c Client) ClusterDelSlots(ctx context.Context, slots ...int) *StatusCmd

func (Client) ClusterDelSlotsRange

func (c Client) ClusterDelSlotsRange(ctx context.Context, min, max int) *StatusCmd

func (Client) ClusterFailover

func (c Client) ClusterFailover(ctx context.Context) *StatusCmd

func (Client) ClusterForget

func (c Client) ClusterForget(ctx context.Context, nodeID string) *StatusCmd

func (Client) ClusterGetKeysInSlot

func (c Client) ClusterGetKeysInSlot(ctx context.Context, slot int, count int) *StringSliceCmd

func (Client) ClusterInfo

func (c Client) ClusterInfo(ctx context.Context) *StringCmd

func (Client) ClusterKeySlot

func (c Client) ClusterKeySlot(ctx context.Context, key string) *IntCmd

func (Client) ClusterMeet

func (c Client) ClusterMeet(ctx context.Context, host, port string) *StatusCmd

func (Client) ClusterNodes

func (c Client) ClusterNodes(ctx context.Context) *StringCmd

func (Client) ClusterReplicate

func (c Client) ClusterReplicate(ctx context.Context, nodeID string) *StatusCmd

func (Client) ClusterResetHard

func (c Client) ClusterResetHard(ctx context.Context) *StatusCmd

func (Client) ClusterResetSoft

func (c Client) ClusterResetSoft(ctx context.Context) *StatusCmd

func (Client) ClusterSaveConfig

func (c Client) ClusterSaveConfig(ctx context.Context) *StatusCmd

func (Client) ClusterSlaves

func (c Client) ClusterSlaves(ctx context.Context, nodeID string) *StringSliceCmd

func (Client) ClusterSlots

func (c Client) ClusterSlots(ctx context.Context) *ClusterSlotsCmd

func (Client) Command

func (c Client) Command(ctx context.Context) *CommandsInfoCmd

func (Client) ConfigGet

func (c Client) ConfigGet(ctx context.Context, parameter string) *SliceCmd

func (Client) ConfigResetStat

func (c Client) ConfigResetStat(ctx context.Context) *StatusCmd

func (Client) ConfigRewrite

func (c Client) ConfigRewrite(ctx context.Context) *StatusCmd

func (Client) ConfigSet

func (c Client) ConfigSet(ctx context.Context, parameter, value string) *StatusCmd

func (*Client) Conn

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

func (*Client) Context

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

func (Client) DBSize

func (c Client) DBSize(ctx context.Context) *IntCmd

func (Client) DebugObject

func (c Client) DebugObject(ctx context.Context, key string) *StringCmd

func (Client) Decr

func (c Client) Decr(ctx context.Context, key string) *IntCmd

func (Client) DecrBy

func (c Client) DecrBy(ctx context.Context, key string, decrement int64) *IntCmd

func (Client) Del

func (c Client) Del(ctx context.Context, keys ...string) *IntCmd

func (*Client) Do

func (c *Client) Do(ctx context.Context, args ...interface{}) *Cmd

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

func (Client) Dump

func (c Client) Dump(ctx context.Context, key string) *StringCmd

func (Client) Echo

func (c Client) Echo(ctx context.Context, message interface{}) *StringCmd

func (Client) Eval

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

func (Client) EvalSha

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

func (Client) Exists

func (c Client) Exists(ctx context.Context, keys ...string) *IntCmd

func (Client) Expire

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

func (Client) ExpireAt

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

func (Client) FlushAll

func (c Client) FlushAll(ctx context.Context) *StatusCmd

func (Client) FlushAllAsync

func (c Client) FlushAllAsync(ctx context.Context) *StatusCmd

func (Client) FlushDB

func (c Client) FlushDB(ctx context.Context) *StatusCmd

func (Client) FlushDBAsync

func (c Client) FlushDBAsync(ctx context.Context) *StatusCmd

func (Client) GeoAdd

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

func (Client) GeoDist

func (c Client) GeoDist(
	ctx context.Context, key string, member1, member2, unit string,
) *FloatCmd

func (Client) GeoHash

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

func (Client) GeoPos

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

func (Client) GeoRadius

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

GeoRadius is a read-only GEORADIUS_RO command.

func (Client) GeoRadiusByMember

func (c Client) GeoRadiusByMember(
	ctx context.Context, key, member string, query *GeoRadiusQuery,
) *GeoLocationCmd

GeoRadius is a read-only GEORADIUSBYMEMBER_RO command.

func (Client) GeoRadiusByMemberStore

func (c Client) GeoRadiusByMemberStore(
	ctx context.Context, key, member string, query *GeoRadiusQuery,
) *IntCmd

GeoRadiusByMemberStore is a writing GEORADIUSBYMEMBER command.

func (Client) GeoRadiusStore

func (c Client) GeoRadiusStore(
	ctx context.Context, key string, longitude, latitude float64, query *GeoRadiusQuery,
) *IntCmd

GeoRadiusStore is a writing GEORADIUS command.

func (Client) Get

func (c Client) Get(ctx context.Context, key string) *StringCmd

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

func (Client) GetBit

func (c Client) GetBit(ctx context.Context, key string, offset int64) *IntCmd

func (Client) GetRange

func (c Client) GetRange(ctx context.Context, key string, start, end int64) *StringCmd

func (Client) GetSet

func (c Client) GetSet(ctx context.Context, key string, value interface{}) *StringCmd

func (Client) HDel

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

func (Client) HExists

func (c Client) HExists(ctx context.Context, key, field string) *BoolCmd

func (Client) HGet

func (c Client) HGet(ctx context.Context, key, field string) *StringCmd

func (Client) HGetAll

func (c Client) HGetAll(ctx context.Context, key string) *StringStringMapCmd

func (Client) HIncrBy

func (c Client) HIncrBy(ctx context.Context, key, field string, incr int64) *IntCmd

func (Client) HIncrByFloat

func (c Client) HIncrByFloat(ctx context.Context, key, field string, incr float64) *FloatCmd

func (Client) HKeys

func (c Client) HKeys(ctx context.Context, key string) *StringSliceCmd

func (Client) HLen

func (c Client) HLen(ctx context.Context, key string) *IntCmd

func (Client) HMGet

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

HMGet returns the values for the specified fields in the hash stored at key. It returns an interface{} to distinguish between empty string and nil value.

func (Client) HMSet

func (c Client) HMSet(ctx context.Context, key string, values ...interface{}) *BoolCmd

HMSet is a deprecated version of HSet left for compatibility with Redis 3.

func (Client) HScan

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

func (Client) HSet

func (c Client) HSet(ctx context.Context, key string, values ...interface{}) *IntCmd

HSet accepts values in following formats:

  • HSet("myhash", "key1", "value1", "key2", "value2")
  • HSet("myhash", []string{"key1", "value1", "key2", "value2"})
  • HSet("myhash", map[string]interface{}{"key1": "value1", "key2": "value2"})

Note that it requires Redis v4 for multiple field/value pairs support.

func (Client) HSetNX

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

func (Client) HVals

func (c Client) HVals(ctx context.Context, key string) *StringSliceCmd

func (Client) Incr

func (c Client) Incr(ctx context.Context, key string) *IntCmd
Example
result, err := rdb.Incr(ctx, "counter").Result()
if err != nil {
	panic(err)
}

fmt.Println(result)
Output:

1

func (Client) IncrBy

func (c Client) IncrBy(ctx context.Context, key string, value int64) *IntCmd

func (Client) IncrByFloat

func (c Client) IncrByFloat(ctx context.Context, key string, value float64) *FloatCmd

func (Client) Info

func (c Client) Info(ctx context.Context, section ...string) *StringCmd

func (Client) Keys

func (c Client) Keys(ctx context.Context, pattern string) *StringSliceCmd

func (Client) LIndex

func (c Client) LIndex(ctx context.Context, key string, index int64) *StringCmd

func (Client) LInsert

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

func (Client) LInsertAfter

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

func (Client) LInsertBefore

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

func (Client) LLen

func (c Client) LLen(ctx context.Context, key string) *IntCmd

func (Client) LPop

func (c Client) LPop(ctx context.Context, key string) *StringCmd

func (Client) LPos

func (c Client) LPos(ctx context.Context, key string, value string, a LPosArgs) *IntCmd

func (Client) LPosCount

func (c Client) LPosCount(ctx context.Context, key string, value string, count int64, a LPosArgs) *IntSliceCmd

func (Client) LPush

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

func (Client) LPushX

func (c Client) LPushX(ctx context.Context, key string, values ...interface{}) *IntCmd

func (Client) LRange

func (c Client) LRange(ctx context.Context, key string, start, stop int64) *StringSliceCmd

func (Client) LRem

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

func (Client) LSet

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

func (Client) LTrim

func (c Client) LTrim(ctx context.Context, key string, start, stop int64) *StatusCmd

func (Client) LastSave

func (c Client) LastSave(ctx context.Context) *IntCmd

func (Client) MGet

func (c Client) MGet(ctx context.Context, keys ...string) *SliceCmd

func (Client) MSet

func (c Client) MSet(ctx context.Context, values ...interface{}) *StatusCmd

MSet is like Set but accepts multiple values:

  • MSet("key1", "value1", "key2", "value2")
  • MSet([]string{"key1", "value1", "key2", "value2"})
  • MSet(map[string]interface{}{"key1": "value1", "key2": "value2"})

func (Client) MSetNX

func (c Client) MSetNX(ctx context.Context, values ...interface{}) *BoolCmd

MSetNX is like SetNX but accepts multiple values:

  • MSetNX("key1", "value1", "key2", "value2")
  • MSetNX([]string{"key1", "value1", "key2", "value2"})
  • MSetNX(map[string]interface{}{"key1": "value1", "key2": "value2"})

func (Client) MemoryUsage

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

func (Client) Migrate

func (c Client) Migrate(ctx context.Context, host, port, key string, db int, timeout time.Duration) *StatusCmd

func (Client) Move

func (c Client) Move(ctx context.Context, key string, db int) *BoolCmd

func (Client) ObjectEncoding

func (c Client) ObjectEncoding(ctx context.Context, key string) *StringCmd

func (Client) ObjectIdleTime

func (c Client) ObjectIdleTime(ctx context.Context, key string) *DurationCmd

func (Client) ObjectRefCount

func (c Client) ObjectRefCount(ctx context.Context, 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(ctx context.Context, key string, expiration time.Duration) *BoolCmd

func (Client) PExpireAt

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

func (Client) PFAdd

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

func (Client) PFCount

func (c Client) PFCount(ctx context.Context, keys ...string) *IntCmd

func (Client) PFMerge

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

func (*Client) PSubscribe

func (c *Client) PSubscribe(ctx context.Context, 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(ctx context.Context, key string) *DurationCmd

func (Client) Persist

func (c Client) Persist(ctx context.Context, key string) *BoolCmd

func (Client) Ping

func (c Client) Ping(ctx context.Context) *StatusCmd

func (*Client) Pipeline

func (c *Client) Pipeline() Pipeliner
Example
pipe := rdb.Pipeline()

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

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

1 <nil>

func (*Client) Pipelined

func (c *Client) Pipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmder, error)
Example
var incr *redis.IntCmd
_, err := rdb.Pipelined(ctx, func(pipe redis.Pipeliner) error {
	incr = pipe.Incr(ctx, "pipelined_counter")
	pipe.Expire(ctx, "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(ctx context.Context, cmd Cmder) error

func (Client) PubSubChannels

func (c Client) PubSubChannels(ctx context.Context, pattern string) *StringSliceCmd

func (Client) PubSubNumPat

func (c Client) PubSubNumPat(ctx context.Context) *IntCmd

func (Client) PubSubNumSub

func (c Client) PubSubNumSub(ctx context.Context, channels ...string) *StringIntMapCmd

func (Client) Publish

func (c Client) Publish(ctx context.Context, channel string, message interface{}) *IntCmd

Publish posts the message to the channel.

func (Client) Quit

func (c Client) Quit(ctx context.Context) *StatusCmd

func (Client) RPop

func (c Client) RPop(ctx context.Context, key string) *StringCmd

func (Client) RPopLPush

func (c Client) RPopLPush(ctx context.Context, source, destination string) *StringCmd

func (Client) RPush

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

func (Client) RPushX

func (c Client) RPushX(ctx context.Context, key string, values ...interface{}) *IntCmd

func (Client) RandomKey

func (c Client) RandomKey(ctx context.Context) *StringCmd

func (Client) ReadOnly

func (c Client) ReadOnly(ctx context.Context) *StatusCmd

func (Client) ReadWrite

func (c Client) ReadWrite(ctx context.Context) *StatusCmd

func (Client) Rename

func (c Client) Rename(ctx context.Context, key, newkey string) *StatusCmd

func (Client) RenameNX

func (c Client) RenameNX(ctx context.Context, key, newkey string) *BoolCmd

func (Client) Restore

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

func (Client) RestoreReplace

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

func (Client) SAdd

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

func (Client) SCard

func (c Client) SCard(ctx context.Context, key string) *IntCmd

func (Client) SDiff

func (c Client) SDiff(ctx context.Context, keys ...string) *StringSliceCmd

func (Client) SDiffStore

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

func (Client) SInter

func (c Client) SInter(ctx context.Context, keys ...string) *StringSliceCmd

func (Client) SInterStore

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

func (Client) SIsMember

func (c Client) SIsMember(ctx context.Context, key string, member interface{}) *BoolCmd

func (Client) SMembers

func (c Client) SMembers(ctx context.Context, key string) *StringSliceCmd

Redis `SMEMBERS key` command output as a slice.

func (Client) SMembersMap

func (c Client) SMembersMap(ctx context.Context, key string) *StringStructMapCmd

Redis `SMEMBERS key` command output as a map.

func (Client) SMove

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

func (Client) SPop

func (c Client) SPop(ctx context.Context, key string) *StringCmd

Redis `SPOP key` command.

func (Client) SPopN

func (c Client) SPopN(ctx context.Context, key string, count int64) *StringSliceCmd

Redis `SPOP key count` command.

func (Client) SRandMember

func (c Client) SRandMember(ctx context.Context, key string) *StringCmd

Redis `SRANDMEMBER key` command.

func (Client) SRandMemberN

func (c Client) SRandMemberN(ctx context.Context, key string, count int64) *StringSliceCmd

Redis `SRANDMEMBER key count` command.

func (Client) SRem

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

func (Client) SScan

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

func (Client) SUnion

func (c Client) SUnion(ctx context.Context, keys ...string) *StringSliceCmd

func (Client) SUnionStore

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

func (Client) Save

func (c Client) Save(ctx context.Context) *StatusCmd

func (Client) Scan

func (c Client) Scan(ctx context.Context, cursor uint64, match string, keyType string, count int64) *ScanCmd
Example
rdb.FlushDB(ctx)
for i := 0; i < 33; i++ {
	err := rdb.Set(ctx, 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 = rdb.Scan(ctx, 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(ctx context.Context, hashes ...string) *BoolSliceCmd

func (Client) ScriptFlush

func (c Client) ScriptFlush(ctx context.Context) *StatusCmd

func (Client) ScriptKill

func (c Client) ScriptKill(ctx context.Context) *StatusCmd

func (Client) ScriptLoad

func (c Client) ScriptLoad(ctx context.Context, script string) *StringCmd

func (Client) Set

func (c Client) Set(ctx context.Context, 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. KeepTTL(-1) expiration is a Redis KEEPTTL option to keep existing TTL.

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

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

func (Client) SetBit

func (c Client) SetBit(ctx context.Context, key string, offset int64, value int) *IntCmd

func (Client) SetEX

func (c Client) SetEX(ctx context.Context, key string, value interface{}, expiration time.Duration) *StatusCmd

Redis `SETEX key expiration value` command.

Example
err := rdb.SetEX(ctx, "key", "value", time.Hour).Err()
if err != nil {
	panic(err)
}
Output:

func (Client) SetNX

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

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

Zero expiration means the key has no expiration time. KeepTTL(-1) expiration is a Redis KEEPTTL option to keep existing TTL.

func (Client) SetRange

func (c Client) SetRange(ctx context.Context, key string, offset int64, value string) *IntCmd

func (Client) SetXX

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

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

Zero expiration means the key has no expiration time. KeepTTL(-1) expiration is a Redis KEEPTTL option to keep existing TTL.

func (Client) Shutdown

func (c Client) Shutdown(ctx context.Context) *StatusCmd

func (Client) ShutdownNoSave

func (c Client) ShutdownNoSave(ctx context.Context) *StatusCmd

func (Client) ShutdownSave

func (c Client) ShutdownSave(ctx context.Context) *StatusCmd

func (Client) SlaveOf

func (c Client) SlaveOf(ctx context.Context, host, port string) *StatusCmd

func (Client) SlowLogGet

func (c Client) SlowLogGet(ctx context.Context, num int64) *SlowLogCmd
Example
const key = "slowlog-log-slower-than"

old := rdb.ConfigGet(ctx, key).Val()
rdb.ConfigSet(ctx, key, "0")
defer rdb.ConfigSet(ctx, key, old[1].(string))

if err := rdb.Do(ctx, "slowlog", "reset").Err(); err != nil {
	panic(err)
}

rdb.Set(ctx, "test", "true", 0)

result, err := rdb.SlowLogGet(ctx, -1).Result()
if err != nil {
	panic(err)
}
fmt.Println(len(result))
Output:

2

func (Client) Sort

func (c Client) Sort(ctx context.Context, key string, sort *Sort) *StringSliceCmd

func (Client) SortInterfaces

func (c Client) SortInterfaces(ctx context.Context, key string, sort *Sort) *SliceCmd

func (Client) SortStore

func (c Client) SortStore(ctx context.Context, key, store string, sort *Sort) *IntCmd

func (Client) StrLen

func (c Client) StrLen(ctx context.Context, key string) *IntCmd

func (Client) String

func (c Client) String() string

func (*Client) Subscribe

func (c *Client) Subscribe(ctx context.Context, 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(ctx context.Context)

func (Client) TTL

func (c Client) TTL(ctx context.Context, key string) *DurationCmd

func (Client) Time

func (c Client) Time(ctx context.Context) *TimeCmd

func (Client) Touch

func (c Client) Touch(ctx context.Context, keys ...string) *IntCmd

func (*Client) TxPipeline

func (c *Client) TxPipeline() Pipeliner

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

Example
pipe := rdb.TxPipeline()

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

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

1 <nil>

func (*Client) TxPipelined

func (c *Client) TxPipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmder, error)
Example
var incr *redis.IntCmd
_, err := rdb.TxPipelined(ctx, func(pipe redis.Pipeliner) error {
	incr = pipe.Incr(ctx, "tx_pipelined_counter")
	pipe.Expire(ctx, "tx_pipelined_counter", time.Hour)
	return nil
})
fmt.Println(incr.Val(), err)
Output:

1 <nil>

func (Client) Type

func (c Client) Type(ctx context.Context, key string) *StatusCmd
func (c Client) Unlink(ctx context.Context, keys ...string) *IntCmd

func (Client) Wait

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

func (*Client) Watch

func (c *Client) Watch(ctx context.Context, 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
const maxRetries = 1000

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

		// Actual opperation (local in optimistic lock).
		n++

		// Operation is commited only if the watched keys remain unchanged.
		_, err = tx.TxPipelined(ctx, func(pipe redis.Pipeliner) error {
			pipe.Set(ctx, key, n, 0)
			return nil
		})
		return err
	}

	for i := 0; i < maxRetries; i++ {
		err := rdb.Watch(ctx, txf, key)
		if err == nil {
			// Success.
			return nil
		}
		if err == redis.TxFailedErr {
			// Optimistic lock lost. Retry.
			continue
		}
		// Return any other error.
		return err
	}

	return errors.New("increment reached maximum number of retries")
}

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

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

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

ended with 100 <nil>
Example (Instrumentation)
rdb := redis.NewClient(&redis.Options{
	Addr: ":6379",
})
rdb.AddHook(redisHook{})

rdb.Watch(ctx, func(tx *redis.Tx) error {
	tx.Ping(ctx)
	tx.Ping(ctx)
	return nil
}, "foo")
Output:

starting processing: <watch foo: >
finished processing: <watch foo: OK>
starting processing: <ping: >
finished processing: <ping: PONG>
starting processing: <ping: >
finished processing: <ping: PONG>
starting processing: <unwatch: >
finished processing: <unwatch: OK>

func (*Client) WithContext

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

func (*Client) WithTimeout

func (c *Client) WithTimeout(timeout time.Duration) *Client

func (Client) XAck

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

func (Client) XAdd

func (c Client) XAdd(ctx context.Context, a *XAddArgs) *StringCmd

func (Client) XClaim

func (c Client) XClaim(ctx context.Context, a *XClaimArgs) *XMessageSliceCmd

func (Client) XClaimJustID

func (c Client) XClaimJustID(ctx context.Context, a *XClaimArgs) *StringSliceCmd

func (Client) XDel

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

func (Client) XGroupCreate

func (c Client) XGroupCreate(ctx context.Context, stream, group, start string) *StatusCmd

func (Client) XGroupCreateMkStream

func (c Client) XGroupCreateMkStream(ctx context.Context, stream, group, start string) *StatusCmd

func (Client) XGroupDelConsumer

func (c Client) XGroupDelConsumer(ctx context.Context, stream, group, consumer string) *IntCmd

func (Client) XGroupDestroy

func (c Client) XGroupDestroy(ctx context.Context, stream, group string) *IntCmd

func (Client) XGroupSetID

func (c Client) XGroupSetID(ctx context.Context, stream, group, start string) *StatusCmd

func (Client) XInfoGroups

func (c Client) XInfoGroups(ctx context.Context, key string) *XInfoGroupsCmd

func (Client) XInfoStream

func (c Client) XInfoStream(ctx context.Context, key string) *XInfoStreamCmd

func (Client) XLen

func (c Client) XLen(ctx context.Context, stream string) *IntCmd

func (Client) XPending

func (c Client) XPending(ctx context.Context, stream, group string) *XPendingCmd

func (Client) XPendingExt

func (c Client) XPendingExt(ctx context.Context, a *XPendingExtArgs) *XPendingExtCmd

func (Client) XRange

func (c Client) XRange(ctx context.Context, stream, start, stop string) *XMessageSliceCmd

func (Client) XRangeN

func (c Client) XRangeN(ctx context.Context, stream, start, stop string, count int64) *XMessageSliceCmd

func (Client) XRead

func (c Client) XRead(ctx context.Context, a *XReadArgs) *XStreamSliceCmd

func (Client) XReadGroup

func (c Client) XReadGroup(ctx context.Context, a *XReadGroupArgs) *XStreamSliceCmd

func (Client) XReadStreams

func (c Client) XReadStreams(ctx context.Context, streams ...string) *XStreamSliceCmd

func (Client) XRevRange

func (c Client) XRevRange(ctx context.Context, stream, start, stop string) *XMessageSliceCmd

func (Client) XRevRangeN

func (c Client) XRevRangeN(ctx context.Context, stream, start, stop string, count int64) *XMessageSliceCmd

func (Client) XTrim

func (c Client) XTrim(ctx context.Context, key string, maxLen int64) *IntCmd

func (Client) XTrimApprox

func (c Client) XTrimApprox(ctx context.Context, key string, maxLen int64) *IntCmd

func (Client) ZAdd

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

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

func (Client) ZAddCh

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

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

func (Client) ZAddNX

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

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

func (Client) ZAddNXCh

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

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

func (Client) ZAddXX

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

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

func (Client) ZAddXXCh

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

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

func (Client) ZCard

func (c Client) ZCard(ctx context.Context, key string) *IntCmd

func (Client) ZCount

func (c Client) ZCount(ctx context.Context, key, min, max string) *IntCmd

func (Client) ZIncr

func (c Client) ZIncr(ctx context.Context, key string, member *Z) *FloatCmd

Redis `ZADD key INCR score member` command.

func (Client) ZIncrBy

func (c Client) ZIncrBy(ctx context.Context, key string, increment float64, member string) *FloatCmd

func (Client) ZIncrNX

func (c Client) ZIncrNX(ctx context.Context, key string, member *Z) *FloatCmd

Redis `ZADD key NX INCR score member` command.

func (Client) ZIncrXX

func (c Client) ZIncrXX(ctx context.Context, key string, member *Z) *FloatCmd

Redis `ZADD key XX INCR score member` command.

func (Client) ZInterStore

func (c Client) ZInterStore(ctx context.Context, destination string, store *ZStore) *IntCmd

func (Client) ZLexCount

func (c Client) ZLexCount(ctx context.Context, key, min, max string) *IntCmd

func (Client) ZPopMax

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

func (Client) ZPopMin

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

func (Client) ZRange

func (c Client) ZRange(ctx context.Context, key string, start, stop int64) *StringSliceCmd

func (Client) ZRangeByLex

func (c Client) ZRangeByLex(ctx context.Context, key string, opt *ZRangeBy) *StringSliceCmd

func (Client) ZRangeByScore

func (c Client) ZRangeByScore(ctx context.Context, key string, opt *ZRangeBy) *StringSliceCmd

func (Client) ZRangeByScoreWithScores

func (c Client) ZRangeByScoreWithScores(ctx context.Context, key string, opt *ZRangeBy) *ZSliceCmd

func (Client) ZRangeWithScores

func (c Client) ZRangeWithScores(ctx context.Context, key string, start, stop int64) *ZSliceCmd

func (Client) ZRank

func (c Client) ZRank(ctx context.Context, key, member string) *IntCmd

func (Client) ZRem

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

func (Client) ZRemRangeByLex

func (c Client) ZRemRangeByLex(ctx context.Context, key, min, max string) *IntCmd

func (Client) ZRemRangeByRank

func (c Client) ZRemRangeByRank(ctx context.Context, key string, start, stop int64) *IntCmd

func (Client) ZRemRangeByScore

func (c Client) ZRemRangeByScore(ctx context.Context, key, min, max string) *IntCmd

func (Client) ZRevRange

func (c Client) ZRevRange(ctx context.Context, key string, start, stop int64) *StringSliceCmd

func (Client) ZRevRangeByLex

func (c Client) ZRevRangeByLex(ctx context.Context, key string, opt *ZRangeBy) *StringSliceCmd

func (Client) ZRevRangeByScore

func (c Client) ZRevRangeByScore(ctx context.Context, key string, opt *ZRangeBy) *StringSliceCmd

func (Client) ZRevRangeByScoreWithScores

func (c Client) ZRevRangeByScoreWithScores(ctx context.Context, key string, opt *ZRangeBy) *ZSliceCmd

func (Client) ZRevRangeWithScores

func (c Client) ZRevRangeWithScores(ctx context.Context, key string, start, stop int64) *ZSliceCmd

func (Client) ZRevRank

func (c Client) ZRevRank(ctx context.Context, key, member string) *IntCmd

func (Client) ZScan

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

func (Client) ZScore

func (c Client) ZScore(ctx context.Context, key, member string) *FloatCmd

func (Client) ZUnionStore

func (c Client) ZUnionStore(ctx context.Context, dest string, store *ZStore) *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
// See http://redis.io/topics/cluster-tutorial for instructions
// how to setup Redis Cluster.
rdb := redis.NewClusterClient(&redis.ClusterOptions{
	Addrs: []string{":7000", ":7001", ":7002", ":7003", ":7004", ":7005"},
})
rdb.Ping(ctx)
Output:

Example (ManualSetup)

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

// 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(ctx context.Context) ([]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
}

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

// ReloadState reloads cluster state. It calls ClusterSlots func
// to get cluster slots information.
rdb.ReloadState(ctx)
Output:

func NewFailoverClusterClient

func NewFailoverClusterClient(failoverOpt *FailoverOptions) *ClusterClient

NewFailoverClusterClient returns a client that supports routing read-only commands to a slave node.

func (*ClusterClient) AddHook

func (hs *ClusterClient) AddHook(hook Hook)

func (ClusterClient) Append

func (c ClusterClient) Append(ctx context.Context, key, value string) *IntCmd

func (ClusterClient) BLPop

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

func (ClusterClient) BRPop

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

func (ClusterClient) BRPopLPush

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

func (ClusterClient) BZPopMax

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

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

func (ClusterClient) BZPopMin

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

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

func (ClusterClient) BgRewriteAOF

func (c ClusterClient) BgRewriteAOF(ctx context.Context) *StatusCmd

func (ClusterClient) BgSave

func (c ClusterClient) BgSave(ctx context.Context) *StatusCmd

func (ClusterClient) BitCount

func (c ClusterClient) BitCount(ctx context.Context, key string, bitCount *BitCount) *IntCmd

func (ClusterClient) BitField

func (c ClusterClient) BitField(ctx context.Context, key string, args ...interface{}) *IntSliceCmd

func (ClusterClient) BitOpAnd

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

func (ClusterClient) BitOpNot

func (c ClusterClient) BitOpNot(ctx context.Context, destKey string, key string) *IntCmd

func (ClusterClient) BitOpOr

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

func (ClusterClient) BitOpXor

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

func (ClusterClient) BitPos

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

func (ClusterClient) ClientGetName

func (c ClusterClient) ClientGetName(ctx context.Context) *StringCmd

ClientGetName returns the name of the connection.

func (ClusterClient) ClientID

func (c ClusterClient) ClientID(ctx context.Context) *IntCmd

func (ClusterClient) ClientKill

func (c ClusterClient) ClientKill(ctx context.Context, ipPort string) *StatusCmd

func (ClusterClient) ClientKillByFilter

func (c ClusterClient) ClientKillByFilter(ctx context.Context, keys ...string) *IntCmd

ClientKillByFilter is new style syntax, while the ClientKill is old

CLIENT KILL <option> [value] ... <option> [value]

func (ClusterClient) ClientList

func (c ClusterClient) ClientList(ctx context.Context) *StringCmd

func (ClusterClient) ClientPause

func (c ClusterClient) ClientPause(ctx context.Context, dur time.Duration) *BoolCmd

func (ClusterClient) ClientUnblock

func (c ClusterClient) ClientUnblock(ctx context.Context, id int64) *IntCmd

func (ClusterClient) ClientUnblockWithError

func (c ClusterClient) ClientUnblockWithError(ctx context.Context, 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(ctx context.Context, slots ...int) *StatusCmd

func (ClusterClient) ClusterAddSlotsRange

func (c ClusterClient) ClusterAddSlotsRange(ctx context.Context, min, max int) *StatusCmd

func (ClusterClient) ClusterCountFailureReports

func (c ClusterClient) ClusterCountFailureReports(ctx context.Context, nodeID string) *IntCmd

func (ClusterClient) ClusterCountKeysInSlot

func (c ClusterClient) ClusterCountKeysInSlot(ctx context.Context, slot int) *IntCmd

func (ClusterClient) ClusterDelSlots

func (c ClusterClient) ClusterDelSlots(ctx context.Context, slots ...int) *StatusCmd

func (ClusterClient) ClusterDelSlotsRange

func (c ClusterClient) ClusterDelSlotsRange(ctx context.Context, min, max int) *StatusCmd

func (ClusterClient) ClusterFailover

func (c ClusterClient) ClusterFailover(ctx context.Context) *StatusCmd

func (ClusterClient) ClusterForget

func (c ClusterClient) ClusterForget(ctx context.Context, nodeID string) *StatusCmd

func (ClusterClient) ClusterGetKeysInSlot

func (c ClusterClient) ClusterGetKeysInSlot(ctx context.Context, slot int, count int) *StringSliceCmd

func (ClusterClient) ClusterInfo

func (c ClusterClient) ClusterInfo(ctx context.Context) *StringCmd

func (ClusterClient) ClusterKeySlot

func (c ClusterClient) ClusterKeySlot(ctx context.Context, key string) *IntCmd

func (ClusterClient) ClusterMeet

func (c ClusterClient) ClusterMeet(ctx context.Context, host, port string) *StatusCmd

func (ClusterClient) ClusterNodes

func (c ClusterClient) ClusterNodes(ctx context.Context) *StringCmd

func (ClusterClient) ClusterReplicate

func (c ClusterClient) ClusterReplicate(ctx context.Context, nodeID string) *StatusCmd

func (ClusterClient) ClusterResetHard

func (c ClusterClient) ClusterResetHard(ctx context.Context) *StatusCmd

func (ClusterClient) ClusterResetSoft

func (c ClusterClient) ClusterResetSoft(ctx context.Context) *StatusCmd

func (ClusterClient) ClusterSaveConfig

func (c ClusterClient) ClusterSaveConfig(ctx context.Context) *StatusCmd

func (ClusterClient) ClusterSlaves

func (c ClusterClient) ClusterSlaves(ctx context.Context, nodeID string) *StringSliceCmd

func (ClusterClient) ClusterSlots

func (c ClusterClient) ClusterSlots(ctx context.Context) *ClusterSlotsCmd

func (ClusterClient) Command

func (c ClusterClient) Command(ctx context.Context) *CommandsInfoCmd

func (ClusterClient) ConfigGet

func (c ClusterClient) ConfigGet(ctx context.Context, parameter string) *SliceCmd

func (ClusterClient) ConfigResetStat

func (c ClusterClient) ConfigResetStat(ctx context.Context) *StatusCmd

func (ClusterClient) ConfigRewrite

func (c ClusterClient) ConfigRewrite(ctx context.Context) *StatusCmd

func (ClusterClient) ConfigSet

func (c ClusterClient) ConfigSet(ctx context.Context, parameter, value string) *StatusCmd

func (*ClusterClient) Context

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

func (*ClusterClient) DBSize

func (c *ClusterClient) DBSize(ctx context.Context) *IntCmd

func (ClusterClient) DebugObject

func (c ClusterClient) DebugObject(ctx context.Context, key string) *StringCmd

func (ClusterClient) Decr

func (c ClusterClient) Decr(ctx context.Context, key string) *IntCmd

func (ClusterClient) DecrBy

func (c ClusterClient) DecrBy(ctx context.Context, key string, decrement int64) *IntCmd

func (ClusterClient) Del

func (c ClusterClient) Del(ctx context.Context, keys ...string) *IntCmd

func (*ClusterClient) Do

func (c *ClusterClient) Do(ctx context.Context, args ...interface{}) *Cmd

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

func (ClusterClient) Dump

func (c ClusterClient) Dump(ctx context.Context, key string) *StringCmd

func (ClusterClient) Echo

func (c ClusterClient) Echo(ctx context.Context, message interface{}) *StringCmd

func (ClusterClient) Eval

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

func (ClusterClient) EvalSha

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

func (ClusterClient) Exists

func (c ClusterClient) Exists(ctx context.Context, keys ...string) *IntCmd

func (ClusterClient) Expire

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

func (ClusterClient) ExpireAt

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

func (ClusterClient) FlushAll

func (c ClusterClient) FlushAll(ctx context.Context) *StatusCmd

func (ClusterClient) FlushAllAsync

func (c ClusterClient) FlushAllAsync(ctx context.Context) *StatusCmd

func (ClusterClient) FlushDB

func (c ClusterClient) FlushDB(ctx context.Context) *StatusCmd

func (ClusterClient) FlushDBAsync

func (c ClusterClient) FlushDBAsync(ctx context.Context) *StatusCmd

func (*ClusterClient) ForEachMaster

func (c *ClusterClient) ForEachMaster(
	ctx context.Context,
	fn func(ctx context.Context, 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) ForEachShard

func (c *ClusterClient) ForEachShard(
	ctx context.Context,
	fn func(ctx context.Context, client *Client) error,
) error

ForEachShard 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(
	ctx context.Context,
	fn func(ctx context.Context, 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(ctx context.Context, key string, geoLocation ...*GeoLocation) *IntCmd

func (ClusterClient) GeoDist

func (c ClusterClient) GeoDist(
	ctx context.Context, key string, member1, member2, unit string,
) *FloatCmd

func (ClusterClient) GeoHash

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

func (ClusterClient) GeoPos

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

func (ClusterClient) GeoRadius

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

GeoRadius is a read-only GEORADIUS_RO command.

func (ClusterClient) GeoRadiusByMember

func (c ClusterClient) GeoRadiusByMember(
	ctx context.Context, key, member string, query *GeoRadiusQuery,
) *GeoLocationCmd

GeoRadius is a read-only GEORADIUSBYMEMBER_RO command.

func (ClusterClient) GeoRadiusByMemberStore

func (c ClusterClient) GeoRadiusByMemberStore(
	ctx context.Context, key, member string, query *GeoRadiusQuery,
) *IntCmd

GeoRadiusByMemberStore is a writing GEORADIUSBYMEMBER command.

func (ClusterClient) GeoRadiusStore

func (c ClusterClient) GeoRadiusStore(
	ctx context.Context, key string, longitude, latitude float64, query *GeoRadiusQuery,
) *IntCmd

GeoRadiusStore is a writing GEORADIUS command.

func (ClusterClient) Get

func (c ClusterClient) Get(ctx context.Context, key string) *StringCmd

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

func (ClusterClient) GetBit

func (c ClusterClient) GetBit(ctx context.Context, key string, offset int64) *IntCmd

func (ClusterClient) GetRange

func (c ClusterClient) GetRange(ctx context.Context, key string, start, end int64) *StringCmd

func (ClusterClient) GetSet

func (c ClusterClient) GetSet(ctx context.Context, key string, value interface{}) *StringCmd

func (ClusterClient) HDel

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

func (ClusterClient) HExists

func (c ClusterClient) HExists(ctx context.Context, key, field string) *BoolCmd

func (ClusterClient) HGet

func (c ClusterClient) HGet(ctx context.Context, key, field string) *StringCmd

func (ClusterClient) HGetAll

func (c ClusterClient) HGetAll(ctx context.Context, key string) *StringStringMapCmd

func (ClusterClient) HIncrBy

func (c ClusterClient) HIncrBy(ctx context.Context, key, field string, incr int64) *IntCmd

func (ClusterClient) HIncrByFloat

func (c ClusterClient) HIncrByFloat(ctx context.Context, key, field string, incr float64) *FloatCmd

func (ClusterClient) HKeys

func (c ClusterClient) HKeys(ctx context.Context, key string) *StringSliceCmd

func (ClusterClient) HLen

func (c ClusterClient) HLen(ctx context.Context, key string) *IntCmd

func (ClusterClient) HMGet

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

HMGet returns the values for the specified fields in the hash stored at key. It returns an interface{} to distinguish between empty string and nil value.

func (ClusterClient) HMSet

func (c ClusterClient) HMSet(ctx context.Context, key string, values ...interface{}) *BoolCmd

HMSet is a deprecated version of HSet left for compatibility with Redis 3.

func (ClusterClient) HScan

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

func (ClusterClient) HSet

func (c ClusterClient) HSet(ctx context.Context, key string, values ...interface{}) *IntCmd

HSet accepts values in following formats:

  • HSet("myhash", "key1", "value1", "key2", "value2")
  • HSet("myhash", []string{"key1", "value1", "key2", "value2"})
  • HSet("myhash", map[string]interface{}{"key1": "value1", "key2": "value2"})

Note that it requires Redis v4 for multiple field/value pairs support.

func (ClusterClient) HSetNX

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

func (ClusterClient) HVals

func (c ClusterClient) HVals(ctx context.Context, key string) *StringSliceCmd

func (ClusterClient) Incr

func (c ClusterClient) Incr(ctx context.Context, key string) *IntCmd

func (ClusterClient) IncrBy

func (c ClusterClient) IncrBy(ctx context.Context, key string, value int64) *IntCmd

func (ClusterClient) IncrByFloat

func (c ClusterClient) IncrByFloat(ctx context.Context, key string, value float64) *FloatCmd

func (ClusterClient) Info

func (c ClusterClient) Info(ctx context.Context, section ...string) *StringCmd

func (ClusterClient) Keys

func (c ClusterClient) Keys(ctx context.Context, pattern string) *StringSliceCmd

func (ClusterClient) LIndex

func (c ClusterClient) LIndex(ctx context.Context, key string, index int64) *StringCmd

func (ClusterClient) LInsert

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

func (ClusterClient) LInsertAfter

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

func (ClusterClient) LInsertBefore

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

func (ClusterClient) LLen

func (c ClusterClient) LLen(ctx context.Context, key string) *IntCmd

func (ClusterClient) LPop

func (c ClusterClient) LPop(ctx context.Context, key string) *StringCmd

func (ClusterClient) LPos

func (c ClusterClient) LPos(ctx context.Context, key string, value string, a LPosArgs) *IntCmd

func (ClusterClient) LPosCount

func (c ClusterClient) LPosCount(ctx context.Context, key string, value string, count int64, a LPosArgs) *IntSliceCmd

func (ClusterClient) LPush

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

func (ClusterClient) LPushX

func (c ClusterClient) LPushX(ctx context.Context, key string, values ...interface{}) *IntCmd

func (ClusterClient) LRange

func (c ClusterClient) LRange(ctx context.Context, key string, start, stop int64) *StringSliceCmd

func (ClusterClient) LRem

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

func (ClusterClient) LSet

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

func (ClusterClient) LTrim

func (c ClusterClient) LTrim(ctx context.Context, key string, start, stop int64) *StatusCmd

func (ClusterClient) LastSave

func (c ClusterClient) LastSave(ctx context.Context) *IntCmd

func (ClusterClient) MGet

func (c ClusterClient) MGet(ctx context.Context, keys ...string) *SliceCmd

func (ClusterClient) MSet

func (c ClusterClient) MSet(ctx context.Context, values ...interface{}) *StatusCmd

MSet is like Set but accepts multiple values:

  • MSet("key1", "value1", "key2", "value2")
  • MSet([]string{"key1", "value1", "key2", "value2"})
  • MSet(map[string]interface{}{"key1": "value1", "key2": "value2"})

func (ClusterClient) MSetNX

func (c ClusterClient) MSetNX(ctx context.Context, values ...interface{}) *BoolCmd

MSetNX is like SetNX but accepts multiple values:

  • MSetNX("key1", "value1", "key2", "value2")
  • MSetNX([]string{"key1", "value1", "key2", "value2"})
  • MSetNX(map[string]interface{}{"key1": "value1", "key2": "value2"})

func (*ClusterClient) MasterForKey

func (c *ClusterClient) MasterForKey(ctx context.Context, key string) (*Client, error)

MasterForKey return a client to the master node for a particular key.

func (ClusterClient) MemoryUsage

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

func (ClusterClient) Migrate

func (c ClusterClient) Migrate(ctx context.Context, host, port, key string, db int, timeout time.Duration) *StatusCmd

func (ClusterClient) Move

func (c ClusterClient) Move(ctx context.Context, key string, db int) *BoolCmd

func (ClusterClient) ObjectEncoding

func (c ClusterClient) ObjectEncoding(ctx context.Context, key string) *StringCmd

func (ClusterClient) ObjectIdleTime

func (c ClusterClient) ObjectIdleTime(ctx context.Context, key string) *DurationCmd

func (ClusterClient) ObjectRefCount

func (c ClusterClient) ObjectRefCount(ctx context.Context, 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(ctx context.Context, key string, expiration time.Duration) *BoolCmd

func (ClusterClient) PExpireAt

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

func (ClusterClient) PFAdd

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

func (ClusterClient) PFCount

func (c ClusterClient) PFCount(ctx context.Context, keys ...string) *IntCmd

func (ClusterClient) PFMerge

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

func (*ClusterClient) PSubscribe

func (c *ClusterClient) PSubscribe(ctx context.Context, 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(ctx context.Context, key string) *DurationCmd

func (ClusterClient) Persist

func (c ClusterClient) Persist(ctx context.Context, key string) *BoolCmd

func (ClusterClient) Ping

func (c ClusterClient) Ping(ctx context.Context) *StatusCmd

func (*ClusterClient) Pipeline

func (c *ClusterClient) Pipeline() Pipeliner

func (*ClusterClient) Pipelined

func (c *ClusterClient) Pipelined(ctx context.Context, 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(ctx context.Context, cmd Cmder) error

func (ClusterClient) PubSubChannels

func (c ClusterClient) PubSubChannels(ctx context.Context, pattern string) *StringSliceCmd

func (ClusterClient) PubSubNumPat

func (c ClusterClient) PubSubNumPat(ctx context.Context) *IntCmd

func (ClusterClient) PubSubNumSub

func (c ClusterClient) PubSubNumSub(ctx context.Context, channels ...string) *StringIntMapCmd

func (ClusterClient) Publish

func (c ClusterClient) Publish(ctx context.Context, channel string, message interface{}) *IntCmd

Publish posts the message to the channel.

func (ClusterClient) Quit

func (c ClusterClient) Quit(ctx context.Context) *StatusCmd

func (ClusterClient) RPop

func (c ClusterClient) RPop(ctx context.Context, key string) *StringCmd

func (ClusterClient) RPopLPush

func (c ClusterClient) RPopLPush(ctx context.Context, source, destination string) *StringCmd

func (ClusterClient) RPush

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

func (ClusterClient) RPushX

func (c ClusterClient) RPushX(ctx context.Context, key string, values ...interface{}) *IntCmd

func (ClusterClient) RandomKey

func (c ClusterClient) RandomKey(ctx context.Context) *StringCmd

func (ClusterClient) ReadOnly

func (c ClusterClient) ReadOnly(ctx context.Context) *StatusCmd

func (ClusterClient) ReadWrite

func (c ClusterClient) ReadWrite(ctx context.Context) *StatusCmd

func (*ClusterClient) ReloadState

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

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

func (ClusterClient) Rename

func (c ClusterClient) Rename(ctx context.Context, key, newkey string) *StatusCmd

func (ClusterClient) RenameNX

func (c ClusterClient) RenameNX(ctx context.Context, key, newkey string) *BoolCmd

func (ClusterClient) Restore

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

func (ClusterClient) RestoreReplace

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

func (ClusterClient) SAdd

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

func (ClusterClient) SCard

func (c ClusterClient) SCard(ctx context.Context, key string) *IntCmd

func (ClusterClient) SDiff

func (c ClusterClient) SDiff(ctx context.Context, keys ...string) *StringSliceCmd

func (ClusterClient) SDiffStore

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

func (ClusterClient) SInter

func (c ClusterClient) SInter(ctx context.Context, keys ...string) *StringSliceCmd

func (ClusterClient) SInterStore

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

func (ClusterClient) SIsMember

func (c ClusterClient) SIsMember(ctx context.Context, key string, member interface{}) *BoolCmd

func (ClusterClient) SMembers

func (c ClusterClient) SMembers(ctx context.Context, key string) *StringSliceCmd

Redis `SMEMBERS key` command output as a slice.

func (ClusterClient) SMembersMap

func (c ClusterClient) SMembersMap(ctx context.Context, key string) *StringStructMapCmd

Redis `SMEMBERS key` command output as a map.

func (ClusterClient) SMove

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

func (ClusterClient) SPop

func (c ClusterClient) SPop(ctx context.Context, key string) *StringCmd

Redis `SPOP key` command.

func (ClusterClient) SPopN

func (c ClusterClient) SPopN(ctx context.Context, key string, count int64) *StringSliceCmd

Redis `SPOP key count` command.

func (ClusterClient) SRandMember

func (c ClusterClient) SRandMember(ctx context.Context, key string) *StringCmd

Redis `SRANDMEMBER key` command.

func (ClusterClient) SRandMemberN

func (c ClusterClient) SRandMemberN(ctx context.Context, key string, count int64) *StringSliceCmd

Redis `SRANDMEMBER key count` command.

func (ClusterClient) SRem

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

func (ClusterClient) SScan

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

func (ClusterClient) SUnion

func (c ClusterClient) SUnion(ctx context.Context, keys ...string) *StringSliceCmd

func (ClusterClient) SUnionStore

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

func (ClusterClient) Save

func (c ClusterClient) Save(ctx context.Context) *StatusCmd

func (ClusterClient) Scan

func (c ClusterClient) Scan(ctx context.Context, cursor uint64, match string, keyType string, count int64) *ScanCmd

func (ClusterClient) ScriptExists

func (c ClusterClient) ScriptExists(ctx context.Context, hashes ...string) *BoolSliceCmd

func (ClusterClient) ScriptFlush

func (c ClusterClient) ScriptFlush(ctx context.Context) *StatusCmd

func (ClusterClient) ScriptKill

func (c ClusterClient) ScriptKill(ctx context.Context) *StatusCmd

func (ClusterClient) ScriptLoad

func (c ClusterClient) ScriptLoad(ctx context.Context, script string) *StringCmd

func (ClusterClient) Set

func (c ClusterClient) Set(ctx context.Context, 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. KeepTTL(-1) expiration is a Redis KEEPTTL option to keep existing TTL.

func (ClusterClient) SetBit

func (c ClusterClient) SetBit(ctx context.Context, key string, offset int64, value int) *IntCmd

func (ClusterClient) SetEX

func (c ClusterClient) SetEX(ctx context.Context, key string, value interface{}, expiration time.Duration) *StatusCmd

Redis `SETEX key expiration value` command.

func (ClusterClient) SetNX

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

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

Zero expiration means the key has no expiration time. KeepTTL(-1) expiration is a Redis KEEPTTL option to keep existing TTL.

func (ClusterClient) SetRange

func (c ClusterClient) SetRange(ctx context.Context, key string, offset int64, value string) *IntCmd

func (ClusterClient) SetXX

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

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

Zero expiration means the key has no expiration time. KeepTTL(-1) expiration is a Redis KEEPTTL option to keep existing TTL.

func (ClusterClient) Shutdown

func (c ClusterClient) Shutdown(ctx context.Context) *StatusCmd

func (ClusterClient) ShutdownNoSave

func (c ClusterClient) ShutdownNoSave(ctx context.Context) *StatusCmd

func (ClusterClient) ShutdownSave

func (c ClusterClient) ShutdownSave(ctx context.Context) *StatusCmd

func (*ClusterClient) SlaveForKey

func (c *ClusterClient) SlaveForKey(ctx context.Context, key string) (*Client, error)

SlaveForKey gets a client for a replica node to run any command on it. This is especially useful if we want to run a particular lua script which has only read only commands on the replica. This is because other redis commands generally have a flag that points that they are read only and automatically run on the replica nodes if ClusterOptions.ReadOnly flag is set to true.

func (ClusterClient) SlaveOf

func (c ClusterClient) SlaveOf(ctx context.Context, host, port string) *StatusCmd

func (ClusterClient) SlowLogGet

func (c ClusterClient) SlowLogGet(ctx context.Context, num int64) *SlowLogCmd

func (ClusterClient) Sort

func (c ClusterClient) Sort(ctx context.Context, key string, sort *Sort) *StringSliceCmd

func (ClusterClient) SortInterfaces

func (c ClusterClient) SortInterfaces(ctx context.Context, key string, sort *Sort) *SliceCmd

func (ClusterClient) SortStore

func (c ClusterClient) SortStore(ctx context.Context, key, store string, sort *Sort) *IntCmd

func (ClusterClient) StrLen

func (c ClusterClient) StrLen(ctx context.Context, key string) *IntCmd

func (*ClusterClient) Subscribe

func (c *ClusterClient) Subscribe(ctx context.Context, 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(ctx context.Context)

func (ClusterClient) TTL

func (c ClusterClient) TTL(ctx context.Context, key string) *DurationCmd

func (ClusterClient) Time

func (c ClusterClient) Time(ctx context.Context) *TimeCmd

func (ClusterClient) Touch

func (c ClusterClient) Touch(ctx context.Context, 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(ctx context.Context, fn func(Pipeliner) error) ([]Cmder, error)

func (ClusterClient) Type

func (c ClusterClient) Type(ctx context.Context, key string) *StatusCmd
func (c ClusterClient) Unlink(ctx context.Context, keys ...string) *IntCmd

func (ClusterClient) Wait

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

func (*ClusterClient) Watch

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

func (*ClusterClient) WithContext

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

func (ClusterClient) XAck

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

func (ClusterClient) XAdd

func (c ClusterClient) XAdd(ctx context.Context, a *XAddArgs) *StringCmd

func (ClusterClient) XClaim

func (c ClusterClient) XClaim(ctx context.Context, a *XClaimArgs) *XMessageSliceCmd

func (ClusterClient) XClaimJustID

func (c ClusterClient) XClaimJustID(ctx context.Context, a *XClaimArgs) *StringSliceCmd

func (ClusterClient) XDel

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

func (ClusterClient) XGroupCreate

func (c ClusterClient) XGroupCreate(ctx context.Context, stream, group, start string) *StatusCmd

func (ClusterClient) XGroupCreateMkStream

func (c ClusterClient) XGroupCreateMkStream(ctx context.Context, stream, group, start string) *StatusCmd

func (ClusterClient) XGroupDelConsumer

func (c ClusterClient) XGroupDelConsumer(ctx context.Context, stream, group, consumer string) *IntCmd

func (ClusterClient) XGroupDestroy

func (c ClusterClient) XGroupDestroy(ctx context.Context, stream, group string) *IntCmd

func (ClusterClient) XGroupSetID

func (c ClusterClient) XGroupSetID(ctx context.Context, stream, group, start string) *StatusCmd

func (ClusterClient) XInfoGroups

func (c ClusterClient) XInfoGroups(ctx context.Context, key string) *XInfoGroupsCmd

func (ClusterClient) XInfoStream

func (c ClusterClient) XInfoStream(ctx context.Context, key string) *XInfoStreamCmd

func (ClusterClient) XLen

func (c ClusterClient) XLen(ctx context.Context, stream string) *IntCmd

func (ClusterClient) XPending

func (c ClusterClient) XPending(ctx context.Context, stream, group string) *XPendingCmd

func (ClusterClient) XPendingExt

func (c ClusterClient) XPendingExt(ctx context.Context, a *XPendingExtArgs) *XPendingExtCmd

func (ClusterClient) XRange

func (c ClusterClient) XRange(ctx context.Context, stream, start, stop string) *XMessageSliceCmd

func (ClusterClient) XRangeN

func (c ClusterClient) XRangeN(ctx context.Context, stream, start, stop string, count int64) *XMessageSliceCmd

func (ClusterClient) XRead

func (c ClusterClient) XRead(ctx context.Context, a *XReadArgs) *XStreamSliceCmd

func (ClusterClient) XReadGroup

func (c ClusterClient) XReadGroup(ctx context.Context, a *XReadGroupArgs) *XStreamSliceCmd

func (ClusterClient) XReadStreams

func (c ClusterClient) XReadStreams(ctx context.Context, streams ...string) *XStreamSliceCmd

func (ClusterClient) XRevRange

func (c ClusterClient) XRevRange(ctx context.Context, stream, start, stop string) *XMessageSliceCmd

func (ClusterClient) XRevRangeN

func (c ClusterClient) XRevRangeN(ctx context.Context, stream, start, stop string, count int64) *XMessageSliceCmd

func (ClusterClient) XTrim

func (c ClusterClient) XTrim(ctx context.Context, key string, maxLen int64) *IntCmd

func (ClusterClient) XTrimApprox

func (c ClusterClient) XTrimApprox(ctx context.Context, key string, maxLen int64) *IntCmd

func (ClusterClient) ZAdd

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

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

func (ClusterClient) ZAddCh

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

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

func (ClusterClient) ZAddNX

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

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

func (ClusterClient) ZAddNXCh

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

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

func (ClusterClient) ZAddXX

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

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

func (ClusterClient) ZAddXXCh

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

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

func (ClusterClient) ZCard

func (c ClusterClient) ZCard(ctx context.Context, key string) *IntCmd

func (ClusterClient) ZCount

func (c ClusterClient) ZCount(ctx context.Context, key, min, max string) *IntCmd

func (ClusterClient) ZIncr

func (c ClusterClient) ZIncr(ctx context.Context, key string, member *Z) *FloatCmd

Redis `ZADD key INCR score member` command.

func (ClusterClient) ZIncrBy

func (c ClusterClient) ZIncrBy(ctx context.Context, key string, increment float64, member string) *FloatCmd

func (ClusterClient) ZIncrNX

func (c ClusterClient) ZIncrNX(ctx context.Context, key string, member *Z) *FloatCmd

Redis `ZADD key NX INCR score member` command.

func (ClusterClient) ZIncrXX

func (c ClusterClient) ZIncrXX(ctx context.Context, key string, member *Z) *FloatCmd

Redis `ZADD key XX INCR score member` command.

func (ClusterClient) ZInterStore

func (c ClusterClient) ZInterStore(ctx context.Context, destination string, store *ZStore) *IntCmd

func (ClusterClient) ZLexCount

func (c ClusterClient) ZLexCount(ctx context.Context, key, min, max string) *IntCmd

func (ClusterClient) ZPopMax

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

func (ClusterClient) ZPopMin

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

func (ClusterClient) ZRange

func (c ClusterClient) ZRange(ctx context.Context, key string, start, stop int64) *StringSliceCmd

func (ClusterClient) ZRangeByLex

func (c ClusterClient) ZRangeByLex(ctx context.Context, key string, opt *ZRangeBy) *StringSliceCmd

func (ClusterClient) ZRangeByScore

func (c ClusterClient) ZRangeByScore(ctx context.Context, key string, opt *ZRangeBy) *StringSliceCmd

func (ClusterClient) ZRangeByScoreWithScores

func (c ClusterClient) ZRangeByScoreWithScores(ctx context.Context, key string, opt *ZRangeBy) *ZSliceCmd

func (ClusterClient) ZRangeWithScores

func (c ClusterClient) ZRangeWithScores(ctx context.Context, key string, start, stop int64) *ZSliceCmd

func (ClusterClient) ZRank

func (c ClusterClient) ZRank(ctx context.Context, key, member string) *IntCmd

func (ClusterClient) ZRem

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

func (ClusterClient) ZRemRangeByLex

func (c ClusterClient) ZRemRangeByLex(ctx context.Context, key, min, max string) *IntCmd

func (ClusterClient) ZRemRangeByRank

func (c ClusterClient) ZRemRangeByRank(ctx context.Context, key string, start, stop int64) *IntCmd

func (ClusterClient) ZRemRangeByScore

func (c ClusterClient) ZRemRangeByScore(ctx context.Context, key, min, max string) *IntCmd

func (ClusterClient) ZRevRange

func (c ClusterClient) ZRevRange(ctx context.Context, key string, start, stop int64) *StringSliceCmd

func (ClusterClient) ZRevRangeByLex

func (c ClusterClient) ZRevRangeByLex(ctx context.Context, key string, opt *ZRangeBy) *StringSliceCmd

func (ClusterClient) ZRevRangeByScore

func (c ClusterClient) ZRevRangeByScore(ctx context.Context, key string, opt *ZRangeBy) *StringSliceCmd

func (ClusterClient) ZRevRangeByScoreWithScores

func (c ClusterClient) ZRevRangeByScoreWithScores(ctx context.Context, key string, opt *ZRangeBy) *ZSliceCmd

func (ClusterClient) ZRevRangeWithScores

func (c ClusterClient) ZRevRangeWithScores(ctx context.Context, key string, start, stop int64) *ZSliceCmd

func (ClusterClient) ZRevRank

func (c ClusterClient) ZRevRank(ctx context.Context, key, member string) *IntCmd

func (ClusterClient) ZScan

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

func (ClusterClient) ZScore

func (c ClusterClient) ZScore(ctx context.Context, key, member string) *FloatCmd

func (ClusterClient) ZUnionStore

func (c ClusterClient) ZUnionStore(ctx context.Context, dest string, store *ZStore) *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

	// NewClient creates a cluster node client with provided name and options.
	NewClient func(opt *Options) *Client

	// The maximum number of retries before giving up. Command is retried
	// on network errors and MOVED/ASK redirects.
	// Default is 3 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(context.Context) ([]ClusterSlot, error)

	Dialer func(ctx context.Context, network, addr string) (net.Conn, error)

	OnConnect func(ctx context.Context, cn *Conn) error

	Username string
	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(ctx context.Context, 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) FullName

func (cmd *ClusterSlotsCmd) FullName() string

func (*ClusterSlotsCmd) Name

func (cmd *ClusterSlotsCmd) Name() string

func (*ClusterSlotsCmd) Result

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

func (*ClusterSlotsCmd) SetErr

func (cmd *ClusterSlotsCmd) SetErr(e 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(ctx context.Context, 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) FullName

func (cmd *Cmd) FullName() string

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) SetErr

func (cmd *Cmd) SetErr(e error)

func (*Cmd) String

func (cmd *Cmd) String() string

func (*Cmd) Text

func (cmd *Cmd) Text() (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(ctx context.Context, fn func(Pipeliner) error) ([]Cmder, error)

	TxPipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmder, error)
	TxPipeline() Pipeliner

	Command(ctx context.Context) *CommandsInfoCmd
	ClientGetName(ctx context.Context) *StringCmd
	Echo(ctx context.Context, message interface{}) *StringCmd
	Ping(ctx context.Context) *StatusCmd
	Quit(ctx context.Context) *StatusCmd
	Del(ctx context.Context, keys ...string) *IntCmd
	Unlink(ctx context.Context, keys ...string) *IntCmd
	Dump(ctx context.Context, key string) *StringCmd
	Exists(ctx context.Context, keys ...string) *IntCmd
	Expire(ctx context.Context, key string, expiration time.Duration) *BoolCmd
	ExpireAt(ctx context.Context, key string, tm time.Time) *BoolCmd
	Keys(ctx context.Context, pattern string) *StringSliceCmd
	Migrate(ctx context.Context, host, port, key string, db int, timeout time.Duration) *StatusCmd
	Move(ctx context.Context, key string, db int) *BoolCmd
	ObjectRefCount(ctx context.Context, key string) *IntCmd
	ObjectEncoding(ctx context.Context, key string) *StringCmd
	ObjectIdleTime(ctx context.Context, key string) *DurationCmd
	Persist(ctx context.Context, key string) *BoolCmd
	PExpire(ctx context.Context, key string, expiration time.Duration) *BoolCmd
	PExpireAt(ctx context.Context, key string, tm time.Time) *BoolCmd
	PTTL(ctx context.Context, key string) *DurationCmd
	RandomKey(ctx context.Context) *StringCmd
	Rename(ctx context.Context, key, newkey string) *StatusCmd
	RenameNX(ctx context.Context, key, newkey string) *BoolCmd
	Restore(ctx context.Context, key string, ttl time.Duration, value string) *StatusCmd
	RestoreReplace(ctx context.Context, key string, ttl time.Duration, value string) *StatusCmd
	Sort(ctx context.Context, key string, sort *Sort) *StringSliceCmd
	SortStore(ctx context.Context, key, store string, sort *Sort) *IntCmd
	SortInterfaces(ctx context.Context, key string, sort *Sort) *SliceCmd
	Touch(ctx context.Context, keys ...string) *IntCmd
	TTL(ctx context.Context, key string) *DurationCmd
	Type(ctx context.Context, key string) *StatusCmd
	Append(ctx context.Context, key, value string) *IntCmd
	Decr(ctx context.Context, key string) *IntCmd
	DecrBy(ctx context.Context, key string, decrement int64) *IntCmd
	Get(ctx context.Context, key string) *StringCmd
	GetRange(ctx context.Context, key string, start, end int64) *StringCmd
	GetSet(ctx context.Context, key string, value interface{}) *StringCmd
	Incr(ctx context.Context, key string) *IntCmd
	IncrBy(ctx context.Context, key string, value int64) *IntCmd
	IncrByFloat(ctx context.Context, key string, value float64) *FloatCmd
	MGet(ctx context.Context, keys ...string) *SliceCmd
	MSet(ctx context.Context, values ...interface{}) *StatusCmd
	MSetNX(ctx context.Context, values ...interface{}) *BoolCmd
	Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *StatusCmd
	SetEX(ctx context.Context, key string, value interface{}, expiration time.Duration) *StatusCmd
	SetNX(ctx context.Context, key string, value interface{}, expiration time.Duration) *BoolCmd
	SetXX(ctx context.Context, key string, value interface{}, expiration time.Duration) *BoolCmd
	SetRange(ctx context.Context, key string, offset int64, value string) *IntCmd
	StrLen(ctx context.Context, key string) *IntCmd

	GetBit(ctx context.Context, key string, offset int64) *IntCmd
	SetBit(ctx context.Context, key string, offset int64, value int) *IntCmd
	BitCount(ctx context.Context, key string, bitCount *BitCount) *IntCmd
	BitOpAnd(ctx context.Context, destKey string, keys ...string) *IntCmd
	BitOpOr(ctx context.Context, destKey string, keys ...string) *IntCmd
	BitOpXor(ctx context.Context, destKey string, keys ...string) *IntCmd
	BitOpNot(ctx context.Context, destKey string, key string) *IntCmd
	BitPos(ctx context.Context, key string, bit int64, pos ...int64) *IntCmd
	BitField(ctx context.Context, key string, args ...interface{}) *IntSliceCmd

	Scan(ctx context.Context, cursor uint64, match string, count int64) *ScanCmd
	SScan(ctx context.Context, key string, cursor uint64, match string, count int64) *ScanCmd
	HScan(ctx context.Context, key string, cursor uint64, match string, count int64) *ScanCmd
	ZScan(ctx context.Context, key string, cursor uint64, match string, count int64) *ScanCmd

	HDel(ctx context.Context, key string, fields ...string) *IntCmd
	HExists(ctx context.Context, key, field string) *BoolCmd
	HGet(ctx context.Context, key, field string) *StringCmd
	HGetAll(ctx context.Context, key string) *StringStringMapCmd
	HIncrBy(ctx context.Context, key, field string, incr int64) *IntCmd
	HIncrByFloat(ctx context.Context, key, field string, incr float64) *FloatCmd
	HKeys(ctx context.Context, key string) *StringSliceCmd
	HLen(ctx context.Context, key string) *IntCmd
	HMGet(ctx context.Context, key string, fields ...string) *SliceCmd
	HSet(ctx context.Context, key string, values ...interface{}) *IntCmd
	HMSet(ctx context.Context, key string, values ...interface{}) *BoolCmd
	HSetNX(ctx context.Context, key, field string, value interface{}) *BoolCmd
	HVals(ctx context.Context, key string) *StringSliceCmd

	BLPop(ctx context.Context, timeout time.Duration, keys ...string) *StringSliceCmd
	BRPop(ctx context.Context, timeout time.Duration, keys ...string) *StringSliceCmd
	BRPopLPush(ctx context.Context, source, destination string, timeout time.Duration) *StringCmd
	LIndex(ctx context.Context, key string, index int64) *StringCmd
	LInsert(ctx context.Context, key, op string, pivot, value interface{}) *IntCmd
	LInsertBefore(ctx context.Context, key string, pivot, value interface{}) *IntCmd
	LInsertAfter(ctx context.Context, key string, pivot, value interface{}) *IntCmd
	LLen(ctx context.Context, key string) *IntCmd
	LPop(ctx context.Context, key string) *StringCmd
	LPos(ctx context.Context, key string, value string, args LPosArgs) *IntCmd
	LPosCount(ctx context.Context, key string, value string, count int64, args LPosArgs) *IntSliceCmd
	LPush(ctx context.Context, key string, values ...interface{}) *IntCmd
	LPushX(ctx context.Context, key string, values ...interface{}) *IntCmd
	LRange(ctx context.Context, key string, start, stop int64) *StringSliceCmd
	LRem(ctx context.Context, key string, count int64, value interface{}) *IntCmd
	LSet(ctx context.Context, key string, index int64, value interface{}) *StatusCmd
	LTrim(ctx context.Context, key string, start, stop int64) *StatusCmd
	RPop(ctx context.Context, key string) *StringCmd
	RPopLPush(ctx context.Context, source, destination string) *StringCmd
	RPush(ctx context.Context, key string, values ...interface{}) *IntCmd
	RPushX(ctx context.Context, key string, values ...interface{}) *IntCmd

	SAdd(ctx context.Context, key string, members ...interface{}) *IntCmd
	SCard(ctx context.Context, key string) *IntCmd
	SDiff(ctx context.Context, keys ...string) *StringSliceCmd
	SDiffStore(ctx context.Context, destination string, keys ...string) *IntCmd
	SInter(ctx context.Context, keys ...string) *StringSliceCmd
	SInterStore(ctx context.Context, destination string, keys ...string) *IntCmd
	SIsMember(ctx context.Context, key string, member interface{}) *BoolCmd
	SMembers(ctx context.Context, key string) *StringSliceCmd
	SMembersMap(ctx context.Context, key string) *StringStructMapCmd
	SMove(ctx context.Context, source, destination string, member interface{}) *BoolCmd
	SPop(ctx context.Context, key string) *StringCmd
	SPopN(ctx context.Context, key string, count int64) *StringSliceCmd
	SRandMember(ctx context.Context, key string) *StringCmd
	SRandMemberN(ctx context.Context, key string, count int64) *StringSliceCmd
	SRem(ctx context.Context, key string, members ...interface{}) *IntCmd
	SUnion(ctx context.Context, keys ...string) *StringSliceCmd
	SUnionStore(ctx context.Context, destination string, keys ...string) *IntCmd

	XAdd(ctx context.Context, a *XAddArgs) *StringCmd
	XDel(ctx context.Context, stream string, ids ...string) *IntCmd
	XLen(ctx context.Context, stream string) *IntCmd
	XRange(ctx context.Context, stream, start, stop string) *XMessageSliceCmd
	XRangeN(ctx context.Context, stream, start, stop string, count int64) *XMessageSliceCmd
	XRevRange(ctx context.Context, stream string, start, stop string) *XMessageSliceCmd
	XRevRangeN(ctx context.Context, stream string, start, stop string, count int64) *XMessageSliceCmd
	XRead(ctx context.Context, a *XReadArgs) *XStreamSliceCmd
	XReadStreams(ctx context.Context, streams ...string) *XStreamSliceCmd
	XGroupCreate(ctx context.Context, stream, group, start string) *StatusCmd
	XGroupCreateMkStream(ctx context.Context, stream, group, start string) *StatusCmd
	XGroupSetID(ctx context.Context, stream, group, start string) *StatusCmd
	XGroupDestroy(ctx context.Context, stream, group string) *IntCmd
	XGroupDelConsumer(ctx context.Context, stream, group, consumer string) *IntCmd
	XReadGroup(ctx context.Context, a *XReadGroupArgs) *XStreamSliceCmd
	XAck(ctx context.Context, stream, group string, ids ...string) *IntCmd
	XPending(ctx context.Context, stream, group string) *XPendingCmd
	XPendingExt(ctx context.Context, a *XPendingExtArgs) *XPendingExtCmd
	XClaim(ctx context.Context, a *XClaimArgs) *XMessageSliceCmd
	XClaimJustID(ctx context.Context, a *XClaimArgs) *StringSliceCmd
	XTrim(ctx context.Context, key string, maxLen int64) *IntCmd
	XTrimApprox(ctx context.Context, key string, maxLen int64) *IntCmd
	XInfoGroups(ctx context.Context, key string) *XInfoGroupsCmd
	XInfoStream(ctx context.Context, key string) *XInfoStreamCmd

	BZPopMax(ctx context.Context, timeout time.Duration, keys ...string) *ZWithKeyCmd
	BZPopMin(ctx context.Context, timeout time.Duration, keys ...string) *ZWithKeyCmd
	ZAdd(ctx context.Context, key string, members ...*Z) *IntCmd
	ZAddNX(ctx context.Context, key string, members ...*Z) *IntCmd
	ZAddXX(ctx context.Context, key string, members ...*Z) *IntCmd
	ZAddCh(ctx context.Context, key string, members ...*Z) *IntCmd
	ZAddNXCh(ctx context.Context, key string, members ...*Z) *IntCmd
	ZAddXXCh(ctx context.Context, key string, members ...*Z) *IntCmd
	ZIncr(ctx context.Context, key string, member *Z) *FloatCmd
	ZIncrNX(ctx context.Context, key string, member *Z) *FloatCmd
	ZIncrXX(ctx context.Context, key string, member *Z) *FloatCmd
	ZCard(ctx context.Context, key string) *IntCmd
	ZCount(ctx context.Context, key, min, max string) *IntCmd
	ZLexCount(ctx context.Context, key, min, max string) *IntCmd
	ZIncrBy(ctx context.Context, key string, increment float64, member string) *FloatCmd
	ZInterStore(ctx context.Context, destination string, store *ZStore) *IntCmd
	ZPopMax(ctx context.Context, key string, count ...int64) *ZSliceCmd
	ZPopMin(ctx context.Context, key string, count ...int64) *ZSliceCmd
	ZRange(ctx context.Context, key string, start, stop int64) *StringSliceCmd
	ZRangeWithScores(ctx context.Context, key string, start, stop int64) *ZSliceCmd
	ZRangeByScore(ctx context.Context, key string, opt *ZRangeBy) *StringSliceCmd
	ZRangeByLex(ctx context.Context, key string, opt *ZRangeBy) *StringSliceCmd
	ZRangeByScoreWithScores(ctx context.Context, key string, opt *ZRangeBy) *ZSliceCmd
	ZRank(ctx context.Context, key, member string) *IntCmd
	ZRem(ctx context.Context, key string, members ...interface{}) *IntCmd
	ZRemRangeByRank(ctx context.Context, key string, start, stop int64) *IntCmd
	ZRemRangeByScore(ctx context.Context, key, min, max string) *IntCmd
	ZRemRangeByLex(ctx context.Context, key, min, max string) *IntCmd
	ZRevRange(ctx context.Context, key string, start, stop int64) *StringSliceCmd
	ZRevRangeWithScores(ctx context.Context, key string, start, stop int64) *ZSliceCmd
	ZRevRangeByScore(ctx context.Context, key string, opt *ZRangeBy) *StringSliceCmd
	ZRevRangeByLex(ctx context.Context, key string, opt *ZRangeBy) *StringSliceCmd
	ZRevRangeByScoreWithScores(ctx context.Context, key string, opt *ZRangeBy) *ZSliceCmd
	ZRevRank(ctx context.Context, key, member string) *IntCmd
	ZScore(ctx context.Context, key, member string) *FloatCmd
	ZUnionStore(ctx context.Context, dest string, store *ZStore) *IntCmd

	PFAdd(ctx context.Context, key string, els ...interface{}) *IntCmd
	PFCount(ctx context.Context, keys ...string) *IntCmd
	PFMerge(ctx context.Context, dest string, keys ...string) *StatusCmd

	BgRewriteAOF(ctx context.Context) *StatusCmd
	BgSave(ctx context.Context) *StatusCmd
	ClientKill(ctx context.Context, ipPort string) *StatusCmd
	ClientKillByFilter(ctx context.Context, keys ...string) *IntCmd
	ClientList(ctx context.Context) *StringCmd
	ClientPause(ctx context.Context, dur time.Duration) *BoolCmd
	ClientID(ctx context.Context) *IntCmd
	ConfigGet(ctx context.Context, parameter string) *SliceCmd
	ConfigResetStat(ctx context.Context) *StatusCmd
	ConfigSet(ctx context.Context, parameter, value string) *StatusCmd
	ConfigRewrite(ctx context.Context) *StatusCmd
	DBSize(ctx context.Context) *IntCmd
	FlushAll(ctx context.Context) *StatusCmd
	FlushAllAsync(ctx context.Context) *StatusCmd
	FlushDB(ctx context.Context) *StatusCmd
	FlushDBAsync(ctx context.Context) *StatusCmd
	Info(ctx context.Context, section ...string) *StringCmd
	LastSave(ctx context.Context) *IntCmd
	Save(ctx context.Context) *StatusCmd
	Shutdown(ctx context.Context) *StatusCmd
	ShutdownSave(ctx context.Context) *StatusCmd
	ShutdownNoSave(ctx context.Context) *StatusCmd
	SlaveOf(ctx context.Context, host, port string) *StatusCmd
	Time(ctx context.Context) *TimeCmd
	DebugObject(ctx context.Context, key string) *StringCmd
	ReadOnly(ctx context.Context) *StatusCmd
	ReadWrite(ctx context.Context) *StatusCmd
	MemoryUsage(ctx context.Context, key string, samples ...int) *IntCmd

	Eval(ctx context.Context, script string, keys []string, args ...interface{}) *Cmd
	EvalSha(ctx context.Context, sha1 string, keys []string, args ...interface{}) *Cmd
	ScriptExists(ctx context.Context, hashes ...string) *BoolSliceCmd
	ScriptFlush(ctx context.Context) *StatusCmd
	ScriptKill(ctx context.Context) *StatusCmd
	ScriptLoad(ctx context.Context, script string) *StringCmd

	Publish(ctx context.Context, channel string, message interface{}) *IntCmd
	PubSubChannels(ctx context.Context, pattern string) *StringSliceCmd
	PubSubNumSub(ctx context.Context, channels ...string) *StringIntMapCmd
	PubSubNumPat(ctx context.Context) *IntCmd

	ClusterSlots(ctx context.Context) *ClusterSlotsCmd
	ClusterNodes(ctx context.Context) *StringCmd
	ClusterMeet(ctx context.Context, host, port string) *StatusCmd
	ClusterForget(ctx context.Context, nodeID string) *StatusCmd
	ClusterReplicate(ctx context.Context, nodeID string) *StatusCmd
	ClusterResetSoft(ctx context.Context) *StatusCmd
	ClusterResetHard(ctx context.Context) *StatusCmd
	ClusterInfo(ctx context.Context) *StringCmd
	ClusterKeySlot(ctx context.Context, key string) *IntCmd
	ClusterGetKeysInSlot(ctx context.Context, slot int, count int) *StringSliceCmd
	ClusterCountFailureReports(ctx context.Context, nodeID string) *IntCmd
	ClusterCountKeysInSlot(ctx context.Context, slot int) *IntCmd
	ClusterDelSlots(ctx context.Context, slots ...int) *StatusCmd
	ClusterDelSlotsRange(ctx context.Context, min, max int) *StatusCmd
	ClusterSaveConfig(ctx context.Context) *StatusCmd
	ClusterSlaves(ctx context.Context, nodeID string) *StringSliceCmd
	ClusterFailover(ctx context.Context) *StatusCmd
	ClusterAddSlots(ctx context.Context, slots ...int) *StatusCmd
	ClusterAddSlotsRange(ctx context.Context, min, max int) *StatusCmd

	GeoAdd(ctx context.Context, key string, geoLocation ...*GeoLocation) *IntCmd
	GeoPos(ctx context.Context, key string, members ...string) *GeoPosCmd
	GeoRadius(ctx context.Context, key string, longitude, latitude float64, query *GeoRadiusQuery) *GeoLocationCmd
	GeoRadiusStore(ctx context.Context, key string, longitude, latitude float64, query *GeoRadiusQuery) *IntCmd
	GeoRadiusByMember(ctx context.Context, key, member string, query *GeoRadiusQuery) *GeoLocationCmd
	GeoRadiusByMemberStore(ctx context.Context, key, member string, query *GeoRadiusQuery) *IntCmd
	GeoDist(ctx context.Context, key string, member1, member2, unit string) *FloatCmd
	GeoHash(ctx context.Context, key string, members ...string) *StringSliceCmd
}

type Cmder

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

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

type CommandInfo

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

type CommandsInfoCmd

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

func NewCommandsInfoCmd

func NewCommandsInfoCmd(ctx context.Context, 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) FullName

func (cmd *CommandsInfoCmd) FullName() string

func (*CommandsInfoCmd) Name

func (cmd *CommandsInfoCmd) Name() string

func (*CommandsInfoCmd) Result

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

func (*CommandsInfoCmd) SetErr

func (cmd *CommandsInfoCmd) SetErr(e 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.

Example
conn := rdb.Conn(context.Background())

err := conn.ClientSetName(ctx, "foobar").Err()
if err != nil {
	panic(err)
}

// Open other connections.
for i := 0; i < 10; i++ {
	go rdb.Ping(ctx)
}

s, err := conn.ClientGetName(ctx).Result()
if err != nil {
	panic(err)
}
fmt.Println(s)
Output:

foobar

func (*Conn) Pipeline

func (c *Conn) Pipeline() Pipeliner

func (*Conn) Pipelined

func (c *Conn) Pipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmder, error)

func (*Conn) Process

func (c *Conn) Process(ctx context.Context, cmd Cmder) error

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(ctx context.Context, fn func(Pipeliner) error) ([]Cmder, error)

type ConsistentHash

type ConsistentHash interface {
	Get(string) string
}

type DurationCmd

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

func NewDurationCmd

func NewDurationCmd(ctx context.Context, 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) FullName

func (cmd *DurationCmd) FullName() string

func (*DurationCmd) Name

func (cmd *DurationCmd) Name() string

func (*DurationCmd) Result

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

func (*DurationCmd) SetErr

func (cmd *DurationCmd) SetErr(e error)

func (*DurationCmd) String

func (cmd *DurationCmd) String() string

func (*DurationCmd) Val

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

type Error

type Error interface {
	error

	// RedisError is a no-op function but
	// serves to distinguish types that are Redis
	// errors from ordinary errors: a type is a
	// Redis error if it has a RedisError method.
	RedisError()
}

type FailoverOptions

type FailoverOptions struct {
	// The master name.
	MasterName string
	// A seed list of host:port addresses of sentinel nodes.
	SentinelAddrs []string
	// Sentinel password from "requirepass <password>" (if enabled) in Sentinel configuration
	SentinelPassword string

	// Allows routing read-only commands to the closest master or slave node.
	// This option only works with NewFailoverClusterClient.
	RouteByLatency bool
	// Allows routing read-only commands to the random master or slave node.
	// This option only works with NewFailoverClusterClient.
	RouteRandomly bool

	// Route all commands to slave read-only nodes.
	SlaveOnly bool

	Dialer    func(ctx context.Context, network, addr string) (net.Conn, error)
	OnConnect func(ctx context.Context, cn *Conn) error

	Username string
	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(ctx context.Context, 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) FullName

func (cmd *FloatCmd) FullName() string

func (*FloatCmd) Name

func (cmd *FloatCmd) Name() string

func (*FloatCmd) Result

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

func (*FloatCmd) SetErr

func (cmd *FloatCmd) SetErr(e 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(ctx context.Context, 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) FullName

func (cmd *GeoLocationCmd) FullName() string

func (*GeoLocationCmd) Name

func (cmd *GeoLocationCmd) Name() string

func (*GeoLocationCmd) Result

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

func (*GeoLocationCmd) SetErr

func (cmd *GeoLocationCmd) SetErr(e 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(ctx context.Context, args ...interface{}) *GeoPosCmd

func NewGeoPosCmdResult

func NewGeoPosCmdResult(val []*GeoPos, err error) *GeoPosCmd

NewGeoPosCmdResult returns a GeoPosCmd initialised with val and err for testing.

func (*GeoPosCmd) Args

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

func (*GeoPosCmd) Err

func (cmd *GeoPosCmd) Err() error

func (*GeoPosCmd) FullName

func (cmd *GeoPosCmd) FullName() string

func (*GeoPosCmd) Name

func (cmd *GeoPosCmd) Name() string

func (*GeoPosCmd) Result

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

func (*GeoPosCmd) SetErr

func (cmd *GeoPosCmd) SetErr(e 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 Hook

type Hook interface {
	BeforeProcess(ctx context.Context, cmd Cmder) (context.Context, error)
	AfterProcess(ctx context.Context, cmd Cmder) error

	BeforeProcessPipeline(ctx context.Context, cmds []Cmder) (context.Context, error)
	AfterProcessPipeline(ctx context.Context, cmds []Cmder) error
}

type IntCmd

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

func NewIntCmd

func NewIntCmd(ctx context.Context, 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) FullName

func (cmd *IntCmd) FullName() string

func (*IntCmd) Name

func (cmd *IntCmd) Name() string

func (*IntCmd) Result

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

func (*IntCmd) SetErr

func (cmd *IntCmd) SetErr(e error)

func (*IntCmd) String

func (cmd *IntCmd) String() string

func (*IntCmd) Uint64

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

func (*IntCmd) Val

func (cmd *IntCmd) Val() int64

type IntSliceCmd

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

func NewIntSliceCmd

func NewIntSliceCmd(ctx context.Context, args ...interface{}) *IntSliceCmd

func (*IntSliceCmd) Args

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

func (*IntSliceCmd) Err

func (cmd *IntSliceCmd) Err() error

func (*IntSliceCmd) FullName

func (cmd *IntSliceCmd) FullName() string

func (*IntSliceCmd) Name

func (cmd *IntSliceCmd) Name() string

func (*IntSliceCmd) Result

func (cmd *IntSliceCmd) Result() ([]int64, error)

func (*IntSliceCmd) SetErr

func (cmd *IntSliceCmd) SetErr(e error)

func (*IntSliceCmd) String

func (cmd *IntSliceCmd) String() string

func (*IntSliceCmd) Val

func (cmd *IntSliceCmd) Val() []int64

type LPosArgs

type LPosArgs struct {
	Rank, MaxLen int64
}

type Limiter

type Limiter interface {
	// Allow returns nil if operation is allowed or an error otherwise.
	// If operation is allowed client must ReportResult of the operation
	// whether it is a success or a failure.
	Allow() error
	// ReportResult reports the result of the previously allowed operation.
	// nil indicates a success, non-nil error usually 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
	PayloadSlice []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(ctx context.Context, network, addr string) (net.Conn, error)

	// Hook that is called when new connection is established.
	OnConnect func(ctx context.Context, cn *Conn) error

	// Use the specified Username to authenticate the current connection
	// with one of the connections defined in the ACL list when connecting
	// to a Redis 6.0 instance, or greater, that is using the Redis ACL system.
	Username string
	// Optional password. Must match the password specified in the
	// requirepass server configuration option (if connecting to a Redis 5.0 instance, or lower),
	// or the User Password when connecting to a Redis 6.0 instance, or greater,
	// that is using the Redis ACL system.
	Password string

	// Database to be selected after connecting to the server.
	DB int

	// Maximum number of retries before giving up.
	// Default is 3 retries; -1 (not 0) disables retries.
	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

	// Limiter interface used to implemented circuit breaker or rate limiter.
	Limiter Limiter
	// contains filtered or unexported fields
}

Options keeps the settings to setup redis connection.

func ParseURL

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

ParseURL parses an URL into Options that can be used to connect to Redis. Scheme is required. There are two connection types: by tcp socket and by unix socket. Tcp connection:

redis://<user>:<password>@<host>:<port>/<db_number>

Unix connection:

unix://<user>:<password>@</path/to/redis.sock>?db=<db_number>
Example
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)
rdb := redis.NewClient(&redis.Options{
	Addr: ":6379",
})
rdb.AddHook(redisHook{})

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

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

func (Pipeline) Append

func (c Pipeline) Append(ctx context.Context, key, value string) *IntCmd

func (Pipeline) Auth

func (c Pipeline) Auth(ctx context.Context, password string) *StatusCmd

func (Pipeline) AuthACL

func (c Pipeline) AuthACL(ctx context.Context, username, password string) *StatusCmd

Perform an AUTH command, using the given user and pass. Should be used to authenticate the current connection with one of the connections defined in the ACL list when connecting to a Redis 6.0 instance, or greater, that is using the Redis ACL system.

func (Pipeline) BLPop

func (c Pipeline) BLPop(ctx context.Context, timeout time.Duration, keys ...string) *StringSliceCmd

func (Pipeline) BRPop

func (c Pipeline) BRPop(ctx context.Context, timeout time.Duration, keys ...string) *StringSliceCmd

func (Pipeline) BRPopLPush

func (c Pipeline) BRPopLPush(ctx context.Context, source, destination string, timeout time.Duration) *StringCmd

func (Pipeline) BZPopMax

func (c Pipeline) BZPopMax(ctx context.Context, timeout time.Duration, keys ...string) *ZWithKeyCmd

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

func (Pipeline) BZPopMin

func (c Pipeline) BZPopMin(ctx context.Context, timeout time.Duration, keys ...string) *ZWithKeyCmd

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

func (Pipeline) BgRewriteAOF

func (c Pipeline) BgRewriteAOF(ctx context.Context) *StatusCmd

func (Pipeline) BgSave

func (c Pipeline) BgSave(ctx context.Context) *StatusCmd

func (Pipeline) BitCount

func (c Pipeline) BitCount(ctx context.Context, key string, bitCount *BitCount) *IntCmd

func (Pipeline) BitField

func (c Pipeline) BitField(ctx context.Context, key string, args ...interface{}) *IntSliceCmd

func (Pipeline) BitOpAnd

func (c Pipeline) BitOpAnd(ctx context.Context, destKey string, keys ...string) *IntCmd

func (Pipeline) BitOpNot

func (c Pipeline) BitOpNot(ctx context.Context, destKey string, key string) *IntCmd

func (Pipeline) BitOpOr

func (c Pipeline) BitOpOr(ctx context.Context, destKey string, keys ...string) *IntCmd

func (Pipeline) BitOpXor

func (c Pipeline) BitOpXor(ctx context.Context, destKey string, keys ...string) *IntCmd

func (Pipeline) BitPos

func (c Pipeline) BitPos(ctx context.Context, key string, bit int64, pos ...int64) *IntCmd

func (Pipeline) ClientGetName

func (c Pipeline) ClientGetName(ctx context.Context) *StringCmd

ClientGetName returns the name of the connection.

func (Pipeline) ClientID

func (c Pipeline) ClientID(ctx context.Context) *IntCmd

func (Pipeline) ClientKill

func (c Pipeline) ClientKill(ctx context.Context, ipPort string) *StatusCmd

func (Pipeline) ClientKillByFilter

func (c Pipeline) ClientKillByFilter(ctx context.Context, keys ...string) *IntCmd

ClientKillByFilter is new style syntax, while the ClientKill is old

CLIENT KILL <option> [value] ... <option> [value]

func (Pipeline) ClientList

func (c Pipeline) ClientList(ctx context.Context) *StringCmd

func (Pipeline) ClientPause

func (c Pipeline) ClientPause(ctx context.Context, dur time.Duration) *BoolCmd

func (Pipeline) ClientSetName

func (c Pipeline) ClientSetName(ctx context.Context, name string) *BoolCmd

ClientSetName assigns a name to the connection.

func (Pipeline) ClientUnblock

func (c Pipeline) ClientUnblock(ctx context.Context, id int64) *IntCmd

func (Pipeline) ClientUnblockWithError

func (c Pipeline) ClientUnblockWithError(ctx context.Context, id int64) *IntCmd

func (*Pipeline) Close

func (c *Pipeline) Close() error

Close closes the pipeline, releasing any open resources.

func (Pipeline) ClusterAddSlots

func (c Pipeline) ClusterAddSlots(ctx context.Context, slots ...int) *StatusCmd

func (Pipeline) ClusterAddSlotsRange

func (c Pipeline) ClusterAddSlotsRange(ctx context.Context, min, max int) *StatusCmd

func (Pipeline) ClusterCountFailureReports

func (c Pipeline) ClusterCountFailureReports(ctx context.Context, nodeID string) *IntCmd

func (Pipeline) ClusterCountKeysInSlot

func (c Pipeline) ClusterCountKeysInSlot(ctx context.Context, slot int) *IntCmd

func (Pipeline) ClusterDelSlots

func (c Pipeline) ClusterDelSlots(ctx context.Context, slots ...int) *StatusCmd

func (Pipeline) ClusterDelSlotsRange

func (c Pipeline) ClusterDelSlotsRange(ctx context.Context, min, max int) *StatusCmd

func (Pipeline) ClusterFailover

func (c Pipeline) ClusterFailover(ctx context.Context) *StatusCmd

func (Pipeline) ClusterForget

func (c Pipeline) ClusterForget(ctx context.Context, nodeID string) *StatusCmd

func (Pipeline) ClusterGetKeysInSlot

func (c Pipeline) ClusterGetKeysInSlot(ctx context.Context, slot int, count int) *StringSliceCmd

func (Pipeline) ClusterInfo

func (c Pipeline) ClusterInfo(ctx context.Context) *StringCmd

func (Pipeline) ClusterKeySlot

func (c Pipeline) ClusterKeySlot(ctx context.Context, key string) *IntCmd

func (Pipeline) ClusterMeet

func (c Pipeline) ClusterMeet(ctx context.Context, host, port string) *StatusCmd

func (Pipeline) ClusterNodes

func (c Pipeline) ClusterNodes(ctx context.Context) *StringCmd

func (Pipeline) ClusterReplicate

func (c Pipeline) ClusterReplicate(ctx context.Context, nodeID string) *StatusCmd

func (Pipeline) ClusterResetHard

func (c Pipeline) ClusterResetHard(ctx context.Context) *StatusCmd

func (Pipeline) ClusterResetSoft

func (c Pipeline) ClusterResetSoft(ctx context.Context) *StatusCmd

func (Pipeline) ClusterSaveConfig

func (c Pipeline) ClusterSaveConfig(ctx context.Context) *StatusCmd

func (Pipeline) ClusterSlaves

func (c Pipeline) ClusterSlaves(ctx context.Context, nodeID string) *StringSliceCmd

func (Pipeline) ClusterSlots

func (c Pipeline) ClusterSlots(ctx context.Context) *ClusterSlotsCmd

func (Pipeline) Command

func (c Pipeline) Command(ctx context.Context) *CommandsInfoCmd

func (Pipeline) ConfigGet

func (c Pipeline) ConfigGet(ctx context.Context, parameter string) *SliceCmd

func (Pipeline) ConfigResetStat

func (c Pipeline) ConfigResetStat(ctx context.Context) *StatusCmd

func (Pipeline) ConfigRewrite

func (c Pipeline) ConfigRewrite(ctx context.Context) *StatusCmd

func (Pipeline) ConfigSet

func (c Pipeline) ConfigSet(ctx context.Context, parameter, value string) *StatusCmd

func (Pipeline) DBSize

func (c Pipeline) DBSize(ctx context.Context) *IntCmd

func (Pipeline) DebugObject

func (c Pipeline) DebugObject(ctx context.Context, key string) *StringCmd

func (Pipeline) Decr

func (c Pipeline) Decr(ctx context.Context, key string) *IntCmd

func (Pipeline) DecrBy

func (c Pipeline) DecrBy(ctx context.Context, key string, decrement int64) *IntCmd

func (Pipeline) Del

func (c Pipeline) Del(ctx context.Context, keys ...string) *IntCmd

func (*Pipeline) Discard

func (c *Pipeline) Discard() error

Discard resets the pipeline and discards queued commands.

func (*Pipeline) Do

func (c *Pipeline) Do(ctx context.Context, args ...interface{}) *Cmd

func (Pipeline) Dump

func (c Pipeline) Dump(ctx context.Context, key string) *StringCmd

func (Pipeline) Echo

func (c Pipeline) Echo(ctx context.Context, message interface{}) *StringCmd

func (Pipeline) Eval

func (c Pipeline) Eval(ctx context.Context, script string, keys []string, args ...interface{}) *Cmd

func (Pipeline) EvalSha

func (c Pipeline) EvalSha(ctx context.Context, sha1 string, keys []string, args ...interface{}) *Cmd

func (*Pipeline) Exec

func (c *Pipeline) Exec(ctx context.Context) ([]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) Exists

func (c Pipeline) Exists(ctx context.Context, keys ...string) *IntCmd

func (Pipeline) Expire

func (c Pipeline) Expire(ctx context.Context, key string, expiration time.Duration) *BoolCmd

func (Pipeline) ExpireAt

func (c Pipeline) ExpireAt(ctx context.Context, key string, tm time.Time) *BoolCmd

func (Pipeline) FlushAll

func (c Pipeline) FlushAll(ctx context.Context) *StatusCmd

func (Pipeline) FlushAllAsync

func (c Pipeline) FlushAllAsync(ctx context.Context) *StatusCmd

func (Pipeline) FlushDB

func (c Pipeline) FlushDB(ctx context.Context) *StatusCmd

func (Pipeline) FlushDBAsync

func (c Pipeline) FlushDBAsync(ctx context.Context) *StatusCmd

func (Pipeline) GeoAdd

func (c Pipeline) GeoAdd(ctx context.Context, key string, geoLocation ...*GeoLocation) *IntCmd

func (Pipeline) GeoDist

func (c Pipeline) GeoDist(
	ctx context.Context, key string, member1, member2, unit string,
) *FloatCmd

func (Pipeline) GeoHash

func (c Pipeline) GeoHash(ctx context.Context, key string, members ...string) *StringSliceCmd

func (Pipeline) GeoPos

func (c Pipeline) GeoPos(ctx context.Context, key string, members ...string) *GeoPosCmd

func (Pipeline) GeoRadius

func (c Pipeline) GeoRadius(
	ctx context.Context, key string, longitude, latitude float64, query *GeoRadiusQuery,
) *GeoLocationCmd

GeoRadius is a read-only GEORADIUS_RO command.

func (Pipeline) GeoRadiusByMember

func (c Pipeline) GeoRadiusByMember(
	ctx context.Context, key, member string, query *GeoRadiusQuery,
) *GeoLocationCmd

GeoRadius is a read-only GEORADIUSBYMEMBER_RO command.

func (Pipeline) GeoRadiusByMemberStore

func (c Pipeline) GeoRadiusByMemberStore(
	ctx context.Context, key, member string, query *GeoRadiusQuery,
) *IntCmd

GeoRadiusByMemberStore is a writing GEORADIUSBYMEMBER command.

func (Pipeline) GeoRadiusStore

func (c Pipeline) GeoRadiusStore(
	ctx context.Context, key string, longitude, latitude float64, query *GeoRadiusQuery,
) *IntCmd

GeoRadiusStore is a writing GEORADIUS command.

func (Pipeline) Get

func (c Pipeline) Get(ctx context.Context, key string) *StringCmd

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

func (Pipeline) GetBit

func (c Pipeline) GetBit(ctx context.Context, key string, offset int64) *IntCmd

func (Pipeline) GetRange

func (c Pipeline) GetRange(ctx context.Context, key string, start, end int64) *StringCmd

func (Pipeline) GetSet

func (c Pipeline) GetSet(ctx context.Context, key string, value interface{}) *StringCmd

func (Pipeline) HDel

func (c Pipeline) HDel(ctx context.Context, key string, fields ...string) *IntCmd

func (Pipeline) HExists

func (c Pipeline) HExists(ctx context.Context, key, field string) *BoolCmd

func (Pipeline) HGet

func (c Pipeline) HGet(ctx context.Context, key, field string) *StringCmd

func (Pipeline) HGetAll

func (c Pipeline) HGetAll(ctx context.Context, key string) *StringStringMapCmd

func (Pipeline) HIncrBy

func (c Pipeline) HIncrBy(ctx context.Context, key, field string, incr int64) *IntCmd

func (Pipeline) HIncrByFloat

func (c Pipeline) HIncrByFloat(ctx context.Context, key, field string, incr float64) *FloatCmd

func (Pipeline) HKeys

func (c Pipeline) HKeys(ctx context.Context, key string) *StringSliceCmd

func (Pipeline) HLen

func (c Pipeline) HLen(ctx context.Context, key string) *IntCmd

func (Pipeline) HMGet

func (c Pipeline) HMGet(ctx context.Context, key string, fields ...string) *SliceCmd

HMGet returns the values for the specified fields in the hash stored at key. It returns an interface{} to distinguish between empty string and nil value.

func (Pipeline) HMSet

func (c Pipeline) HMSet(ctx context.Context, key string, values ...interface{}) *BoolCmd

HMSet is a deprecated version of HSet left for compatibility with Redis 3.

func (Pipeline) HScan

func (c Pipeline) HScan(ctx context.Context, key string, cursor uint64, match string, count int64) *ScanCmd

func (Pipeline) HSet

func (c Pipeline) HSet(ctx context.Context, key string, values ...interface{}) *IntCmd

HSet accepts values in following formats:

  • HSet("myhash", "key1", "value1", "key2", "value2")
  • HSet("myhash", []string{"key1", "value1", "key2", "value2"})
  • HSet("myhash", map[string]interface{}{"key1": "value1", "key2": "value2"})

Note that it requires Redis v4 for multiple field/value pairs support.

func (Pipeline) HSetNX

func (c Pipeline) HSetNX(ctx context.Context, key, field string, value interface{}) *BoolCmd

func (Pipeline) HVals

func (c Pipeline) HVals(ctx context.Context, key string) *StringSliceCmd

func (Pipeline) Incr

func (c Pipeline) Incr(ctx context.Context, key string) *IntCmd

func (Pipeline) IncrBy

func (c Pipeline) IncrBy(ctx context.Context, key string, value int64) *IntCmd

func (Pipeline) IncrByFloat

func (c Pipeline) IncrByFloat(ctx context.Context, key string, value float64) *FloatCmd

func (Pipeline) Info

func (c Pipeline) Info(ctx context.Context, section ...string) *StringCmd

func (Pipeline) Keys

func (c Pipeline) Keys(ctx context.Context, pattern string) *StringSliceCmd

func (Pipeline) LIndex

func (c Pipeline) LIndex(ctx context.Context, key string, index int64) *StringCmd

func (Pipeline) LInsert

func (c Pipeline) LInsert(ctx context.Context, key, op string, pivot, value interface{}) *IntCmd

func (Pipeline) LInsertAfter

func (c Pipeline) LInsertAfter(ctx context.Context, key string, pivot, value interface{}) *IntCmd

func (Pipeline) LInsertBefore

func (c Pipeline) LInsertBefore(ctx context.Context, key string, pivot, value interface{}) *IntCmd

func (Pipeline) LLen

func (c Pipeline) LLen(ctx context.Context, key string) *IntCmd

func (Pipeline) LPop

func (c Pipeline) LPop(ctx context.Context, key string) *StringCmd

func (Pipeline) LPos

func (c Pipeline) LPos(ctx context.Context, key string, value string, a LPosArgs) *IntCmd

func (Pipeline) LPosCount

func (c Pipeline) LPosCount(ctx context.Context, key string, value string, count int64, a LPosArgs) *IntSliceCmd

func (Pipeline) LPush

func (c Pipeline) LPush(ctx context.Context, key string, values ...interface{}) *IntCmd

func (Pipeline) LPushX

func (c Pipeline) LPushX(ctx context.Context, key string, values ...interface{}) *IntCmd

func (Pipeline) LRange

func (c Pipeline) LRange(ctx context.Context, key string, start, stop int64) *StringSliceCmd

func (Pipeline) LRem

func (c Pipeline) LRem(ctx context.Context, key string, count int64, value interface{}) *IntCmd

func (Pipeline) LSet

func (c Pipeline) LSet(ctx context.Context, key string, index int64, value interface{}) *StatusCmd

func (Pipeline) LTrim

func (c Pipeline) LTrim(ctx context.Context, key string, start, stop int64) *StatusCmd

func (Pipeline) LastSave

func (c Pipeline) LastSave(ctx context.Context) *IntCmd

func (Pipeline) MGet

func (c Pipeline) MGet(ctx context.Context, keys ...string) *SliceCmd

func (Pipeline) MSet

func (c Pipeline) MSet(ctx context.Context, values ...interface{}) *StatusCmd

MSet is like Set but accepts multiple values:

  • MSet("key1", "value1", "key2", "value2")
  • MSet([]string{"key1", "value1", "key2", "value2"})
  • MSet(map[string]interface{}{"key1": "value1", "key2": "value2"})

func (Pipeline) MSetNX

func (c Pipeline) MSetNX(ctx context.Context, values ...interface{}) *BoolCmd

MSetNX is like SetNX but accepts multiple values:

  • MSetNX("key1", "value1", "key2", "value2")
  • MSetNX([]string{"key1", "value1", "key2", "value2"})
  • MSetNX(map[string]interface{}{"key1": "value1", "key2": "value2"})

func (Pipeline) MemoryUsage

func (c Pipeline) MemoryUsage(ctx context.Context, key string, samples ...int) *IntCmd

func (Pipeline) Migrate

func (c Pipeline) Migrate(ctx context.Context, host, port, key string, db int, timeout time.Duration) *StatusCmd

func (Pipeline) Move

func (c Pipeline) Move(ctx context.Context, key string, db int) *BoolCmd

func (Pipeline) ObjectEncoding

func (c Pipeline) ObjectEncoding(ctx context.Context, key string) *StringCmd

func (Pipeline) ObjectIdleTime

func (c Pipeline) ObjectIdleTime(ctx context.Context, key string) *DurationCmd

func (Pipeline) ObjectRefCount

func (c Pipeline) ObjectRefCount(ctx context.Context, key string) *IntCmd

func (Pipeline) PExpire

func (c Pipeline) PExpire(ctx context.Context, key string, expiration time.Duration) *BoolCmd

func (Pipeline) PExpireAt

func (c Pipeline) PExpireAt(ctx context.Context, key string, tm time.Time) *BoolCmd

func (Pipeline) PFAdd

func (c Pipeline) PFAdd(ctx context.Context, key string, els ...interface{}) *IntCmd

func (Pipeline) PFCount

func (c Pipeline) PFCount(ctx context.Context, keys ...string) *IntCmd

func (Pipeline) PFMerge

func (c Pipeline) PFMerge(ctx context.Context, dest string, keys ...string) *StatusCmd

func (Pipeline) PTTL

func (c Pipeline) PTTL(ctx context.Context, key string) *DurationCmd

func (Pipeline) Persist

func (c Pipeline) Persist(ctx context.Context, key string) *BoolCmd

func (Pipeline) Ping

func (c Pipeline) Ping(ctx context.Context) *StatusCmd

func (*Pipeline) Pipeline

func (c *Pipeline) Pipeline() Pipeliner

func (*Pipeline) Pipelined

func (c *Pipeline) Pipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmder, error)

func (*Pipeline) Process

func (c *Pipeline) Process(ctx context.Context, cmd Cmder) error

Process queues the cmd for later execution.

func (Pipeline) PubSubChannels

func (c Pipeline) PubSubChannels(ctx context.Context, pattern string) *StringSliceCmd

func (Pipeline) PubSubNumPat

func (c Pipeline) PubSubNumPat(ctx context.Context) *IntCmd

func (Pipeline) PubSubNumSub

func (c Pipeline) PubSubNumSub(ctx context.Context, channels ...string) *StringIntMapCmd

func (Pipeline) Publish

func (c Pipeline) Publish(ctx context.Context, channel string, message interface{}) *IntCmd

Publish posts the message to the channel.

func (Pipeline) Quit

func (c Pipeline) Quit(ctx context.Context) *StatusCmd

func (Pipeline) RPop

func (c Pipeline) RPop(ctx context.Context, key string) *StringCmd

func (Pipeline) RPopLPush

func (c Pipeline) RPopLPush(ctx context.Context, source, destination string) *StringCmd

func (Pipeline) RPush

func (c Pipeline) RPush(ctx context.Context, key string, values ...interface{}) *IntCmd

func (Pipeline) RPushX

func (c Pipeline) RPushX(ctx context.Context, key string, values ...interface{}) *IntCmd

func (Pipeline) RandomKey

func (c Pipeline) RandomKey(ctx context.Context) *StringCmd

func (Pipeline) ReadOnly

func (c Pipeline) ReadOnly(ctx context.Context) *StatusCmd

func (Pipeline) ReadWrite

func (c Pipeline) ReadWrite(ctx context.Context) *StatusCmd

func (Pipeline) Rename

func (c Pipeline) Rename(ctx context.Context, key, newkey string) *StatusCmd

func (Pipeline) RenameNX

func (c Pipeline) RenameNX(ctx context.Context, key, newkey string) *BoolCmd

func (Pipeline) Restore

func (c Pipeline) Restore(ctx context.Context, key string, ttl time.Duration, value string) *StatusCmd

func (Pipeline) RestoreReplace

func (c Pipeline) RestoreReplace(ctx context.Context, key string, ttl time.Duration, value string) *StatusCmd

func (Pipeline) SAdd

func (c Pipeline) SAdd(ctx context.Context, key string, members ...interface{}) *IntCmd

func (Pipeline) SCard

func (c Pipeline) SCard(ctx context.Context, key string) *IntCmd

func (Pipeline) SDiff

func (c Pipeline) SDiff(ctx context.Context, keys ...string) *StringSliceCmd

func (Pipeline) SDiffStore

func (c Pipeline) SDiffStore(ctx context.Context, destination string, keys ...string) *IntCmd

func (Pipeline) SInter

func (c Pipeline) SInter(ctx context.Context, keys ...string) *StringSliceCmd

func (Pipeline) SInterStore

func (c Pipeline) SInterStore(ctx context.Context, destination string, keys ...string) *IntCmd

func (Pipeline) SIsMember

func (c Pipeline) SIsMember(ctx context.Context, key string, member interface{}) *BoolCmd

func (Pipeline) SMembers

func (c Pipeline) SMembers(ctx context.Context, key string) *StringSliceCmd

Redis `SMEMBERS key` command output as a slice.

func (Pipeline) SMembersMap

func (c Pipeline) SMembersMap(ctx context.Context, key string) *StringStructMapCmd

Redis `SMEMBERS key` command output as a map.

func (Pipeline) SMove

func (c Pipeline) SMove(ctx context.Context, source, destination string, member interface{}) *BoolCmd

func (Pipeline) SPop

func (c Pipeline) SPop(ctx context.Context, key string) *StringCmd

Redis `SPOP key` command.

func (Pipeline) SPopN

func (c Pipeline) SPopN(ctx context.Context, key string, count int64) *StringSliceCmd

Redis `SPOP key count` command.

func (Pipeline) SRandMember

func (c Pipeline) SRandMember(ctx context.Context, key string) *StringCmd

Redis `SRANDMEMBER key` command.

func (Pipeline) SRandMemberN

func (c Pipeline) SRandMemberN(ctx context.Context, key string, count int64) *StringSliceCmd

Redis `SRANDMEMBER key count` command.

func (Pipeline) SRem

func (c Pipeline) SRem(ctx context.Context, key string, members ...interface{}) *IntCmd

func (Pipeline) SScan

func (c Pipeline) SScan(ctx context.Context, key string, cursor uint64, match string, count int64) *ScanCmd

func (Pipeline) SUnion

func (c Pipeline) SUnion(ctx context.Context, keys ...string) *StringSliceCmd

func (Pipeline) SUnionStore

func (c Pipeline) SUnionStore(ctx context.Context, destination string, keys ...string) *IntCmd

func (Pipeline) Save

func (c Pipeline) Save(ctx context.Context) *StatusCmd

func (Pipeline) Scan

func (c Pipeline) Scan(ctx context.Context, cursor uint64, match string, keyType string, count int64) *ScanCmd

func (Pipeline) ScriptExists

func (c Pipeline) ScriptExists(ctx context.Context, hashes ...string) *BoolSliceCmd

func (Pipeline) ScriptFlush

func (c Pipeline) ScriptFlush(ctx context.Context) *StatusCmd

func (Pipeline) ScriptKill

func (c Pipeline) ScriptKill(ctx context.Context) *StatusCmd

func (Pipeline) ScriptLoad

func (c Pipeline) ScriptLoad(ctx context.Context, script string) *StringCmd

func (Pipeline) Select

func (c Pipeline) Select(ctx context.Context, index int) *StatusCmd

func (Pipeline) Set

func (c Pipeline) Set(ctx context.Context, 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. KeepTTL(-1) expiration is a Redis KEEPTTL option to keep existing TTL.

func (Pipeline) SetBit

func (c Pipeline) SetBit(ctx context.Context, key string, offset int64, value int) *IntCmd

func (Pipeline) SetEX

func (c Pipeline) SetEX(ctx context.Context, key string, value interface{}, expiration time.Duration) *StatusCmd

Redis `SETEX key expiration value` command.

func (Pipeline) SetNX

func (c Pipeline) SetNX(ctx context.Context, key string, value interface{}, expiration time.Duration) *BoolCmd

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

Zero expiration means the key has no expiration time. KeepTTL(-1) expiration is a Redis KEEPTTL option to keep existing TTL.

func (Pipeline) SetRange

func (c Pipeline) SetRange(ctx context.Context, key string, offset int64, value string) *IntCmd

func (Pipeline) SetXX

func (c Pipeline) SetXX(ctx context.Context, key string, value interface{}, expiration time.Duration) *BoolCmd

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

Zero expiration means the key has no expiration time. KeepTTL(-1) expiration is a Redis KEEPTTL option to keep existing TTL.

func (Pipeline) Shutdown

func (c Pipeline) Shutdown(ctx context.Context) *StatusCmd

func (Pipeline) ShutdownNoSave

func (c Pipeline) ShutdownNoSave(ctx context.Context) *StatusCmd

func (Pipeline) ShutdownSave

func (c Pipeline) ShutdownSave(ctx context.Context) *StatusCmd

func (Pipeline) SlaveOf

func (c Pipeline) SlaveOf(ctx context.Context, host, port string) *StatusCmd

func (Pipeline) SlowLogGet

func (c Pipeline) SlowLogGet(ctx context.Context, num int64) *SlowLogCmd

func (Pipeline) Sort

func (c Pipeline) Sort(ctx context.Context, key string, sort *Sort) *StringSliceCmd

func (Pipeline) SortInterfaces

func (c Pipeline) SortInterfaces(ctx context.Context, key string, sort *Sort) *SliceCmd

func (Pipeline) SortStore

func (c Pipeline) SortStore(ctx context.Context, key, store string, sort *Sort) *IntCmd

func (Pipeline) StrLen

func (c Pipeline) StrLen(ctx context.Context, key string) *IntCmd

func (Pipeline) SwapDB

func (c Pipeline) SwapDB(ctx context.Context, index1, index2 int) *StatusCmd

func (Pipeline) Sync

func (c Pipeline) Sync(ctx context.Context)

func (Pipeline) TTL

func (c Pipeline) TTL(ctx context.Context, key string) *DurationCmd

func (Pipeline) Time

func (c Pipeline) Time(ctx context.Context) *TimeCmd

func (Pipeline) Touch

func (c Pipeline) Touch(ctx context.Context, keys ...string) *IntCmd

func (*Pipeline) TxPipeline

func (c *Pipeline) TxPipeline() Pipeliner

func (*Pipeline) TxPipelined

func (c *Pipeline) TxPipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmder, error)

func (Pipeline) Type

func (c Pipeline) Type(ctx context.Context, key string) *StatusCmd
func (c Pipeline) Unlink(ctx context.Context, keys ...string) *IntCmd

func (Pipeline) Wait

func (c Pipeline) Wait(ctx context.Context, numSlaves int, timeout time.Duration) *IntCmd

func (Pipeline) XAck

func (c Pipeline) XAck(ctx context.Context, stream, group string, ids ...string) *IntCmd

func (Pipeline) XAdd

func (c Pipeline) XAdd(ctx context.Context, a *XAddArgs) *StringCmd

func (Pipeline) XClaim

func (c Pipeline) XClaim(ctx context.Context, a *XClaimArgs) *XMessageSliceCmd

func (Pipeline) XClaimJustID

func (c Pipeline) XClaimJustID(ctx context.Context, a *XClaimArgs) *StringSliceCmd

func (Pipeline) XDel

func (c Pipeline) XDel(ctx context.Context, stream string, ids ...string) *IntCmd

func (Pipeline) XGroupCreate

func (c Pipeline) XGroupCreate(ctx context.Context, stream, group, start string) *StatusCmd

func (Pipeline) XGroupCreateMkStream

func (c Pipeline) XGroupCreateMkStream(ctx context.Context, stream, group, start string) *StatusCmd

func (Pipeline) XGroupDelConsumer

func (c Pipeline) XGroupDelConsumer(ctx context.Context, stream, group, consumer string) *IntCmd

func (Pipeline) XGroupDestroy

func (c Pipeline) XGroupDestroy(ctx context.Context, stream, group string) *IntCmd

func (Pipeline) XGroupSetID

func (c Pipeline) XGroupSetID(ctx context.Context, stream, group, start string) *StatusCmd

func (Pipeline) XInfoGroups

func (c Pipeline) XInfoGroups(ctx context.Context, key string) *XInfoGroupsCmd

func (Pipeline) XInfoStream

func (c Pipeline) XInfoStream(ctx context.Context, key string) *XInfoStreamCmd

func (Pipeline) XLen

func (c Pipeline) XLen(ctx context.Context, stream string) *IntCmd

func (Pipeline) XPending

func (c Pipeline) XPending(ctx context.Context, stream, group string) *XPendingCmd

func (Pipeline) XPendingExt

func (c Pipeline) XPendingExt(ctx context.Context, a *XPendingExtArgs) *XPendingExtCmd

func (Pipeline) XRange

func (c Pipeline) XRange(ctx context.Context, stream, start, stop string) *XMessageSliceCmd

func (Pipeline) XRangeN

func (c Pipeline) XRangeN(ctx context.Context, stream, start, stop string, count int64) *XMessageSliceCmd

func (Pipeline) XRead

func (c Pipeline) XRead(ctx context.Context, a *XReadArgs) *XStreamSliceCmd

func (Pipeline) XReadGroup

func (c Pipeline) XReadGroup(ctx context.Context, a *XReadGroupArgs) *XStreamSliceCmd

func (Pipeline) XReadStreams

func (c Pipeline) XReadStreams(ctx context.Context, streams ...string) *XStreamSliceCmd

func (Pipeline) XRevRange

func (c Pipeline) XRevRange(ctx context.Context, stream, start, stop string) *XMessageSliceCmd

func (Pipeline) XRevRangeN

func (c Pipeline) XRevRangeN(ctx context.Context, stream, start, stop string, count int64) *XMessageSliceCmd

func (Pipeline) XTrim

func (c Pipeline) XTrim(ctx context.Context, key string, maxLen int64) *IntCmd

func (Pipeline) XTrimApprox

func (c Pipeline) XTrimApprox(ctx context.Context, key string, maxLen int64) *IntCmd

func (Pipeline) ZAdd

func (c Pipeline) ZAdd(ctx context.Context, key string, members ...*Z) *IntCmd

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

func (Pipeline) ZAddCh

func (c Pipeline) ZAddCh(ctx context.Context, key string, members ...*Z) *IntCmd

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

func (Pipeline) ZAddNX

func (c Pipeline) ZAddNX(ctx context.Context, key string, members ...*Z) *IntCmd

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

func (Pipeline) ZAddNXCh

func (c Pipeline) ZAddNXCh(ctx context.Context, key string, members ...*Z) *IntCmd

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

func (Pipeline) ZAddXX

func (c Pipeline) ZAddXX(ctx context.Context, key string, members ...*Z) *IntCmd

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

func (Pipeline) ZAddXXCh

func (c Pipeline) ZAddXXCh(ctx context.Context, key string, members ...*Z) *IntCmd

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

func (Pipeline) ZCard

func (c Pipeline) ZCard(ctx context.Context, key string) *IntCmd

func (Pipeline) ZCount

func (c Pipeline) ZCount(ctx context.Context, key, min, max string) *IntCmd

func (Pipeline) ZIncr

func (c Pipeline) ZIncr(ctx context.Context, key string, member *Z) *FloatCmd

Redis `ZADD key INCR score member` command.

func (Pipeline) ZIncrBy

func (c Pipeline) ZIncrBy(ctx context.Context, key string, increment float64, member string) *FloatCmd

func (Pipeline) ZIncrNX

func (c Pipeline) ZIncrNX(ctx context.Context, key string, member *Z) *FloatCmd

Redis `ZADD key NX INCR score member` command.

func (Pipeline) ZIncrXX

func (c Pipeline) ZIncrXX(ctx context.Context, key string, member *Z) *FloatCmd

Redis `ZADD key XX INCR score member` command.

func (Pipeline) ZInterStore

func (c Pipeline) ZInterStore(ctx context.Context, destination string, store *ZStore) *IntCmd

func (Pipeline) ZLexCount

func (c Pipeline) ZLexCount(ctx context.Context, key, min, max string) *IntCmd

func (Pipeline) ZPopMax

func (c Pipeline) ZPopMax(ctx context.Context, key string, count ...int64) *ZSliceCmd

func (Pipeline) ZPopMin

func (c Pipeline) ZPopMin(ctx context.Context, key string, count ...int64) *ZSliceCmd

func (Pipeline) ZRange

func (c Pipeline) ZRange(ctx context.Context, key string, start, stop int64) *StringSliceCmd

func (Pipeline) ZRangeByLex

func (c Pipeline) ZRangeByLex(ctx context.Context, key string, opt *ZRangeBy) *StringSliceCmd

func (Pipeline) ZRangeByScore

func (c Pipeline) ZRangeByScore(ctx context.Context, key string, opt *ZRangeBy) *StringSliceCmd

func (Pipeline) ZRangeByScoreWithScores

func (c Pipeline) ZRangeByScoreWithScores(ctx context.Context, key string, opt *ZRangeBy) *ZSliceCmd

func (Pipeline) ZRangeWithScores

func (c Pipeline) ZRangeWithScores(ctx context.Context, key string, start, stop int64) *ZSliceCmd

func (Pipeline) ZRank

func (c Pipeline) ZRank(ctx context.Context, key, member string) *IntCmd

func (Pipeline) ZRem

func (c Pipeline) ZRem(ctx context.Context, key string, members ...interface{}) *IntCmd

func (Pipeline) ZRemRangeByLex

func (c Pipeline) ZRemRangeByLex(ctx context.Context, key, min, max string) *IntCmd

func (Pipeline) ZRemRangeByRank

func (c Pipeline) ZRemRangeByRank(ctx context.Context, key string, start, stop int64) *IntCmd

func (Pipeline) ZRemRangeByScore

func (c Pipeline) ZRemRangeByScore(ctx context.Context, key, min, max string) *IntCmd

func (Pipeline) ZRevRange

func (c Pipeline) ZRevRange(ctx context.Context, key string, start, stop int64) *StringSliceCmd

func (Pipeline) ZRevRangeByLex

func (c Pipeline) ZRevRangeByLex(ctx context.Context, key string, opt *ZRangeBy) *StringSliceCmd

func (Pipeline) ZRevRangeByScore

func (c Pipeline) ZRevRangeByScore(ctx context.Context, key string, opt *ZRangeBy) *StringSliceCmd

func (Pipeline) ZRevRangeByScoreWithScores

func (c Pipeline) ZRevRangeByScoreWithScores(ctx context.Context, key string, opt *ZRangeBy) *ZSliceCmd

func (Pipeline) ZRevRangeWithScores

func (c Pipeline) ZRevRangeWithScores(ctx context.Context, key string, start, stop int64) *ZSliceCmd

func (Pipeline) ZRevRank

func (c Pipeline) ZRevRank(ctx context.Context, key, member string) *IntCmd

func (Pipeline) ZScan

func (c Pipeline) ZScan(ctx context.Context, key string, cursor uint64, match string, count int64) *ScanCmd

func (Pipeline) ZScore

func (c Pipeline) ZScore(ctx context.Context, key, member string) *FloatCmd

func (Pipeline) ZUnionStore

func (c Pipeline) ZUnionStore(ctx context.Context, dest string, store *ZStore) *IntCmd

type Pipeliner

type Pipeliner interface {
	StatefulCmdable
	Do(ctx context.Context, args ...interface{}) *Cmd
	Process(ctx context.Context, cmd Cmder) error
	Close() error
	Discard() error
	Exec(ctx context.Context) ([]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.

Example
pubsub := rdb.Subscribe(ctx, "mychannel1")

// Wait for confirmation that subscription is created before publishing anything.
_, err := pubsub.Receive(ctx)
if err != nil {
	panic(err)
}

// Go channel which receives messages.
ch := pubsub.Channel()

// Publish a message.
err = rdb.Publish(ctx, "mychannel1", "hello").Err()
if err != nil {
	panic(err)
}

time.AfterFunc(time.Second, func() {
	// When pubsub is closed channel is closed too.
	_ = pubsub.Close()
})

// Consume messages.
for msg := range ch {
	fmt.Println(msg.Channel, msg.Payload)
}
Output:

mychannel1 hello

func (*PubSub) Channel

func (c *PubSub) Channel() <-chan *Message

Channel returns a Go channel for concurrently receiving messages. The channel is closed together with the PubSub. If the Go channel is blocked full for 30 seconds the message is dropped. Receive* APIs can not be used after channel is created.

go-redis periodically sends ping messages to test connection health and re-subscribes if ping can not not received for 30 seconds.

func (*PubSub) ChannelSize

func (c *PubSub) ChannelSize(size int) <-chan *Message

ChannelSize is like Channel, but creates a Go channel with specified buffer size.

func (*PubSub) ChannelWithSubscriptions

func (c *PubSub) ChannelWithSubscriptions(ctx context.Context, size int) <-chan interface{}

ChannelWithSubscriptions is like Channel, but message type can be either *Subscription or *Message. Subscription messages can be used to detect reconnections.

ChannelWithSubscriptions can not be used together with Channel or ChannelSize.

func (*PubSub) Close

func (c *PubSub) Close() error

func (*PubSub) PSubscribe

func (c *PubSub) PSubscribe(ctx context.Context, patterns ...string) error

PSubscribe the client to the given patterns. It returns empty subscription if there are no patterns.

func (*PubSub) PUnsubscribe

func (c *PubSub) PUnsubscribe(ctx context.Context, patterns ...string) error

PUnsubscribe the client from the given patterns, or from all of them if none is given.

func (*PubSub) Ping

func (c *PubSub) Ping(ctx context.Context, payload ...string) error

func (*PubSub) Receive

func (c *PubSub) Receive(ctx context.Context) (interface{}, error)

Receive returns a message as a Subscription, Message, Pong or error. See PubSub example for details. This is low-level API and in most cases Channel should be used instead.

Example
pubsub := rdb.Subscribe(ctx, "mychannel2")
defer pubsub.Close()

for i := 0; i < 2; i++ {
	// ReceiveTimeout is a low level API. Use ReceiveMessage instead.
	msgi, err := pubsub.ReceiveTimeout(ctx, time.Second)
	if err != nil {
		break
	}

	switch msg := msgi.(type) {
	case *redis.Subscription:
		fmt.Println("subscribed to", msg.Channel)

		_, err := rdb.Publish(ctx, "mychannel2", "hello").Result()
		if err != nil {
			panic(err)
		}
	case *redis.Message:
		fmt.Println("received", msg.Payload, "from", msg.Channel)
	default:
		panic("unreached")
	}
}

// sent message to 1 rdb
// received hello from mychannel2
Output:

func (*PubSub) ReceiveMessage

func (c *PubSub) ReceiveMessage(ctx context.Context) (*Message, error)

ReceiveMessage returns a Message or error ignoring Subscription and Pong messages. This is low-level API and in most cases Channel should be used instead.

func (*PubSub) ReceiveTimeout

func (c *PubSub) ReceiveTimeout(ctx context.Context, timeout time.Duration) (interface{}, error)

ReceiveTimeout acts like Receive but returns an error if message is not received in time. This is low-level API and in most cases Channel should be used instead.

func (*PubSub) String

func (c *PubSub) String() string

func (*PubSub) Subscribe

func (c *PubSub) Subscribe(ctx context.Context, channels ...string) error

Subscribe the client to the specified channels. It returns empty subscription if there are no channels.

func (*PubSub) Unsubscribe

func (c *PubSub) Unsubscribe(ctx context.Context, channels ...string) error

Unsubscribe the client from the given channels, or from all of them if none is given.

type Ring

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

Ring is a Redis client that uses consistent hashing to distribute keys across multiple Redis servers (shards). It's safe for concurrent use by multiple goroutines.

Ring monitors the state of each shard and removes dead shards from the ring. When a shard comes online it is added back to the ring. This gives you maximum availability and partition tolerance, but no consistency between different shards or even clients. Each client uses shards that are available to the client and does not do any coordination when shard state is changed.

Ring should be used when you need multiple Redis servers for caching and can tolerate losing data when one of the servers dies. Otherwise you should use Redis Cluster.

func NewRing

func NewRing(opt *RingOptions) *Ring
Example
rdb := redis.NewRing(&redis.RingOptions{
	Addrs: map[string]string{
		"shard1": ":7000",
		"shard2": ":7001",
		"shard3": ":7002",
	},
})
rdb.Ping(ctx)
Output:

func (*Ring) AddHook

func (hs *Ring) AddHook(hook Hook)

func (Ring) Append

func (c Ring) Append(ctx context.Context, key, value string) *IntCmd

func (Ring) BLPop

func (c Ring) BLPop(ctx context.Context, timeout time.Duration, keys ...string) *StringSliceCmd

func (Ring) BRPop

func (c Ring) BRPop(ctx context.Context, timeout time.Duration, keys ...string) *StringSliceCmd

func (Ring) BRPopLPush

func (c Ring) BRPopLPush(ctx context.Context, source, destination string, timeout time.Duration) *StringCmd

func (Ring) BZPopMax

func (c Ring) BZPopMax(ctx context.Context, timeout time.Duration, keys ...string) *ZWithKeyCmd

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

func (Ring) BZPopMin

func (c Ring) BZPopMin(ctx context.Context, timeout time.Duration, keys ...string) *ZWithKeyCmd

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

func (Ring) BgRewriteAOF

func (c Ring) BgRewriteAOF(ctx context.Context) *StatusCmd

func (Ring) BgSave

func (c Ring) BgSave(ctx context.Context) *StatusCmd

func (Ring) BitCount

func (c Ring) BitCount(ctx context.Context, key string, bitCount *BitCount) *IntCmd

func (Ring) BitField

func (c Ring) BitField(ctx context.Context, key string, args ...interface{}) *IntSliceCmd

func (Ring) BitOpAnd

func (c Ring) BitOpAnd(ctx context.Context, destKey string, keys ...string) *IntCmd

func (Ring) BitOpNot

func (c Ring) BitOpNot(ctx context.Context, destKey string, key string) *IntCmd

func (Ring) BitOpOr

func (c Ring) BitOpOr(ctx context.Context, destKey string, keys ...string) *IntCmd

func (Ring) BitOpXor

func (c Ring) BitOpXor(ctx context.Context, destKey string, keys ...string) *IntCmd

func (Ring) BitPos

func (c Ring) BitPos(ctx context.Context, key string, bit int64, pos ...int64) *IntCmd

func (Ring) ClientGetName

func (c Ring) ClientGetName(ctx context.Context) *StringCmd

ClientGetName returns the name of the connection.

func (Ring) ClientID

func (c Ring) ClientID(ctx context.Context) *IntCmd

func (Ring) ClientKill

func (c Ring) ClientKill(ctx context.Context, ipPort string) *StatusCmd

func (Ring) ClientKillByFilter

func (c Ring) ClientKillByFilter(ctx context.Context, keys ...string) *IntCmd

ClientKillByFilter is new style syntax, while the ClientKill is old

CLIENT KILL <option> [value] ... <option> [value]

func (Ring) ClientList

func (c Ring) ClientList(ctx context.Context) *StringCmd

func (Ring) ClientPause

func (c Ring) ClientPause(ctx context.Context, dur time.Duration) *BoolCmd

func (Ring) ClientUnblock

func (c Ring) ClientUnblock(ctx context.Context, id int64) *IntCmd

func (Ring) ClientUnblockWithError

func (c Ring) ClientUnblockWithError(ctx context.Context, id int64) *IntCmd

func (*Ring) Close

func (c *Ring) Close() error

Close closes the ring client, releasing any open resources.

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

func (Ring) ClusterAddSlots

func (c Ring) ClusterAddSlots(ctx context.Context, slots ...int) *StatusCmd

func (Ring) ClusterAddSlotsRange

func (c Ring) ClusterAddSlotsRange(ctx context.Context, min, max int) *StatusCmd

func (Ring) ClusterCountFailureReports

func (c Ring) ClusterCountFailureReports(ctx context.Context, nodeID string) *IntCmd

func (Ring) ClusterCountKeysInSlot

func (c Ring) ClusterCountKeysInSlot(ctx context.Context, slot int) *IntCmd

func (Ring) ClusterDelSlots

func (c Ring) ClusterDelSlots(ctx context.Context, slots ...int) *StatusCmd

func (Ring) ClusterDelSlotsRange

func (c Ring) ClusterDelSlotsRange(ctx context.Context, min, max int) *StatusCmd

func (Ring) ClusterFailover

func (c Ring) ClusterFailover(ctx context.Context) *StatusCmd

func (Ring) ClusterForget

func (c Ring) ClusterForget(ctx context.Context, nodeID string) *StatusCmd

func (Ring) ClusterGetKeysInSlot

func (c Ring) ClusterGetKeysInSlot(ctx context.Context, slot int, count int) *StringSliceCmd

func (Ring) ClusterInfo

func (c Ring) ClusterInfo(ctx context.Context) *StringCmd

func (Ring) ClusterKeySlot

func (c Ring) ClusterKeySlot(ctx context.Context, key string) *IntCmd

func (Ring) ClusterMeet

func (c Ring) ClusterMeet(ctx context.Context, host, port string) *StatusCmd

func (Ring) ClusterNodes

func (c Ring) ClusterNodes(ctx context.Context) *StringCmd

func (Ring) ClusterReplicate

func (c Ring) ClusterReplicate(ctx context.Context, nodeID string) *StatusCmd

func (Ring) ClusterResetHard

func (c Ring) ClusterResetHard(ctx context.Context) *StatusCmd

func (Ring) ClusterResetSoft

func (c Ring) ClusterResetSoft(ctx context.Context) *StatusCmd

func (Ring) ClusterSaveConfig

func (c Ring) ClusterSaveConfig(ctx context.Context) *StatusCmd

func (Ring) ClusterSlaves

func (c Ring) ClusterSlaves(ctx context.Context, nodeID string) *StringSliceCmd

func (Ring) ClusterSlots

func (c Ring) ClusterSlots(ctx context.Context) *ClusterSlotsCmd

func (Ring) Command

func (c Ring) Command(ctx context.Context) *CommandsInfoCmd

func (Ring) ConfigGet

func (c Ring) ConfigGet(ctx context.Context, parameter string) *SliceCmd

func (Ring) ConfigResetStat

func (c Ring) ConfigResetStat(ctx context.Context) *StatusCmd

func (Ring) ConfigRewrite

func (c Ring) ConfigRewrite(ctx context.Context) *StatusCmd

func (Ring) ConfigSet

func (c Ring) ConfigSet(ctx context.Context, parameter, value string) *StatusCmd

func (*Ring) Context

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

func (Ring) DBSize

func (c Ring) DBSize(ctx context.Context) *IntCmd

func (Ring) DebugObject

func (c Ring) DebugObject(ctx context.Context, key string) *StringCmd

func (Ring) Decr

func (c Ring) Decr(ctx context.Context, key string) *IntCmd

func (Ring) DecrBy

func (c Ring) DecrBy(ctx context.Context, key string, decrement int64) *IntCmd

func (Ring) Del

func (c Ring) Del(ctx context.Context, keys ...string) *IntCmd

func (*Ring) Do

func (c *Ring) Do(ctx context.Context, args ...interface{}) *Cmd

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

func (Ring) Dump

func (c Ring) Dump(ctx context.Context, key string) *StringCmd

func (Ring) Echo

func (c Ring) Echo(ctx context.Context, message interface{}) *StringCmd

func (Ring) Eval

func (c Ring) Eval(ctx context.Context, script string, keys []string, args ...interface{}) *Cmd

func (Ring) EvalSha

func (c Ring) EvalSha(ctx context.Context, sha1 string, keys []string, args ...interface{}) *Cmd

func (Ring) Exists

func (c Ring) Exists(ctx context.Context, keys ...string) *IntCmd

func (Ring) Expire

func (c Ring) Expire(ctx context.Context, key string, expiration time.Duration) *BoolCmd

func (Ring) ExpireAt

func (c Ring) ExpireAt(ctx context.Context, key string, tm time.Time) *BoolCmd

func (Ring) FlushAll

func (c Ring) FlushAll(ctx context.Context) *StatusCmd

func (Ring) FlushAllAsync

func (c Ring) FlushAllAsync(ctx context.Context) *StatusCmd

func (Ring) FlushDB

func (c Ring) FlushDB(ctx context.Context) *StatusCmd

func (Ring) FlushDBAsync

func (c Ring) FlushDBAsync(ctx context.Context) *StatusCmd

func (*Ring) ForEachShard

func (c *Ring) ForEachShard(
	ctx context.Context,
	fn func(ctx context.Context, client *Client) error,
) error

ForEachShard concurrently calls the fn on each live shard in the ring. It returns the first error if any.

func (Ring) GeoAdd

func (c Ring) GeoAdd(ctx context.Context, key string, geoLocation ...*GeoLocation) *IntCmd

func (Ring) GeoDist

func (c Ring) GeoDist(
	ctx context.Context, key string, member1, member2, unit string,
) *FloatCmd

func (Ring) GeoHash

func (c Ring) GeoHash(ctx context.Context, key string, members ...string) *StringSliceCmd

func (Ring) GeoPos

func (c Ring) GeoPos(ctx context.Context, key string, members ...string) *GeoPosCmd

func (Ring) GeoRadius

func (c Ring) GeoRadius(
	ctx context.Context, key string, longitude, latitude float64, query *GeoRadiusQuery,
) *GeoLocationCmd

GeoRadius is a read-only GEORADIUS_RO command.

func (Ring) GeoRadiusByMember

func (c Ring) GeoRadiusByMember(
	ctx context.Context, key, member string, query *GeoRadiusQuery,
) *GeoLocationCmd

GeoRadius is a read-only GEORADIUSBYMEMBER_RO command.

func (Ring) GeoRadiusByMemberStore

func (c Ring) GeoRadiusByMemberStore(
	ctx context.Context, key, member string, query *GeoRadiusQuery,
) *IntCmd

GeoRadiusByMemberStore is a writing GEORADIUSBYMEMBER command.

func (Ring) GeoRadiusStore

func (c Ring) GeoRadiusStore(
	ctx context.Context, key string, longitude, latitude float64, query *GeoRadiusQuery,
) *IntCmd

GeoRadiusStore is a writing GEORADIUS command.

func (Ring) Get

func (c Ring) Get(ctx context.Context, key string) *StringCmd

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

func (Ring) GetBit

func (c Ring) GetBit(ctx context.Context, key string, offset int64) *IntCmd

func (Ring) GetRange

func (c Ring) GetRange(ctx context.Context, key string, start, end int64) *StringCmd

func (Ring) GetSet

func (c Ring) GetSet(ctx context.Context, key string, value interface{}) *StringCmd

func (Ring) HDel

func (c Ring) HDel(ctx context.Context, key string, fields ...string) *IntCmd

func (Ring) HExists

func (c Ring) HExists(ctx context.Context, key, field string) *BoolCmd

func (Ring) HGet

func (c Ring) HGet(ctx context.Context, key, field string) *StringCmd

func (Ring) HGetAll

func (c Ring) HGetAll(ctx context.Context, key string) *StringStringMapCmd

func (Ring) HIncrBy

func (c Ring) HIncrBy(ctx context.Context, key, field string, incr int64) *IntCmd

func (Ring) HIncrByFloat

func (c Ring) HIncrByFloat(ctx context.Context, key, field string, incr float64) *FloatCmd

func (Ring) HKeys

func (c Ring) HKeys(ctx context.Context, key string) *StringSliceCmd

func (Ring) HLen

func (c Ring) HLen(ctx context.Context, key string) *IntCmd

func (Ring) HMGet

func (c Ring) HMGet(ctx context.Context, key string, fields ...string) *SliceCmd

HMGet returns the values for the specified fields in the hash stored at key. It returns an interface{} to distinguish between empty string and nil value.

func (Ring) HMSet

func (c Ring) HMSet(ctx context.Context, key string, values ...interface{}) *BoolCmd

HMSet is a deprecated version of HSet left for compatibility with Redis 3.

func (Ring) HScan

func (c Ring) HScan(ctx context.Context, key string, cursor uint64, match string, count int64) *ScanCmd

func (Ring) HSet

func (c Ring) HSet(ctx context.Context, key string, values ...interface{}) *IntCmd

HSet accepts values in following formats:

  • HSet("myhash", "key1", "value1", "key2", "value2")
  • HSet("myhash", []string{"key1", "value1", "key2", "value2"})
  • HSet("myhash", map[string]interface{}{"key1": "value1", "key2": "value2"})

Note that it requires Redis v4 for multiple field/value pairs support.

func (Ring) HSetNX

func (c Ring) HSetNX(ctx context.Context, key, field string, value interface{}) *BoolCmd

func (Ring) HVals

func (c Ring) HVals(ctx context.Context, key string) *StringSliceCmd

func (Ring) Incr

func (c Ring) Incr(ctx context.Context, key string) *IntCmd

func (Ring) IncrBy

func (c Ring) IncrBy(ctx context.Context, key string, value int64) *IntCmd

func (Ring) IncrByFloat

func (c Ring) IncrByFloat(ctx context.Context, key string, value float64) *FloatCmd

func (Ring) Info

func (c Ring) Info(ctx context.Context, section ...string) *StringCmd

func (Ring) Keys

func (c Ring) Keys(ctx context.Context, pattern string) *StringSliceCmd

func (Ring) LIndex

func (c Ring) LIndex(ctx context.Context, key string, index int64) *StringCmd

func (Ring) LInsert

func (c Ring) LInsert(ctx context.Context, key, op string, pivot, value interface{}) *IntCmd

func (Ring) LInsertAfter

func (c Ring) LInsertAfter(ctx context.Context, key string, pivot, value interface{}) *IntCmd

func (Ring) LInsertBefore

func (c Ring) LInsertBefore(ctx context.Context, key string, pivot, value interface{}) *IntCmd

func (Ring) LLen

func (c Ring) LLen(ctx context.Context, key string) *IntCmd

func (Ring) LPop

func (c Ring) LPop(ctx context.Context, key string) *StringCmd

func (Ring) LPos

func (c Ring) LPos(ctx context.Context, key string, value string, a LPosArgs) *IntCmd

func (Ring) LPosCount

func (c Ring) LPosCount(ctx context.Context, key string, value string, count int64, a LPosArgs) *IntSliceCmd

func (Ring) LPush

func (c Ring) LPush(ctx context.Context, key string, values ...interface{}) *IntCmd

func (Ring) LPushX

func (c Ring) LPushX(ctx context.Context, key string, values ...interface{}) *IntCmd

func (Ring) LRange

func (c Ring) LRange(ctx context.Context, key string, start, stop int64) *StringSliceCmd

func (Ring) LRem

func (c Ring) LRem(ctx context.Context, key string, count int64, value interface{}) *IntCmd

func (Ring) LSet

func (c Ring) LSet(ctx context.Context, key string, index int64, value interface{}) *StatusCmd

func (Ring) LTrim

func (c Ring) LTrim(ctx context.Context, key string, start, stop int64) *StatusCmd

func (Ring) LastSave

func (c Ring) LastSave(ctx context.Context) *IntCmd

func (*Ring) Len

func (c *Ring) Len() int

Len returns the current number of shards in the ring.

func (Ring) MGet

func (c Ring) MGet(ctx context.Context, keys ...string) *SliceCmd

func (Ring) MSet

func (c Ring) MSet(ctx context.Context, values ...interface{}) *StatusCmd

MSet is like Set but accepts multiple values:

  • MSet("key1", "value1", "key2", "value2")
  • MSet([]string{"key1", "value1", "key2", "value2"})
  • MSet(map[string]interface{}{"key1": "value1", "key2": "value2"})

func (Ring) MSetNX

func (c Ring) MSetNX(ctx context.Context, values ...interface{}) *BoolCmd

MSetNX is like SetNX but accepts multiple values:

  • MSetNX("key1", "value1", "key2", "value2")
  • MSetNX([]string{"key1", "value1", "key2", "value2"})
  • MSetNX(map[string]interface{}{"key1": "value1", "key2": "value2"})

func (Ring) MemoryUsage

func (c Ring) MemoryUsage(ctx context.Context, key string, samples ...int) *IntCmd

func (Ring) Migrate

func (c Ring) Migrate(ctx context.Context, host, port, key string, db int, timeout time.Duration) *StatusCmd

func (Ring) Move

func (c Ring) Move(ctx context.Context, key string, db int) *BoolCmd

func (Ring) ObjectEncoding

func (c Ring) ObjectEncoding(ctx context.Context, key string) *StringCmd

func (Ring) ObjectIdleTime

func (c Ring) ObjectIdleTime(ctx context.Context, key string) *DurationCmd

func (Ring) ObjectRefCount

func (c Ring) ObjectRefCount(ctx context.Context, key string) *IntCmd

func (*Ring) Options

func (c *Ring) Options() *RingOptions

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

func (Ring) PExpire

func (c Ring) PExpire(ctx context.Context, key string, expiration time.Duration) *BoolCmd

func (Ring) PExpireAt

func (c Ring) PExpireAt(ctx context.Context, key string, tm time.Time) *BoolCmd

func (Ring) PFAdd

func (c Ring) PFAdd(ctx context.Context, key string, els ...interface{}) *IntCmd

func (Ring) PFCount

func (c Ring) PFCount(ctx context.Context, keys ...string) *IntCmd

func (Ring) PFMerge

func (c Ring) PFMerge(ctx context.Context, dest string, keys ...string) *StatusCmd

func (*Ring) PSubscribe

func (c *Ring) PSubscribe(ctx context.Context, channels ...string) *PubSub

PSubscribe subscribes the client to the given patterns.

func (Ring) PTTL

func (c Ring) PTTL(ctx context.Context, key string) *DurationCmd

func (Ring) Persist

func (c Ring) Persist(ctx context.Context, key string) *BoolCmd

func (Ring) Ping

func (c Ring) Ping(ctx context.Context) *StatusCmd

func (*Ring) Pipeline

func (c *Ring) Pipeline() Pipeliner

func (*Ring) Pipelined

func (c *Ring) Pipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmder, error)

func (*Ring) PoolStats

func (c *Ring) PoolStats() *PoolStats

PoolStats returns accumulated connection pool stats.

func (*Ring) Process

func (c *Ring) Process(ctx context.Context, cmd Cmder) error

func (Ring) PubSubChannels

func (c Ring) PubSubChannels(ctx context.Context, pattern string) *StringSliceCmd

func (Ring) PubSubNumPat

func (c Ring) PubSubNumPat(ctx context.Context) *IntCmd

func (Ring) PubSubNumSub

func (c Ring) PubSubNumSub(ctx context.Context, channels ...string) *StringIntMapCmd

func (Ring) Publish

func (c Ring) Publish(ctx context.Context, channel string, message interface{}) *IntCmd

Publish posts the message to the channel.

func (Ring) Quit

func (c Ring) Quit(ctx context.Context) *StatusCmd

func (Ring) RPop

func (c Ring) RPop(ctx context.Context, key string) *StringCmd

func (Ring) RPopLPush

func (c Ring) RPopLPush(ctx context.Context, source, destination string) *StringCmd

func (Ring) RPush

func (c Ring) RPush(ctx context.Context, key string, values ...interface{}) *IntCmd

func (Ring) RPushX

func (c Ring) RPushX(ctx context.Context, key string, values ...interface{}) *IntCmd

func (Ring) RandomKey

func (c Ring) RandomKey(ctx context.Context) *StringCmd

func (Ring) ReadOnly

func (c Ring) ReadOnly(ctx context.Context) *StatusCmd

func (Ring) ReadWrite

func (c Ring) ReadWrite(ctx context.Context) *StatusCmd

func (Ring) Rename

func (c Ring) Rename(ctx context.Context, key, newkey string) *StatusCmd

func (Ring) RenameNX

func (c Ring) RenameNX(ctx context.Context, key, newkey string) *BoolCmd

func (Ring) Restore

func (c Ring) Restore(ctx context.Context, key string, ttl time.Duration, value string) *StatusCmd

func (Ring) RestoreReplace

func (c Ring) RestoreReplace(ctx context.Context, key string, ttl time.Duration, value string) *StatusCmd

func (Ring) SAdd

func (c Ring) SAdd(ctx context.Context, key string, members ...interface{}) *IntCmd

func (Ring) SCard

func (c Ring) SCard(ctx context.Context, key string) *IntCmd

func (Ring) SDiff

func (c Ring) SDiff(ctx context.Context, keys ...string) *StringSliceCmd

func (Ring) SDiffStore

func (c Ring) SDiffStore(ctx context.Context, destination string, keys ...string) *IntCmd

func (Ring) SInter

func (c Ring) SInter(ctx context.Context, keys ...string) *StringSliceCmd

func (Ring) SInterStore

func (c Ring) SInterStore(ctx context.Context, destination string, keys ...string) *IntCmd

func (Ring) SIsMember

func (c Ring) SIsMember(ctx context.Context, key string, member interface{}) *BoolCmd

func (Ring) SMembers

func (c Ring) SMembers(ctx context.Context, key string) *StringSliceCmd

Redis `SMEMBERS key` command output as a slice.

func (Ring) SMembersMap

func (c Ring) SMembersMap(ctx context.Context, key string) *StringStructMapCmd

Redis `SMEMBERS key` command output as a map.

func (Ring) SMove

func (c Ring) SMove(ctx context.Context, source, destination string, member interface{}) *BoolCmd

func (Ring) SPop

func (c Ring) SPop(ctx context.Context, key string) *StringCmd

Redis `SPOP key` command.

func (Ring) SPopN

func (c Ring) SPopN(ctx context.Context, key string, count int64) *StringSliceCmd

Redis `SPOP key count` command.

func (Ring) SRandMember

func (c Ring) SRandMember(ctx context.Context, key string) *StringCmd

Redis `SRANDMEMBER key` command.

func (Ring) SRandMemberN

func (c Ring) SRandMemberN(ctx context.Context, key string, count int64) *StringSliceCmd

Redis `SRANDMEMBER key count` command.

func (Ring) SRem

func (c Ring) SRem(ctx context.Context, key string, members ...interface{}) *IntCmd

func (Ring) SScan

func (c Ring) SScan(ctx context.Context, key string, cursor uint64, match string, count int64) *ScanCmd

func (Ring) SUnion

func (c Ring) SUnion(ctx context.Context, keys ...string) *StringSliceCmd

func (Ring) SUnionStore

func (c Ring) SUnionStore(ctx context.Context, destination string, keys ...string) *IntCmd

func (Ring) Save

func (c Ring) Save(ctx context.Context) *StatusCmd

func (Ring) Scan

func (c Ring) Scan(ctx context.Context, cursor uint64, match string, keyType string, count int64) *ScanCmd

func (Ring) ScriptExists

func (c Ring) ScriptExists(ctx context.Context, hashes ...string) *BoolSliceCmd

func (Ring) ScriptFlush

func (c Ring) ScriptFlush(ctx context.Context) *StatusCmd

func (Ring) ScriptKill

func (c Ring) ScriptKill(ctx context.Context) *StatusCmd

func (Ring) ScriptLoad

func (c Ring) ScriptLoad(ctx context.Context, script string) *StringCmd

func (Ring) Set

func (c Ring) Set(ctx context.Context, 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. KeepTTL(-1) expiration is a Redis KEEPTTL option to keep existing TTL.

func (Ring) SetBit

func (c Ring) SetBit(ctx context.Context, key string, offset int64, value int) *IntCmd

func (Ring) SetEX

func (c Ring) SetEX(ctx context.Context, key string, value interface{}, expiration time.Duration) *StatusCmd

Redis `SETEX key expiration value` command.

func (Ring) SetNX

func (c Ring) SetNX(ctx context.Context, key string, value interface{}, expiration time.Duration) *BoolCmd

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

Zero expiration means the key has no expiration time. KeepTTL(-1) expiration is a Redis KEEPTTL option to keep existing TTL.

func (Ring) SetRange

func (c Ring) SetRange(ctx context.Context, key string, offset int64, value string) *IntCmd

func (Ring) SetXX

func (c Ring) SetXX(ctx context.Context, key string, value interface{}, expiration time.Duration) *BoolCmd

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

Zero expiration means the key has no expiration time. KeepTTL(-1) expiration is a Redis KEEPTTL option to keep existing TTL.

func (Ring) Shutdown

func (c Ring) Shutdown(ctx context.Context) *StatusCmd

func (Ring) ShutdownNoSave

func (c Ring) ShutdownNoSave(ctx context.Context) *StatusCmd

func (Ring) ShutdownSave

func (c Ring) ShutdownSave(ctx context.Context) *StatusCmd

func (Ring) SlaveOf

func (c Ring) SlaveOf(ctx context.Context, host, port string) *StatusCmd

func (Ring) SlowLogGet

func (c Ring) SlowLogGet(ctx context.Context, num int64) *SlowLogCmd

func (Ring) Sort

func (c Ring) Sort(ctx context.Context, key string, sort *Sort) *StringSliceCmd

func (Ring) SortInterfaces

func (c Ring) SortInterfaces(ctx context.Context, key string, sort *Sort) *SliceCmd

func (Ring) SortStore

func (c Ring) SortStore(ctx context.Context, key, store string, sort *Sort) *IntCmd

func (Ring) StrLen

func (c Ring) StrLen(ctx context.Context, key string) *IntCmd

func (*Ring) Subscribe

func (c *Ring) Subscribe(ctx context.Context, channels ...string) *PubSub

Subscribe subscribes the client to the specified channels.

func (Ring) Sync

func (c Ring) Sync(ctx context.Context)

func (Ring) TTL

func (c Ring) TTL(ctx context.Context, key string) *DurationCmd

func (Ring) Time

func (c Ring) Time(ctx context.Context) *TimeCmd

func (Ring) Touch

func (c Ring) Touch(ctx context.Context, keys ...string) *IntCmd

func (*Ring) TxPipeline

func (c *Ring) TxPipeline() Pipeliner

func (*Ring) TxPipelined

func (c *Ring) TxPipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmder, error)

func (Ring) Type

func (c Ring) Type(ctx context.Context, key string) *StatusCmd
func (c Ring) Unlink(ctx context.Context, keys ...string) *IntCmd

func (Ring) Wait

func (c Ring) Wait(ctx context.Context, numSlaves int, timeout time.Duration) *IntCmd

func (*Ring) Watch

func (c *Ring) Watch(ctx context.Context, fn func(*Tx) error, keys ...string) error

func (*Ring) WithContext

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

func (Ring) XAck

func (c Ring) XAck(ctx context.Context, stream, group string, ids ...string) *IntCmd

func (Ring) XAdd

func (c Ring) XAdd(ctx context.Context, a *XAddArgs) *StringCmd

func (Ring) XClaim

func (c Ring) XClaim(ctx context.Context, a *XClaimArgs) *XMessageSliceCmd

func (Ring) XClaimJustID

func (c Ring) XClaimJustID(ctx context.Context, a *XClaimArgs) *StringSliceCmd

func (Ring) XDel

func (c Ring) XDel(ctx context.Context, stream string, ids ...string) *IntCmd

func (Ring) XGroupCreate

func (c Ring) XGroupCreate(ctx context.Context, stream, group, start string) *StatusCmd

func (Ring) XGroupCreateMkStream

func (c Ring) XGroupCreateMkStream(ctx context.Context, stream, group, start string) *StatusCmd

func (Ring) XGroupDelConsumer

func (c Ring) XGroupDelConsumer(ctx context.Context, stream, group, consumer string) *IntCmd

func (Ring) XGroupDestroy

func (c Ring) XGroupDestroy(ctx context.Context, stream, group string) *IntCmd

func (Ring) XGroupSetID

func (c Ring) XGroupSetID(ctx context.Context, stream, group, start string) *StatusCmd

func (Ring) XInfoGroups

func (c Ring) XInfoGroups(ctx context.Context, key string) *XInfoGroupsCmd

func (Ring) XInfoStream

func (c Ring) XInfoStream(ctx context.Context, key string) *XInfoStreamCmd

func (Ring) XLen

func (c Ring) XLen(ctx context.Context, stream string) *IntCmd

func (Ring) XPending

func (c Ring) XPending(ctx context.Context, stream, group string) *XPendingCmd

func (Ring) XPendingExt

func (c Ring) XPendingExt(ctx context.Context, a *XPendingExtArgs) *XPendingExtCmd

func (Ring) XRange

func (c Ring) XRange(ctx context.Context, stream, start, stop string) *XMessageSliceCmd

func (Ring) XRangeN

func (c Ring) XRangeN(ctx context.Context, stream, start, stop string, count int64) *XMessageSliceCmd

func (Ring) XRead

func (c Ring) XRead(ctx context.Context, a *XReadArgs) *XStreamSliceCmd

func (Ring) XReadGroup

func (c Ring) XReadGroup(ctx context.Context, a *XReadGroupArgs) *XStreamSliceCmd

func (Ring) XReadStreams

func (c Ring) XReadStreams(ctx context.Context, streams ...string) *XStreamSliceCmd

func (Ring) XRevRange

func (c Ring) XRevRange(ctx context.Context, stream, start, stop string) *XMessageSliceCmd

func (Ring) XRevRangeN

func (c Ring) XRevRangeN(ctx context.Context, stream, start, stop string, count int64) *XMessageSliceCmd

func (Ring) XTrim

func (c Ring) XTrim(ctx context.Context, key string, maxLen int64) *IntCmd

func (Ring) XTrimApprox

func (c Ring) XTrimApprox(ctx context.Context, key string, maxLen int64) *IntCmd

func (Ring) ZAdd

func (c Ring) ZAdd(ctx context.Context, key string, members ...*Z) *IntCmd

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

func (Ring) ZAddCh

func (c Ring) ZAddCh(ctx context.Context, key string, members ...*Z) *IntCmd

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

func (Ring) ZAddNX

func (c Ring) ZAddNX(ctx context.Context, key string, members ...*Z) *IntCmd

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

func (Ring) ZAddNXCh

func (c Ring) ZAddNXCh(ctx context.Context, key string, members ...*Z) *IntCmd

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

func (Ring) ZAddXX

func (c Ring) ZAddXX(ctx context.Context, key string, members ...*Z) *IntCmd

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

func (Ring) ZAddXXCh

func (c Ring) ZAddXXCh(ctx context.Context, key string, members ...*Z) *IntCmd

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

func (Ring) ZCard

func (c Ring) ZCard(ctx context.Context, key string) *IntCmd

func (Ring) ZCount

func (c Ring) ZCount(ctx context.Context, key, min, max string) *IntCmd

func (Ring) ZIncr

func (c Ring) ZIncr(ctx context.Context, key string, member *Z) *FloatCmd

Redis `ZADD key INCR score member` command.

func (Ring) ZIncrBy

func (c Ring) ZIncrBy(ctx context.Context, key string, increment float64, member string) *FloatCmd

func (Ring) ZIncrNX

func (c Ring) ZIncrNX(ctx context.Context, key string, member *Z) *FloatCmd

Redis `ZADD key NX INCR score member` command.

func (Ring) ZIncrXX

func (c Ring) ZIncrXX(ctx context.Context, key string, member *Z) *FloatCmd

Redis `ZADD key XX INCR score member` command.

func (Ring) ZInterStore

func (c Ring) ZInterStore(ctx context.Context, destination string, store *ZStore) *IntCmd

func (Ring) ZLexCount

func (c Ring) ZLexCount(ctx context.Context, key, min, max string) *IntCmd

func (Ring) ZPopMax

func (c Ring) ZPopMax(ctx context.Context, key string, count ...int64) *ZSliceCmd

func (Ring) ZPopMin

func (c Ring) ZPopMin(ctx context.Context, key string, count ...int64) *ZSliceCmd

func (Ring) ZRange

func (c Ring) ZRange(ctx context.Context, key string, start, stop int64) *StringSliceCmd

func (Ring) ZRangeByLex

func (c Ring) ZRangeByLex(ctx context.Context, key string, opt *ZRangeBy) *StringSliceCmd

func (Ring) ZRangeByScore

func (c Ring) ZRangeByScore(ctx context.Context, key string, opt *ZRangeBy) *StringSliceCmd

func (Ring) ZRangeByScoreWithScores

func (c Ring) ZRangeByScoreWithScores(ctx context.Context, key string, opt *ZRangeBy) *ZSliceCmd

func (Ring) ZRangeWithScores

func (c Ring) ZRangeWithScores(ctx context.Context, key string, start, stop int64) *ZSliceCmd

func (Ring) ZRank

func (c Ring) ZRank(ctx context.Context, key, member string) *IntCmd

func (Ring) ZRem

func (c Ring) ZRem(ctx context.Context, key string, members ...interface{}) *IntCmd

func (Ring) ZRemRangeByLex

func (c Ring) ZRemRangeByLex(ctx context.Context, key, min, max string) *IntCmd

func (Ring) ZRemRangeByRank

func (c Ring) ZRemRangeByRank(ctx context.Context, key string, start, stop int64) *IntCmd

func (Ring) ZRemRangeByScore

func (c Ring) ZRemRangeByScore(ctx context.Context, key, min, max string) *IntCmd

func (Ring) ZRevRange

func (c Ring) ZRevRange(ctx context.Context, key string, start, stop int64) *StringSliceCmd

func (Ring) ZRevRangeByLex

func (c Ring) ZRevRangeByLex(ctx context.Context, key string, opt *ZRangeBy) *StringSliceCmd

func (Ring) ZRevRangeByScore

func (c Ring) ZRevRangeByScore(ctx context.Context, key string, opt *ZRangeBy) *StringSliceCmd

func (Ring) ZRevRangeByScoreWithScores

func (c Ring) ZRevRangeByScoreWithScores(ctx context.Context, key string, opt *ZRangeBy) *ZSliceCmd

func (Ring) ZRevRangeWithScores

func (c Ring) ZRevRangeWithScores(ctx context.Context, key string, start, stop int64) *ZSliceCmd

func (Ring) ZRevRank

func (c Ring) ZRevRank(ctx context.Context, key, member string) *IntCmd

func (Ring) ZScan

func (c Ring) ZScan(ctx context.Context, key string, cursor uint64, match string, count int64) *ScanCmd

func (Ring) ZScore

func (c Ring) ZScore(ctx context.Context, key, member string) *FloatCmd

func (Ring) ZUnionStore

func (c Ring) ZUnionStore(ctx context.Context, dest string, store *ZStore) *IntCmd

type RingOptions

type RingOptions struct {
	// Map of name => host:port addresses of ring shards.
	Addrs map[string]string

	// NewClient creates a shard client with provided name and options.
	NewClient func(name string, opt *Options) *Client

	// Frequency of PING commands sent to check shards availability.
	// Shard is considered down after 3 subsequent failed checks.
	HeartbeatFrequency time.Duration

	// NewConsistentHash returns a consistent hash that is used
	// to distribute keys across the shards.
	//
	// See https://medium.com/@dgryski/consistent-hashing-algorithmic-tradeoffs-ef6b8e2fcae8
	// for consistent hashing algorithmic tradeoffs.
	NewConsistentHash func(shards []string) ConsistentHash

	Dialer    func(ctx context.Context, network, addr string) (net.Conn, error)
	OnConnect func(ctx context.Context, cn *Conn) error

	Username string
	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
	Limiter   Limiter
}

RingOptions are used to configure a ring client and should be passed to NewRing.

type ScanCmd

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

func NewScanCmd

func NewScanCmd(ctx context.Context, process cmdable, args ...interface{}) *ScanCmd

func NewScanCmdResult

func NewScanCmdResult(keys []string, cursor uint64, err error) *ScanCmd

NewScanCmdResult returns a ScanCmd initialised with val and err for testing.

func (*ScanCmd) Args

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

func (*ScanCmd) Err

func (cmd *ScanCmd) Err() error

func (*ScanCmd) FullName

func (cmd *ScanCmd) FullName() string

func (*ScanCmd) Iterator

func (cmd *ScanCmd) Iterator() *ScanIterator

Iterator creates a new ScanIterator.

Example
iter := rdb.Scan(ctx, 0, "", 0).Iterator()
for iter.Next(ctx) {
	fmt.Println(iter.Val())
}
if err := iter.Err(); err != nil {
	panic(err)
}
Output:

func (*ScanCmd) Name

func (cmd *ScanCmd) Name() string

func (*ScanCmd) Result

func (cmd *ScanCmd) Result() (keys []string, cursor uint64, err error)

func (*ScanCmd) SetErr

func (cmd *ScanCmd) SetErr(e error)

func (*ScanCmd) String

func (cmd *ScanCmd) String() string

func (*ScanCmd) Val

func (cmd *ScanCmd) Val() (keys []string, cursor uint64)

type ScanIterator

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

ScanIterator is used to incrementally iterate over a collection of elements. It's safe for concurrent use by multiple goroutines.

Example
iter := rdb.Scan(ctx, 0, "", 0).Iterator()
for iter.Next(ctx) {
	fmt.Println(iter.Val())
}
if err := iter.Err(); err != nil {
	panic(err)
}
Output:

func (*ScanIterator) Err

func (it *ScanIterator) Err() error

Err returns the last iterator error, if any.

func (*ScanIterator) Next

func (it *ScanIterator) Next(ctx context.Context) bool

Next advances the cursor and returns true if more values can be read.

func (*ScanIterator) Val

func (it *ScanIterator) Val() string

Val returns the key/field at the current cursor position.

type Script

type Script struct {
	// contains filtered or unexported fields
}
Example
IncrByXX := redis.NewScript(`
		if redis.call("GET", KEYS[1]) ~= false then
			return redis.call("INCRBY", KEYS[1], ARGV[1])
		end
		return false
	`)

n, err := IncrByXX.Run(ctx, rdb, []string{"xx_counter"}, 2).Result()
fmt.Println(n, err)

err = rdb.Set(ctx, "xx_counter", "40", 0).Err()
if err != nil {
	panic(err)
}

n, err = IncrByXX.Run(ctx, rdb, []string{"xx_counter"}, 2).Result()
fmt.Println(n, err)
Output:

<nil> redis: nil
42 <nil>

func NewScript

func NewScript(src string) *Script

func (*Script) Eval

func (s *Script) Eval(ctx context.Context, c scripter, keys []string, args ...interface{}) *Cmd

func (*Script) EvalSha

func (s *Script) EvalSha(ctx context.Context, c scripter, keys []string, args ...interface{}) *Cmd

func (*Script) Exists

func (s *Script) Exists(ctx context.Context, c scripter) *BoolSliceCmd

func (*Script) Hash

func (s *Script) Hash() string

func (*Script) Load

func (s *Script) Load(ctx context.Context, c scripter) *StringCmd

func (*Script) Run

func (s *Script) Run(ctx context.Context, c scripter, keys []string, args ...interface{}) *Cmd

Run optimistically uses EVALSHA to run the script. If script does not exist it is retried using EVAL.

type SentinelClient

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

SentinelClient is a client for a Redis Sentinel.

func NewSentinelClient

func NewSentinelClient(opt *Options) *SentinelClient

func (*SentinelClient) AddHook

func (hs *SentinelClient) AddHook(hook Hook)

func (*SentinelClient) CkQuorum

func (c *SentinelClient) CkQuorum(ctx context.Context, name string) *StringCmd

CkQuorum checks if the current Sentinel configuration is able to reach the quorum needed to failover a master, and the majority needed to authorize the failover. This command should be used in monitoring systems to check if a Sentinel deployment is ok.

func (SentinelClient) Close

func (c SentinelClient) 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 (*SentinelClient) Context

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

func (*SentinelClient) Failover

func (c *SentinelClient) Failover(ctx context.Context, name string) *StatusCmd

Failover forces a failover as if the master was not reachable, and without asking for agreement to other Sentinels.

func (*SentinelClient) FlushConfig

func (c *SentinelClient) FlushConfig(ctx context.Context) *StatusCmd

FlushConfig forces Sentinel to rewrite its configuration on disk, including the current Sentinel state.

func (*SentinelClient) GetMasterAddrByName

func (c *SentinelClient) GetMasterAddrByName(ctx context.Context, name string) *StringSliceCmd

func (*SentinelClient) Master

func (c *SentinelClient) Master(ctx context.Context, name string) *StringStringMapCmd

Master shows the state and info of the specified master.

func (*SentinelClient) Masters

func (c *SentinelClient) Masters(ctx context.Context) *SliceCmd

Masters shows a list of monitored masters and their state.

func (*SentinelClient) Monitor

func (c *SentinelClient) Monitor(ctx context.Context, name, ip, port, quorum string) *StringCmd

Monitor tells the Sentinel to start monitoring a new master with the specified name, ip, port, and quorum.

func (*SentinelClient) PSubscribe

func (c *SentinelClient) PSubscribe(ctx context.Context, channels ...string) *PubSub

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

func (*SentinelClient) Ping

func (c *SentinelClient) Ping(ctx context.Context) *StringCmd

Ping is used to test if a connection is still alive, or to measure latency.

func (*SentinelClient) Process

func (c *SentinelClient) Process(ctx context.Context, cmd Cmder) error

func (*SentinelClient) Remove

func (c *SentinelClient) Remove(ctx context.Context, name string) *StringCmd

Remove is used in order to remove the specified master: the master will no longer be monitored, and will totally be removed from the internal state of the Sentinel.

func (*SentinelClient) Reset

func (c *SentinelClient) Reset(ctx context.Context, pattern string) *IntCmd

Reset resets all the masters with matching name. The pattern argument is a glob-style pattern. The reset process clears any previous state in a master (including a failover in progress), and removes every slave and sentinel already discovered and associated with the master.

func (*SentinelClient) Sentinels

func (c *SentinelClient) Sentinels(ctx context.Context, name string) *SliceCmd

func (*SentinelClient) Set

func (c *SentinelClient) Set(ctx context.Context, name, option, value string) *StringCmd

Set is used in order to change configuration parameters of a specific master.

func (*SentinelClient) Slaves

func (c *SentinelClient) Slaves(ctx context.Context, name string) *SliceCmd

Slaves shows a list of slaves for the specified master and their state.

func (SentinelClient) String

func (c SentinelClient) String() string

func (*SentinelClient) Subscribe

func (c *SentinelClient) Subscribe(ctx context.Context, channels ...string) *PubSub

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

func (*SentinelClient) WithContext

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

type SliceCmd

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

func NewSliceCmd

func NewSliceCmd(ctx context.Context, args ...interface{}) *SliceCmd

func NewSliceResult

func NewSliceResult(val []interface{}, err error) *SliceCmd

NewSliceResult returns a SliceCmd initialised with val and err for testing.

func (*SliceCmd) Args

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

func (*SliceCmd) Err

func (cmd *SliceCmd) Err() error

func (*SliceCmd) FullName

func (cmd *SliceCmd) FullName() string

func (*SliceCmd) Name

func (cmd *SliceCmd) Name() string

func (*SliceCmd) Result

func (cmd *SliceCmd) Result() ([]interface{}, error)

func (*SliceCmd) SetErr

func (cmd *SliceCmd) SetErr(e error)

func (*SliceCmd) String

func (cmd *SliceCmd) String() string

func (*SliceCmd) Val

func (cmd *SliceCmd) Val() []interface{}

type SlowLog

type SlowLog struct {
	ID       int64
	Time     time.Time
	Duration time.Duration
	Args     []string
	// These are also optional fields emitted only by Redis 4.0 or greater:
	// https://redis.io/commands/slowlog#output-format
	ClientAddr string
	ClientName string
}

type SlowLogCmd

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

func NewSlowLogCmd

func NewSlowLogCmd(ctx context.Context, args ...interface{}) *SlowLogCmd

func (*SlowLogCmd) Args

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

func (*SlowLogCmd) Err

func (cmd *SlowLogCmd) Err() error

func (*SlowLogCmd) FullName

func (cmd *SlowLogCmd) FullName() string

func (*SlowLogCmd) Name

func (cmd *SlowLogCmd) Name() string

func (*SlowLogCmd) Result

func (cmd *SlowLogCmd) Result() ([]SlowLog, error)

func (*SlowLogCmd) SetErr

func (cmd *SlowLogCmd) SetErr(e error)

func (*SlowLogCmd) String

func (cmd *SlowLogCmd) String() string

func (*SlowLogCmd) Val

func (cmd *SlowLogCmd) Val() []SlowLog

type Sort

type Sort struct {
	By            string
	Offset, Count int64
	Get           []string
	Order         string
	Alpha         bool
}

type StatefulCmdable

type StatefulCmdable interface {
	Cmdable
	Auth(ctx context.Context, password string) *StatusCmd
	AuthACL(ctx context.Context, username, password string) *StatusCmd
	Select(ctx context.Context, index int) *StatusCmd
	SwapDB(ctx context.Context, index1, index2 int) *StatusCmd
	ClientSetName(ctx context.Context, name string) *BoolCmd
}

type StatusCmd

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

func NewStatusCmd

func NewStatusCmd(ctx context.Context, args ...interface{}) *StatusCmd

func NewStatusResult

func NewStatusResult(val string, err error) *StatusCmd

NewStatusResult returns a StatusCmd initialised with val and err for testing.

func (*StatusCmd) Args

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

func (*StatusCmd) Err

func (cmd *StatusCmd) Err() error

func (*StatusCmd) FullName

func (cmd *StatusCmd) FullName() string

func (*StatusCmd) Name

func (cmd *StatusCmd) Name() string

func (*StatusCmd) Result

func (cmd *StatusCmd) Result() (string, error)

func (*StatusCmd) SetErr

func (cmd *StatusCmd) SetErr(e error)

func (*StatusCmd) String

func (cmd *StatusCmd) String() string

func (*StatusCmd) Val

func (cmd *StatusCmd) Val() string

type StringCmd

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

func NewStringCmd

func NewStringCmd(ctx context.Context, args ...interface{}) *StringCmd

func NewStringResult

func NewStringResult(val string, err error) *StringCmd

NewStringResult returns a StringCmd initialised with val and err for testing.

func (*StringCmd) Args

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

func (*StringCmd) Bytes

func (cmd *StringCmd) Bytes() ([]byte, error)

func (*StringCmd) Err

func (cmd *StringCmd) Err() error

func (*StringCmd) Float32

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

func (*StringCmd) Float64

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

func (*StringCmd) FullName

func (cmd *StringCmd) FullName() string

func (*StringCmd) Int

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

func (*StringCmd) Int64

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

func (*StringCmd) Name

func (cmd *StringCmd) Name() string

func (*StringCmd) Result

func (cmd *StringCmd) Result() (string, error)

func (*StringCmd) Scan

func (cmd *StringCmd) Scan(val interface{}) error

func (*StringCmd) SetErr

func (cmd *StringCmd) SetErr(e error)

func (*StringCmd) String

func (cmd *StringCmd) String() string

func (*StringCmd) Time

func (cmd *StringCmd) Time() (time.Time, error)

func (*StringCmd) Uint64

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

func (*StringCmd) Val

func (cmd *StringCmd) Val() string

type StringIntMapCmd

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

func NewStringIntMapCmd

func NewStringIntMapCmd(ctx context.Context, args ...interface{}) *StringIntMapCmd

func NewStringIntMapCmdResult

func NewStringIntMapCmdResult(val map[string]int64, err error) *StringIntMapCmd

NewStringIntMapCmdResult returns a StringIntMapCmd initialised with val and err for testing.

func (*StringIntMapCmd) Args

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

func (*StringIntMapCmd) Err

func (cmd *StringIntMapCmd) Err() error

func (*StringIntMapCmd) FullName

func (cmd *StringIntMapCmd) FullName() string

func (*StringIntMapCmd) Name

func (cmd *StringIntMapCmd) Name() string

func (*StringIntMapCmd) Result

func (cmd *StringIntMapCmd) Result() (map[string]int64, error)

func (*StringIntMapCmd) SetErr

func (cmd *StringIntMapCmd) SetErr(e error)

func (*StringIntMapCmd) String

func (cmd *StringIntMapCmd) String() string

func (*StringIntMapCmd) Val

func (cmd *StringIntMapCmd) Val() map[string]int64

type StringSliceCmd

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

func NewStringSliceCmd

func NewStringSliceCmd(ctx context.Context, args ...interface{}) *StringSliceCmd

func NewStringSliceResult

func NewStringSliceResult(val []string, err error) *StringSliceCmd

NewStringSliceResult returns a StringSliceCmd initialised with val and err for testing.

func (*StringSliceCmd) Args

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

func (*StringSliceCmd) Err

func (cmd *StringSliceCmd) Err() error

func (*StringSliceCmd) FullName

func (cmd *StringSliceCmd) FullName() string

func (*StringSliceCmd) Name

func (cmd *StringSliceCmd) Name() string

func (*StringSliceCmd) Result

func (cmd *StringSliceCmd) Result() ([]string, error)

func (*StringSliceCmd) ScanSlice

func (cmd *StringSliceCmd) ScanSlice(container interface{}) error

func (*StringSliceCmd) SetErr

func (cmd *StringSliceCmd) SetErr(e error)

func (*StringSliceCmd) String

func (cmd *StringSliceCmd) String() string

func (*StringSliceCmd) Val

func (cmd *StringSliceCmd) Val() []string

type StringStringMapCmd

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

func NewStringStringMapCmd

func NewStringStringMapCmd(ctx context.Context, args ...interface{}) *StringStringMapCmd

func NewStringStringMapResult

func NewStringStringMapResult(val map[string]string, err error) *StringStringMapCmd

NewStringStringMapResult returns a StringStringMapCmd initialised with val and err for testing.

func (*StringStringMapCmd) Args

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

func (*StringStringMapCmd) Err

func (cmd *StringStringMapCmd) Err() error

func (*StringStringMapCmd) FullName

func (cmd *StringStringMapCmd) FullName() string

func (*StringStringMapCmd) Name

func (cmd *StringStringMapCmd) Name() string

func (*StringStringMapCmd) Result

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

func (*StringStringMapCmd) SetErr

func (cmd *StringStringMapCmd) SetErr(e error)

func (*StringStringMapCmd) String

func (cmd *StringStringMapCmd) String() string

func (*StringStringMapCmd) Val

func (cmd *StringStringMapCmd) Val() map[string]string

type StringStructMapCmd

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

func NewStringStructMapCmd

func NewStringStructMapCmd(ctx context.Context, args ...interface{}) *StringStructMapCmd

func (*StringStructMapCmd) Args

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

func (*StringStructMapCmd) Err

func (cmd *StringStructMapCmd) Err() error

func (*StringStructMapCmd) FullName

func (cmd *StringStructMapCmd) FullName() string

func (*StringStructMapCmd) Name

func (cmd *StringStructMapCmd) Name() string

func (*StringStructMapCmd) Result

func (cmd *StringStructMapCmd) Result() (map[string]struct{}, error)

func (*StringStructMapCmd) SetErr

func (cmd *StringStructMapCmd) SetErr(e error)

func (*StringStructMapCmd) String

func (cmd *StringStructMapCmd) String() string

func (*StringStructMapCmd) Val

func (cmd *StringStructMapCmd) Val() map[string]struct{}

type Subscription

type Subscription struct {
	// Can be "subscribe", "unsubscribe", "psubscribe" or "punsubscribe".
	Kind string
	// Channel name we have subscribed to.
	Channel string
	// Number of channels we are currently subscribed to.
	Count int
}

Subscription received after a successful subscription to channel.

func (*Subscription) String

func (m *Subscription) String() string

type TimeCmd

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

func NewTimeCmd

func NewTimeCmd(ctx context.Context, args ...interface{}) *TimeCmd

func NewTimeCmdResult

func NewTimeCmdResult(val time.Time, err error) *TimeCmd

NewTimeCmdResult returns a TimeCmd initialised with val and err for testing.

func (*TimeCmd) Args

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

func (*TimeCmd) Err

func (cmd *TimeCmd) Err() error

func (*TimeCmd) FullName

func (cmd *TimeCmd) FullName() string

func (*TimeCmd) Name

func (cmd *TimeCmd) Name() string

func (*TimeCmd) Result

func (cmd *TimeCmd) Result() (time.Time, error)

func (*TimeCmd) SetErr

func (cmd *TimeCmd) SetErr(e error)

func (*TimeCmd) String

func (cmd *TimeCmd) String() string

func (*TimeCmd) Val

func (cmd *TimeCmd) Val() time.Time

type Tx

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

Tx implements Redis transactions as described in http://redis.io/topics/transactions. It's NOT safe for concurrent use by multiple goroutines, because Exec resets list of watched keys. If you don't need WATCH it is better to use Pipeline.

func (*Tx) AddHook

func (hs *Tx) AddHook(hook Hook)

func (Tx) Append

func (c Tx) Append(ctx context.Context, key, value string) *IntCmd

func (Tx) Auth

func (c Tx) Auth(ctx context.Context, password string) *StatusCmd

func (Tx) AuthACL

func (c Tx) AuthACL(ctx context.Context, username, password string) *StatusCmd

Perform an AUTH command, using the given user and pass. Should be used to authenticate the current connection with one of the connections defined in the ACL list when connecting to a Redis 6.0 instance, or greater, that is using the Redis ACL system.

func (Tx) BLPop

func (c Tx) BLPop(ctx context.Context, timeout time.Duration, keys ...string) *StringSliceCmd

func (Tx) BRPop

func (c Tx) BRPop(ctx context.Context, timeout time.Duration, keys ...string) *StringSliceCmd

func (Tx) BRPopLPush

func (c Tx) BRPopLPush(ctx context.Context, source, destination string, timeout time.Duration) *StringCmd

func (Tx) BZPopMax

func (c Tx) BZPopMax(ctx context.Context, timeout time.Duration, keys ...string) *ZWithKeyCmd

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

func (Tx) BZPopMin

func (c Tx) BZPopMin(ctx context.Context, timeout time.Duration, keys ...string) *ZWithKeyCmd

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

func (Tx) BgRewriteAOF

func (c Tx) BgRewriteAOF(ctx context.Context) *StatusCmd

func (Tx) BgSave

func (c Tx) BgSave(ctx context.Context) *StatusCmd

func (Tx) BitCount

func (c Tx) BitCount(ctx context.Context, key string, bitCount *BitCount) *IntCmd

func (Tx) BitField

func (c Tx) BitField(ctx context.Context, key string, args ...interface{}) *IntSliceCmd

func (Tx) BitOpAnd

func (c Tx) BitOpAnd(ctx context.Context, destKey string, keys ...string) *IntCmd

func (Tx) BitOpNot

func (c Tx) BitOpNot(ctx context.Context, destKey string, key string) *IntCmd

func (Tx) BitOpOr

func (c Tx) BitOpOr(ctx context.Context, destKey string, keys ...string) *IntCmd

func (Tx) BitOpXor

func (c Tx) BitOpXor(ctx context.Context, destKey string, keys ...string) *IntCmd

func (Tx) BitPos

func (c Tx) BitPos(ctx context.Context, key string, bit int64, pos ...int64) *IntCmd

func (Tx) ClientGetName

func (c Tx) ClientGetName(ctx context.Context) *StringCmd

ClientGetName returns the name of the connection.

func (Tx) ClientID

func (c Tx) ClientID(ctx context.Context) *IntCmd

func (Tx) ClientKill

func (c Tx) ClientKill(ctx context.Context, ipPort string) *StatusCmd

func (Tx) ClientKillByFilter

func (c Tx) ClientKillByFilter(ctx context.Context, keys ...string) *IntCmd

ClientKillByFilter is new style syntax, while the ClientKill is old

CLIENT KILL <option> [value] ... <option> [value]

func (Tx) ClientList

func (c Tx) ClientList(ctx context.Context) *StringCmd

func (Tx) ClientPause

func (c Tx) ClientPause(ctx context.Context, dur time.Duration) *BoolCmd

func (Tx) ClientSetName

func (c Tx) ClientSetName(ctx context.Context, name string) *BoolCmd

ClientSetName assigns a name to the connection.

func (Tx) ClientUnblock

func (c Tx) ClientUnblock(ctx context.Context, id int64) *IntCmd

func (Tx) ClientUnblockWithError

func (c Tx) ClientUnblockWithError(ctx context.Context, id int64) *IntCmd

func (*Tx) Close

func (c *Tx) Close(ctx context.Context) error

Close closes the transaction, releasing any open resources.

func (Tx) ClusterAddSlots

func (c Tx) ClusterAddSlots(ctx context.Context, slots ...int) *StatusCmd

func (Tx) ClusterAddSlotsRange

func (c Tx) ClusterAddSlotsRange(ctx context.Context, min, max int) *StatusCmd

func (Tx) ClusterCountFailureReports

func (c Tx) ClusterCountFailureReports(ctx context.Context, nodeID string) *IntCmd

func (Tx) ClusterCountKeysInSlot

func (c Tx) ClusterCountKeysInSlot(ctx context.Context, slot int) *IntCmd

func (Tx) ClusterDelSlots

func (c Tx) ClusterDelSlots(ctx context.Context, slots ...int) *StatusCmd

func (Tx) ClusterDelSlotsRange

func (c Tx) ClusterDelSlotsRange(ctx context.Context, min, max int) *StatusCmd

func (Tx) ClusterFailover

func (c Tx) ClusterFailover(ctx context.Context) *StatusCmd

func (Tx) ClusterForget

func (c Tx) ClusterForget(ctx context.Context, nodeID string) *StatusCmd

func (Tx) ClusterGetKeysInSlot

func (c Tx) ClusterGetKeysInSlot(ctx context.Context, slot int, count int) *StringSliceCmd

func (Tx) ClusterInfo

func (c Tx) ClusterInfo(ctx context.Context) *StringCmd

func (Tx) ClusterKeySlot

func (c Tx) ClusterKeySlot(ctx context.Context, key string) *IntCmd

func (Tx) ClusterMeet

func (c Tx) ClusterMeet(ctx context.Context, host, port string) *StatusCmd

func (Tx) ClusterNodes

func (c Tx) ClusterNodes(ctx context.Context) *StringCmd

func (Tx) ClusterReplicate

func (c Tx) ClusterReplicate(ctx context.Context, nodeID string) *StatusCmd

func (Tx) ClusterResetHard

func (c Tx) ClusterResetHard(ctx context.Context) *StatusCmd

func (Tx) ClusterResetSoft

func (c Tx) ClusterResetSoft(ctx context.Context) *StatusCmd

func (Tx) ClusterSaveConfig

func (c Tx) ClusterSaveConfig(ctx context.Context) *StatusCmd

func (Tx) ClusterSlaves

func (c Tx) ClusterSlaves(ctx context.Context, nodeID string) *StringSliceCmd

func (Tx) ClusterSlots

func (c Tx) ClusterSlots(ctx context.Context) *ClusterSlotsCmd

func (Tx) Command

func (c Tx) Command(ctx context.Context) *CommandsInfoCmd

func (Tx) ConfigGet

func (c Tx) ConfigGet(ctx context.Context, parameter string) *SliceCmd

func (Tx) ConfigResetStat

func (c Tx) ConfigResetStat(ctx context.Context) *StatusCmd

func (Tx) ConfigRewrite

func (c Tx) ConfigRewrite(ctx context.Context) *StatusCmd

func (Tx) ConfigSet

func (c Tx) ConfigSet(ctx context.Context, parameter, value string) *StatusCmd

func (*Tx) Context

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

func (Tx) DBSize

func (c Tx) DBSize(ctx context.Context) *IntCmd

func (Tx) DebugObject

func (c Tx) DebugObject(ctx context.Context, key string) *StringCmd

func (Tx) Decr

func (c Tx) Decr(ctx context.Context, key string) *IntCmd

func (Tx) DecrBy

func (c Tx) DecrBy(ctx context.Context, key string, decrement int64) *IntCmd

func (Tx) Del

func (c Tx) Del(ctx context.Context, keys ...string) *IntCmd

func (Tx) Dump

func (c Tx) Dump(ctx context.Context, key string) *StringCmd

func (Tx) Echo

func (c Tx) Echo(ctx context.Context, message interface{}) *StringCmd

func (Tx) Eval

func (c Tx) Eval(ctx context.Context, script string, keys []string, args ...interface{}) *Cmd

func (Tx) EvalSha

func (c Tx) EvalSha(ctx context.Context, sha1 string, keys []string, args ...interface{}) *Cmd

func (Tx) Exists

func (c Tx) Exists(ctx context.Context, keys ...string) *IntCmd

func (Tx) Expire

func (c Tx) Expire(ctx context.Context, key string, expiration time.Duration) *BoolCmd

func (Tx) ExpireAt

func (c Tx) ExpireAt(ctx context.Context, key string, tm time.Time) *BoolCmd

func (Tx) FlushAll

func (c Tx) FlushAll(ctx context.Context) *StatusCmd

func (Tx) FlushAllAsync

func (c Tx) FlushAllAsync(ctx context.Context) *StatusCmd

func (Tx) FlushDB

func (c Tx) FlushDB(ctx context.Context) *StatusCmd

func (Tx) FlushDBAsync

func (c Tx) FlushDBAsync(ctx context.Context) *StatusCmd

func (Tx) GeoAdd

func (c Tx) GeoAdd(ctx context.Context, key string, geoLocation ...*GeoLocation) *IntCmd

func (Tx) GeoDist

func (c Tx) GeoDist(
	ctx context.Context, key string, member1, member2, unit string,
) *FloatCmd

func (Tx) GeoHash

func (c Tx) GeoHash(ctx context.Context, key string, members ...string) *StringSliceCmd

func (Tx) GeoPos

func (c Tx) GeoPos(ctx context.Context, key string, members ...string) *GeoPosCmd

func (Tx) GeoRadius

func (c Tx) GeoRadius(
	ctx context.Context, key string, longitude, latitude float64, query *GeoRadiusQuery,
) *GeoLocationCmd

GeoRadius is a read-only GEORADIUS_RO command.

func (Tx) GeoRadiusByMember

func (c Tx) GeoRadiusByMember(
	ctx context.Context, key, member string, query *GeoRadiusQuery,
) *GeoLocationCmd

GeoRadius is a read-only GEORADIUSBYMEMBER_RO command.

func (Tx) GeoRadiusByMemberStore

func (c Tx) GeoRadiusByMemberStore(
	ctx context.Context, key, member string, query *GeoRadiusQuery,
) *IntCmd

GeoRadiusByMemberStore is a writing GEORADIUSBYMEMBER command.

func (Tx) GeoRadiusStore

func (c Tx) GeoRadiusStore(
	ctx context.Context, key string, longitude, latitude float64, query *GeoRadiusQuery,
) *IntCmd

GeoRadiusStore is a writing GEORADIUS command.

func (Tx) Get

func (c Tx) Get(ctx context.Context, key string) *StringCmd

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

func (Tx) GetBit

func (c Tx) GetBit(ctx context.Context, key string, offset int64) *IntCmd

func (Tx) GetRange

func (c Tx) GetRange(ctx context.Context, key string, start, end int64) *StringCmd

func (Tx) GetSet

func (c Tx) GetSet(ctx context.Context, key string, value interface{}) *StringCmd

func (Tx) HDel

func (c Tx) HDel(ctx context.Context, key string, fields ...string) *IntCmd

func (Tx) HExists

func (c Tx) HExists(ctx context.Context, key, field string) *BoolCmd

func (Tx) HGet

func (c Tx) HGet(ctx context.Context, key, field string) *StringCmd

func (Tx) HGetAll

func (c Tx) HGetAll(ctx context.Context, key string) *StringStringMapCmd

func (Tx) HIncrBy

func (c Tx) HIncrBy(ctx context.Context, key, field string, incr int64) *IntCmd

func (Tx) HIncrByFloat

func (c Tx) HIncrByFloat(ctx context.Context, key, field string, incr float64) *FloatCmd

func (Tx) HKeys

func (c Tx) HKeys(ctx context.Context, key string) *StringSliceCmd

func (Tx) HLen

func (c Tx) HLen(ctx context.Context, key string) *IntCmd

func (Tx) HMGet

func (c Tx) HMGet(ctx context.Context, key string, fields ...string) *SliceCmd

HMGet returns the values for the specified fields in the hash stored at key. It returns an interface{} to distinguish between empty string and nil value.

func (Tx) HMSet

func (c Tx) HMSet(ctx context.Context, key string, values ...interface{}) *BoolCmd

HMSet is a deprecated version of HSet left for compatibility with Redis 3.

func (Tx) HScan

func (c Tx) HScan(ctx context.Context, key string, cursor uint64, match string, count int64) *ScanCmd

func (Tx) HSet

func (c Tx) HSet(ctx context.Context, key string, values ...interface{}) *IntCmd

HSet accepts values in following formats:

  • HSet("myhash", "key1", "value1", "key2", "value2")
  • HSet("myhash", []string{"key1", "value1", "key2", "value2"})
  • HSet("myhash", map[string]interface{}{"key1": "value1", "key2": "value2"})

Note that it requires Redis v4 for multiple field/value pairs support.

func (Tx) HSetNX

func (c Tx) HSetNX(ctx context.Context, key, field string, value interface{}) *BoolCmd

func (Tx) HVals

func (c Tx) HVals(ctx context.Context, key string) *StringSliceCmd

func (Tx) Incr

func (c Tx) Incr(ctx context.Context, key string) *IntCmd

func (Tx) IncrBy

func (c Tx) IncrBy(ctx context.Context, key string, value int64) *IntCmd

func (Tx) IncrByFloat

func (c Tx) IncrByFloat(ctx context.Context, key string, value float64) *FloatCmd

func (Tx) Info

func (c Tx) Info(ctx context.Context, section ...string) *StringCmd

func (Tx) Keys

func (c Tx) Keys(ctx context.Context, pattern string) *StringSliceCmd

func (Tx) LIndex

func (c Tx) LIndex(ctx context.Context, key string, index int64) *StringCmd

func (Tx) LInsert

func (c Tx) LInsert(ctx context.Context, key, op string, pivot, value interface{}) *IntCmd

func (Tx) LInsertAfter

func (c Tx) LInsertAfter(ctx context.Context, key string, pivot, value interface{}) *IntCmd

func (Tx) LInsertBefore

func (c Tx) LInsertBefore(ctx context.Context, key string, pivot, value interface{}) *IntCmd

func (Tx) LLen

func (c Tx) LLen(ctx context.Context, key string) *IntCmd

func (Tx) LPop

func (c Tx) LPop(ctx context.Context, key string) *StringCmd

func (Tx) LPos

func (c Tx) LPos(ctx context.Context, key string, value string, a LPosArgs) *IntCmd

func (Tx) LPosCount

func (c Tx) LPosCount(ctx context.Context, key string, value string, count int64, a LPosArgs) *IntSliceCmd

func (Tx) LPush

func (c Tx) LPush(ctx context.Context, key string, values ...interface{}) *IntCmd

func (Tx) LPushX

func (c Tx) LPushX(ctx context.Context, key string, values ...interface{}) *IntCmd

func (Tx) LRange

func (c Tx) LRange(ctx context.Context, key string, start, stop int64) *StringSliceCmd

func (Tx) LRem

func (c Tx) LRem(ctx context.Context, key string, count int64, value interface{}) *IntCmd

func (Tx) LSet

func (c Tx) LSet(ctx context.Context, key string, index int64, value interface{}) *StatusCmd

func (Tx) LTrim

func (c Tx) LTrim(ctx context.Context, key string, start, stop int64) *StatusCmd

func (Tx) LastSave

func (c Tx) LastSave(ctx context.Context) *IntCmd

func (Tx) MGet

func (c Tx) MGet(ctx context.Context, keys ...string) *SliceCmd

func (Tx) MSet

func (c Tx) MSet(ctx context.Context, values ...interface{}) *StatusCmd

MSet is like Set but accepts multiple values:

  • MSet("key1", "value1", "key2", "value2")
  • MSet([]string{"key1", "value1", "key2", "value2"})
  • MSet(map[string]interface{}{"key1": "value1", "key2": "value2"})

func (Tx) MSetNX

func (c Tx) MSetNX(ctx context.Context, values ...interface{}) *BoolCmd

MSetNX is like SetNX but accepts multiple values:

  • MSetNX("key1", "value1", "key2", "value2")
  • MSetNX([]string{"key1", "value1", "key2", "value2"})
  • MSetNX(map[string]interface{}{"key1": "value1", "key2": "value2"})

func (Tx) MemoryUsage

func (c Tx) MemoryUsage(ctx context.Context, key string, samples ...int) *IntCmd

func (Tx) Migrate

func (c Tx) Migrate(ctx context.Context, host, port, key string, db int, timeout time.Duration) *StatusCmd

func (Tx) Move

func (c Tx) Move(ctx context.Context, key string, db int) *BoolCmd

func (Tx) ObjectEncoding

func (c Tx) ObjectEncoding(ctx context.Context, key string) *StringCmd

func (Tx) ObjectIdleTime

func (c Tx) ObjectIdleTime(ctx context.Context, key string) *DurationCmd

func (Tx) ObjectRefCount

func (c Tx) ObjectRefCount(ctx context.Context, key string) *IntCmd

func (Tx) PExpire

func (c Tx) PExpire(ctx context.Context, key string, expiration time.Duration) *BoolCmd

func (Tx) PExpireAt

func (c Tx) PExpireAt(ctx context.Context, key string, tm time.Time) *BoolCmd

func (Tx) PFAdd

func (c Tx) PFAdd(ctx context.Context, key string, els ...interface{}) *IntCmd

func (Tx) PFCount

func (c Tx) PFCount(ctx context.Context, keys ...string) *IntCmd

func (Tx) PFMerge

func (c Tx) PFMerge(ctx context.Context, dest string, keys ...string) *StatusCmd

func (Tx) PTTL

func (c Tx) PTTL(ctx context.Context, key string) *DurationCmd

func (Tx) Persist

func (c Tx) Persist(ctx context.Context, key string) *BoolCmd

func (Tx) Ping

func (c Tx) Ping(ctx context.Context) *StatusCmd

func (*Tx) Pipeline

func (c *Tx) Pipeline() Pipeliner

Pipeline creates a pipeline. Usually it is more convenient to use Pipelined.

func (*Tx) Pipelined

func (c *Tx) Pipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmder, error)

Pipelined executes commands queued in the fn outside of the transaction. Use TxPipelined if you need transactional behavior.

func (*Tx) Process

func (c *Tx) Process(ctx context.Context, cmd Cmder) error

func (Tx) PubSubChannels

func (c Tx) PubSubChannels(ctx context.Context, pattern string) *StringSliceCmd

func (Tx) PubSubNumPat

func (c Tx) PubSubNumPat(ctx context.Context) *IntCmd

func (Tx) PubSubNumSub

func (c Tx) PubSubNumSub(ctx context.Context, channels ...string) *StringIntMapCmd

func (Tx) Publish

func (c Tx) Publish(ctx context.Context, channel string, message interface{}) *IntCmd

Publish posts the message to the channel.

func (Tx) Quit

func (c Tx) Quit(ctx context.Context) *StatusCmd

func (Tx) RPop

func (c Tx) RPop(ctx context.Context, key string) *StringCmd

func (Tx) RPopLPush

func (c Tx) RPopLPush(ctx context.Context, source, destination string) *StringCmd

func (Tx) RPush

func (c Tx) RPush(ctx context.Context, key string, values ...interface{}) *IntCmd

func (Tx) RPushX

func (c Tx) RPushX(ctx context.Context, key string, values ...interface{}) *IntCmd

func (Tx) RandomKey

func (c Tx) RandomKey(ctx context.Context) *StringCmd

func (Tx) ReadOnly

func (c Tx) ReadOnly(ctx context.Context) *StatusCmd

func (Tx) ReadWrite

func (c Tx) ReadWrite(ctx context.Context) *StatusCmd

func (Tx) Rename

func (c Tx) Rename(ctx context.Context, key, newkey string) *StatusCmd

func (Tx) RenameNX

func (c Tx) RenameNX(ctx context.Context, key, newkey string) *BoolCmd

func (Tx) Restore

func (c Tx) Restore(ctx context.Context, key string, ttl time.Duration, value string) *StatusCmd

func (Tx) RestoreReplace

func (c Tx) RestoreReplace(ctx context.Context, key string, ttl time.Duration, value string) *StatusCmd

func (Tx) SAdd

func (c Tx) SAdd(ctx context.Context, key string, members ...interface{}) *IntCmd

func (Tx) SCard

func (c Tx) SCard(ctx context.Context, key string) *IntCmd

func (Tx) SDiff

func (c Tx) SDiff(ctx context.Context, keys ...string) *StringSliceCmd

func (Tx) SDiffStore

func (c Tx) SDiffStore(ctx context.Context, destination string, keys ...string) *IntCmd

func (Tx) SInter

func (c Tx) SInter(ctx context.Context, keys ...string) *StringSliceCmd

func (Tx) SInterStore

func (c Tx) SInterStore(ctx context.Context, destination string, keys ...string) *IntCmd

func (Tx) SIsMember

func (c Tx) SIsMember(ctx context.Context, key string, member interface{}) *BoolCmd

func (Tx) SMembers

func (c Tx) SMembers(ctx context.Context, key string) *StringSliceCmd

Redis `SMEMBERS key` command output as a slice.

func (Tx) SMembersMap

func (c Tx) SMembersMap(ctx context.Context, key string) *StringStructMapCmd

Redis `SMEMBERS key` command output as a map.

func (Tx) SMove

func (c Tx) SMove(ctx context.Context, source, destination string, member interface{}) *BoolCmd

func (Tx) SPop

func (c Tx) SPop(ctx context.Context, key string) *StringCmd

Redis `SPOP key` command.

func (Tx) SPopN

func (c Tx) SPopN(ctx context.Context, key string, count int64) *StringSliceCmd

Redis `SPOP key count` command.

func (Tx) SRandMember

func (c Tx) SRandMember(ctx context.Context, key string) *StringCmd

Redis `SRANDMEMBER key` command.

func (Tx) SRandMemberN

func (c Tx) SRandMemberN(ctx context.Context, key string, count int64) *StringSliceCmd

Redis `SRANDMEMBER key count` command.

func (Tx) SRem

func (c Tx) SRem(ctx context.Context, key string, members ...interface{}) *IntCmd

func (Tx) SScan

func (c Tx) SScan(ctx context.Context, key string, cursor uint64, match string, count int64) *ScanCmd

func (Tx) SUnion

func (c Tx) SUnion(ctx context.Context, keys ...string) *StringSliceCmd

func (Tx) SUnionStore

func (c Tx) SUnionStore(ctx context.Context, destination string, keys ...string) *IntCmd

func (Tx) Save

func (c Tx) Save(ctx context.Context) *StatusCmd

func (Tx) Scan

func (c Tx) Scan(ctx context.Context, cursor uint64, match string, keyType string, count int64) *ScanCmd

func (Tx) ScriptExists

func (c Tx) ScriptExists(ctx context.Context, hashes ...string) *BoolSliceCmd

func (Tx) ScriptFlush

func (c Tx) ScriptFlush(ctx context.Context) *StatusCmd

func (Tx) ScriptKill

func (c Tx) ScriptKill(ctx context.Context) *StatusCmd

func (Tx) ScriptLoad

func (c Tx) ScriptLoad(ctx context.Context, script string) *StringCmd

func (Tx) Select

func (c Tx) Select(ctx context.Context, index int) *StatusCmd

func (Tx) Set

func (c Tx) Set(ctx context.Context, 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. KeepTTL(-1) expiration is a Redis KEEPTTL option to keep existing TTL.

func (Tx) SetBit

func (c Tx) SetBit(ctx context.Context, key string, offset int64, value int) *IntCmd

func (Tx) SetEX

func (c Tx) SetEX(ctx context.Context, key string, value interface{}, expiration time.Duration) *StatusCmd

Redis `SETEX key expiration value` command.

func (Tx) SetNX

func (c Tx) SetNX(ctx context.Context, key string, value interface{}, expiration time.Duration) *BoolCmd

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

Zero expiration means the key has no expiration time. KeepTTL(-1) expiration is a Redis KEEPTTL option to keep existing TTL.

func (Tx) SetRange

func (c Tx) SetRange(ctx context.Context, key string, offset int64, value string) *IntCmd

func (Tx) SetXX

func (c Tx) SetXX(ctx context.Context, key string, value interface{}, expiration time.Duration) *BoolCmd

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

Zero expiration means the key has no expiration time. KeepTTL(-1) expiration is a Redis KEEPTTL option to keep existing TTL.

func (Tx) Shutdown

func (c Tx) Shutdown(ctx context.Context) *StatusCmd

func (Tx) ShutdownNoSave

func (c Tx) ShutdownNoSave(ctx context.Context) *StatusCmd

func (Tx) ShutdownSave

func (c Tx) ShutdownSave(ctx context.Context) *StatusCmd

func (Tx) SlaveOf

func (c Tx) SlaveOf(ctx context.Context, host, port string) *StatusCmd

func (Tx) SlowLogGet

func (c Tx) SlowLogGet(ctx context.Context, num int64) *SlowLogCmd

func (Tx) Sort

func (c Tx) Sort(ctx context.Context, key string, sort *Sort) *StringSliceCmd

func (Tx) SortInterfaces

func (c Tx) SortInterfaces(ctx context.Context, key string, sort *Sort) *SliceCmd

func (Tx) SortStore

func (c Tx) SortStore(ctx context.Context, key, store string, sort *Sort) *IntCmd

func (Tx) StrLen

func (c Tx) StrLen(ctx context.Context, key string) *IntCmd

func (*Tx) String

func (c *Tx) String() string

func (Tx) SwapDB

func (c Tx) SwapDB(ctx context.Context, index1, index2 int) *StatusCmd

func (Tx) Sync

func (c Tx) Sync(ctx context.Context)

func (Tx) TTL

func (c Tx) TTL(ctx context.Context, key string) *DurationCmd

func (Tx) Time

func (c Tx) Time(ctx context.Context) *TimeCmd

func (Tx) Touch

func (c Tx) Touch(ctx context.Context, keys ...string) *IntCmd

func (*Tx) TxPipeline

func (c *Tx) TxPipeline() Pipeliner

TxPipeline creates a pipeline. Usually it is more convenient to use TxPipelined.

func (*Tx) TxPipelined

func (c *Tx) TxPipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmder, error)

TxPipelined executes commands queued in the fn in the transaction.

When using WATCH, EXEC will execute commands only if the watched keys were not modified, allowing for a check-and-set mechanism.

Exec always returns list of commands. If transaction fails TxFailedErr is returned. Otherwise Exec returns an error of the first failed command or nil.

func (Tx) Type

func (c Tx) Type(ctx context.Context, key string) *StatusCmd
func (c Tx) Unlink(ctx context.Context, keys ...string) *IntCmd

func (*Tx) Unwatch

func (c *Tx) Unwatch(ctx context.Context, keys ...string) *StatusCmd

Unwatch flushes all the previously watched keys for a transaction.

func (Tx) Wait

func (c Tx) Wait(ctx context.Context, numSlaves int, timeout time.Duration) *IntCmd

func (*Tx) Watch

func (c *Tx) Watch(ctx context.Context, keys ...string) *StatusCmd

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

func (*Tx) WithContext

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

func (Tx) XAck

func (c Tx) XAck(ctx context.Context, stream, group string, ids ...string) *IntCmd

func (Tx) XAdd

func (c Tx) XAdd(ctx context.Context, a *XAddArgs) *StringCmd

func (Tx) XClaim

func (c Tx) XClaim(ctx context.Context, a *XClaimArgs) *XMessageSliceCmd

func (Tx) XClaimJustID

func (c Tx) XClaimJustID(ctx context.Context, a *XClaimArgs) *StringSliceCmd

func (Tx) XDel

func (c Tx) XDel(ctx context.Context, stream string, ids ...string) *IntCmd

func (Tx) XGroupCreate

func (c Tx) XGroupCreate(ctx context.Context, stream, group, start string) *StatusCmd

func (Tx) XGroupCreateMkStream

func (c Tx) XGroupCreateMkStream(ctx context.Context, stream, group, start string) *StatusCmd

func (Tx) XGroupDelConsumer

func (c Tx) XGroupDelConsumer(ctx context.Context, stream, group, consumer string) *IntCmd

func (Tx) XGroupDestroy

func (c Tx) XGroupDestroy(ctx context.Context, stream, group string) *IntCmd

func (Tx) XGroupSetID

func (c Tx) XGroupSetID(ctx context.Context, stream, group, start string) *StatusCmd

func (Tx) XInfoGroups

func (c Tx) XInfoGroups(ctx context.Context, key string) *XInfoGroupsCmd

func (Tx) XInfoStream

func (c Tx) XInfoStream(ctx context.Context, key string) *XInfoStreamCmd

func (Tx) XLen

func (c Tx) XLen(ctx context.Context, stream string) *IntCmd

func (Tx) XPending

func (c Tx) XPending(ctx context.Context, stream, group string) *XPendingCmd

func (Tx) XPendingExt

func (c Tx) XPendingExt(ctx context.Context, a *XPendingExtArgs) *XPendingExtCmd

func (Tx) XRange

func (c Tx) XRange(ctx context.Context, stream, start, stop string) *XMessageSliceCmd

func (Tx) XRangeN

func (c Tx) XRangeN(ctx context.Context, stream, start, stop string, count int64) *XMessageSliceCmd

func (Tx) XRead

func (c Tx) XRead(ctx context.Context, a *XReadArgs) *XStreamSliceCmd

func (Tx) XReadGroup

func (c Tx) XReadGroup(ctx context.Context, a *XReadGroupArgs) *XStreamSliceCmd

func (Tx) XReadStreams

func (c Tx) XReadStreams(ctx context.Context, streams ...string) *XStreamSliceCmd

func (Tx) XRevRange

func (c Tx) XRevRange(ctx context.Context, stream, start, stop string) *XMessageSliceCmd

func (Tx) XRevRangeN

func (c Tx) XRevRangeN(ctx context.Context, stream, start, stop string, count int64) *XMessageSliceCmd

func (Tx) XTrim

func (c Tx) XTrim(ctx context.Context, key string, maxLen int64) *IntCmd

func (Tx) XTrimApprox

func (c Tx) XTrimApprox(ctx context.Context, key string, maxLen int64) *IntCmd

func (Tx) ZAdd

func (c Tx) ZAdd(ctx context.Context, key string, members ...*Z) *IntCmd

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

func (Tx) ZAddCh

func (c Tx) ZAddCh(ctx context.Context, key string, members ...*Z) *IntCmd

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

func (Tx) ZAddNX

func (c Tx) ZAddNX(ctx context.Context, key string, members ...*Z) *IntCmd

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

func (Tx) ZAddNXCh

func (c Tx) ZAddNXCh(ctx context.Context, key string, members ...*Z) *IntCmd

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

func (Tx) ZAddXX

func (c Tx) ZAddXX(ctx context.Context, key string, members ...*Z) *IntCmd

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

func (Tx) ZAddXXCh

func (c Tx) ZAddXXCh(ctx context.Context, key string, members ...*Z) *IntCmd

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

func (Tx) ZCard

func (c Tx) ZCard(ctx context.Context, key string) *IntCmd

func (Tx) ZCount

func (c Tx) ZCount(ctx context.Context, key, min, max string) *IntCmd

func (Tx) ZIncr

func (c Tx) ZIncr(ctx context.Context, key string, member *Z) *FloatCmd

Redis `ZADD key INCR score member` command.

func (Tx) ZIncrBy

func (c Tx) ZIncrBy(ctx context.Context, key string, increment float64, member string) *FloatCmd

func (Tx) ZIncrNX

func (c Tx) ZIncrNX(ctx context.Context, key string, member *Z) *FloatCmd

Redis `ZADD key NX INCR score member` command.

func (Tx) ZIncrXX

func (c Tx) ZIncrXX(ctx context.Context, key string, member *Z) *FloatCmd

Redis `ZADD key XX INCR score member` command.

func (Tx) ZInterStore

func (c Tx) ZInterStore(ctx context.Context, destination string, store *ZStore) *IntCmd

func (Tx) ZLexCount

func (c Tx) ZLexCount(ctx context.Context, key, min, max string) *IntCmd

func (Tx) ZPopMax

func (c Tx) ZPopMax(ctx context.Context, key string, count ...int64) *ZSliceCmd

func (Tx) ZPopMin

func (c Tx) ZPopMin(ctx context.Context, key string, count ...int64) *ZSliceCmd

func (Tx) ZRange

func (c Tx) ZRange(ctx context.Context, key string, start, stop int64) *StringSliceCmd

func (Tx) ZRangeByLex

func (c Tx) ZRangeByLex(ctx context.Context, key string, opt *ZRangeBy) *StringSliceCmd

func (Tx) ZRangeByScore

func (c Tx) ZRangeByScore(ctx context.Context, key string, opt *ZRangeBy) *StringSliceCmd

func (Tx) ZRangeByScoreWithScores

func (c Tx) ZRangeByScoreWithScores(ctx context.Context, key string, opt *ZRangeBy) *ZSliceCmd

func (Tx) ZRangeWithScores

func (c Tx) ZRangeWithScores(ctx context.Context, key string, start, stop int64) *ZSliceCmd

func (Tx) ZRank

func (c Tx) ZRank(ctx context.Context, key, member string) *IntCmd

func (Tx) ZRem

func (c Tx) ZRem(ctx context.Context, key string, members ...interface{}) *IntCmd

func (Tx) ZRemRangeByLex

func (c Tx) ZRemRangeByLex(ctx context.Context, key, min, max string) *IntCmd

func (Tx) ZRemRangeByRank

func (c Tx) ZRemRangeByRank(ctx context.Context, key string, start, stop int64) *IntCmd

func (Tx) ZRemRangeByScore

func (c Tx) ZRemRangeByScore(ctx context.Context, key, min, max string) *IntCmd

func (Tx) ZRevRange

func (c Tx) ZRevRange(ctx context.Context, key string, start, stop int64) *StringSliceCmd

func (Tx) ZRevRangeByLex

func (c Tx) ZRevRangeByLex(ctx context.Context, key string, opt *ZRangeBy) *StringSliceCmd

func (Tx) ZRevRangeByScore

func (c Tx) ZRevRangeByScore(ctx context.Context, key string, opt *ZRangeBy) *StringSliceCmd

func (Tx) ZRevRangeByScoreWithScores

func (c Tx) ZRevRangeByScoreWithScores(ctx context.Context, key string, opt *ZRangeBy) *ZSliceCmd

func (Tx) ZRevRangeWithScores

func (c Tx) ZRevRangeWithScores(ctx context.Context, key string, start, stop int64) *ZSliceCmd

func (Tx) ZRevRank

func (c Tx) ZRevRank(ctx context.Context, key, member string) *IntCmd

func (Tx) ZScan

func (c Tx) ZScan(ctx context.Context, key string, cursor uint64, match string, count int64) *ScanCmd

func (Tx) ZScore

func (c Tx) ZScore(ctx context.Context, key, member string) *FloatCmd

func (Tx) ZUnionStore

func (c Tx) ZUnionStore(ctx context.Context, dest string, store *ZStore) *IntCmd

type UniversalClient

type UniversalClient interface {
	Cmdable
	Context() context.Context
	AddHook(Hook)
	Watch(ctx context.Context, fn func(*Tx) error, keys ...string) error
	Do(ctx context.Context, args ...interface{}) *Cmd
	Process(ctx context.Context, cmd Cmder) error
	Subscribe(ctx context.Context, channels ...string) *PubSub
	PSubscribe(ctx context.Context, channels ...string) *PubSub
	Close() error
	PoolStats() *PoolStats
}

UniversalClient is an abstract client which - based on the provided options - can connect to either clusters, or sentinel-backed failover instances or simple single-instance servers. This can be useful for testing cluster-specific applications locally.

func NewUniversalClient

func NewUniversalClient(opts *UniversalOptions) UniversalClient

NewUniversalClient returns a new multi client. The type of client returned depends on the following three conditions:

1. if a MasterName is passed a sentinel-backed FailoverClient will be returned 2. if the number of Addrs is two or more, a ClusterClient will be returned 3. otherwise, a single-node redis Client will be returned.

Example (Cluster)
rdb := redis.NewUniversalClient(&redis.UniversalOptions{
	Addrs: []string{":7000", ":7001", ":7002", ":7003", ":7004", ":7005"},
})
defer rdb.Close()

rdb.Ping(ctx)
Output:

Example (Failover)
rdb := redis.NewUniversalClient(&redis.UniversalOptions{
	MasterName: "master",
	Addrs:      []string{":26379"},
})
defer rdb.Close()

rdb.Ping(ctx)
Output:

Example (Simple)
rdb := redis.NewUniversalClient(&redis.UniversalOptions{
	Addrs: []string{":6379"},
})
defer rdb.Close()

rdb.Ping(ctx)
Output:

type UniversalOptions

type UniversalOptions struct {
	// Either a single address or a seed list of host:port addresses
	// of cluster/sentinel nodes.
	Addrs []string

	// Database to be selected after connecting to the server.
	// Only single-node and failover clients.
	DB int

	Dialer    func(ctx context.Context, network, addr string) (net.Conn, error)
	OnConnect func(ctx context.Context, cn *Conn) error

	Username         string
	Password         string
	SentinelPassword string

	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

	MaxRedirects   int
	ReadOnly       bool
	RouteByLatency bool
	RouteRandomly  bool

	// The sentinel master name.
	// Only failover clients.
	MasterName string
}

UniversalOptions information is required by UniversalClient to establish connections.

func (*UniversalOptions) Cluster

func (o *UniversalOptions) Cluster() *ClusterOptions

Cluster returns cluster options created from the universal options.

func (*UniversalOptions) Failover

func (o *UniversalOptions) Failover() *FailoverOptions

Failover returns failover options created from the universal options.

func (*UniversalOptions) Simple

func (o *UniversalOptions) Simple() *Options

Simple returns basic options created from the universal options.

type XAddArgs

type XAddArgs struct {
	Stream       string
	MaxLen       int64 // MAXLEN N
	MaxLenApprox int64 // MAXLEN ~ N
	ID           string
	Values       interface{}
}

XAddArgs accepts values in the following formats:

  • XAddArgs.Values = []interface{}{"key1", "value1", "key2", "value2"}
  • XAddArgs.Values = []string("key1", "value1", "key2", "value2")
  • XAddArgs.Values = map[string]interface{}{"key1": "value1", "key2": "value2"}

Note that map will not preserve the order of key-value pairs.

type XClaimArgs

type XClaimArgs struct {
	Stream   string
	Group    string
	Consumer string
	MinIdle  time.Duration
	Messages []string
}

type XInfoGroup

type XInfoGroup struct {
	Name            string
	Consumers       int64
	Pending         int64
	LastDeliveredID string
}

type XInfoGroupsCmd

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

func NewXInfoGroupsCmd

func NewXInfoGroupsCmd(ctx context.Context, stream string) *XInfoGroupsCmd

func (*XInfoGroupsCmd) Args

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

func (*XInfoGroupsCmd) Err

func (cmd *XInfoGroupsCmd) Err() error

func (*XInfoGroupsCmd) FullName

func (cmd *XInfoGroupsCmd) FullName() string

func (*XInfoGroupsCmd) Name

func (cmd *XInfoGroupsCmd) Name() string

func (*XInfoGroupsCmd) Result

func (cmd *XInfoGroupsCmd) Result() ([]XInfoGroup, error)

func (*XInfoGroupsCmd) SetErr

func (cmd *XInfoGroupsCmd) SetErr(e error)

func (*XInfoGroupsCmd) String

func (cmd *XInfoGroupsCmd) String() string

func (*XInfoGroupsCmd) Val

func (cmd *XInfoGroupsCmd) Val() []XInfoGroup

type XInfoStream

type XInfoStream struct {
	Length          int64
	RadixTreeKeys   int64
	RadixTreeNodes  int64
	Groups          int64
	LastGeneratedID string
	FirstEntry      XMessage
	LastEntry       XMessage
}

type XInfoStreamCmd

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

func NewXInfoStreamCmd

func NewXInfoStreamCmd(ctx context.Context, stream string) *XInfoStreamCmd

func (*XInfoStreamCmd) Args

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

func (*XInfoStreamCmd) Err

func (cmd *XInfoStreamCmd) Err() error

func (*XInfoStreamCmd) FullName

func (cmd *XInfoStreamCmd) FullName() string

func (*XInfoStreamCmd) Name

func (cmd *XInfoStreamCmd) Name() string

func (*XInfoStreamCmd) Result

func (cmd *XInfoStreamCmd) Result() (*XInfoStream, error)

func (*XInfoStreamCmd) SetErr

func (cmd *XInfoStreamCmd) SetErr(e error)

func (*XInfoStreamCmd) String

func (cmd *XInfoStreamCmd) String() string

func (*XInfoStreamCmd) Val

func (cmd *XInfoStreamCmd) Val() *XInfoStream

type XMessage

type XMessage struct {
	ID     string
	Values map[string]interface{}
}

type XMessageSliceCmd

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

func NewXMessageSliceCmd

func NewXMessageSliceCmd(ctx context.Context, args ...interface{}) *XMessageSliceCmd

func NewXMessageSliceCmdResult

func NewXMessageSliceCmdResult(val []XMessage, err error) *XMessageSliceCmd

NewXMessageSliceCmdResult returns a XMessageSliceCmd initialised with val and err for testing.

func (*XMessageSliceCmd) Args

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

func (*XMessageSliceCmd) Err

func (cmd *XMessageSliceCmd) Err() error

func (*XMessageSliceCmd) FullName

func (cmd *XMessageSliceCmd) FullName() string

func (*XMessageSliceCmd) Name

func (cmd *XMessageSliceCmd) Name() string

func (*XMessageSliceCmd) Result

func (cmd *XMessageSliceCmd) Result() ([]XMessage, error)

func (*XMessageSliceCmd) SetErr

func (cmd *XMessageSliceCmd) SetErr(e error)

func (*XMessageSliceCmd) String

func (cmd *XMessageSliceCmd) String() string

func (*XMessageSliceCmd) Val

func (cmd *XMessageSliceCmd) Val() []XMessage

type XPending

type XPending struct {
	Count     int64
	Lower     string
	Higher    string
	Consumers map[string]int64
}

type XPendingCmd

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

func NewXPendingCmd

func NewXPendingCmd(ctx context.Context, args ...interface{}) *XPendingCmd

func (*XPendingCmd) Args

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

func (*XPendingCmd) Err

func (cmd *XPendingCmd) Err() error

func (*XPendingCmd) FullName

func (cmd *XPendingCmd) FullName() string

func (*XPendingCmd) Name

func (cmd *XPendingCmd) Name() string

func (*XPendingCmd) Result

func (cmd *XPendingCmd) Result() (*XPending, error)

func (*XPendingCmd) SetErr

func (cmd *XPendingCmd) SetErr(e error)

func (*XPendingCmd) String

func (cmd *XPendingCmd) String() string

func (*XPendingCmd) Val

func (cmd *XPendingCmd) Val() *XPending

type XPendingExt

type XPendingExt struct {
	ID         string
	Consumer   string
	Idle       time.Duration
	RetryCount int64
}

type XPendingExtArgs

type XPendingExtArgs struct {
	Stream   string
	Group    string
	Start    string
	End      string
	Count    int64
	Consumer string
}

type XPendingExtCmd

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

func NewXPendingExtCmd

func NewXPendingExtCmd(ctx context.Context, args ...interface{}) *XPendingExtCmd

func (*XPendingExtCmd) Args

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

func (*XPendingExtCmd) Err

func (cmd *XPendingExtCmd) Err() error

func (*XPendingExtCmd) FullName

func (cmd *XPendingExtCmd) FullName() string

func (*XPendingExtCmd) Name

func (cmd *XPendingExtCmd) Name() string

func (*XPendingExtCmd) Result

func (cmd *XPendingExtCmd) Result() ([]XPendingExt, error)

func (*XPendingExtCmd) SetErr

func (cmd *XPendingExtCmd) SetErr(e error)

func (*XPendingExtCmd) String

func (cmd *XPendingExtCmd) String() string

func (*XPendingExtCmd) Val

func (cmd *XPendingExtCmd) Val() []XPendingExt

type XReadArgs

type XReadArgs struct {
	Streams []string // list of streams and ids, e.g. stream1 stream2 id1 id2
	Count   int64
	Block   time.Duration
}

type XReadGroupArgs

type XReadGroupArgs struct {
	Group    string
	Consumer string
	Streams  []string // list of streams and ids, e.g. stream1 stream2 id1 id2
	Count    int64
	Block    time.Duration
	NoAck    bool
}

type XStream

type XStream struct {
	Stream   string
	Messages []XMessage
}

type XStreamSliceCmd

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

func NewXStreamSliceCmd

func NewXStreamSliceCmd(ctx context.Context, args ...interface{}) *XStreamSliceCmd

func NewXStreamSliceCmdResult

func NewXStreamSliceCmdResult(val []XStream, err error) *XStreamSliceCmd

NewXStreamSliceCmdResult returns a XStreamSliceCmd initialised with val and err for testing.

func (*XStreamSliceCmd) Args

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

func (*XStreamSliceCmd) Err

func (cmd *XStreamSliceCmd) Err() error

func (*XStreamSliceCmd) FullName

func (cmd *XStreamSliceCmd) FullName() string

func (*XStreamSliceCmd) Name

func (cmd *XStreamSliceCmd) Name() string

func (*XStreamSliceCmd) Result

func (cmd *XStreamSliceCmd) Result() ([]XStream, error)

func (*XStreamSliceCmd) SetErr

func (cmd *XStreamSliceCmd) SetErr(e error)

func (*XStreamSliceCmd) String

func (cmd *XStreamSliceCmd) String() string

func (*XStreamSliceCmd) Val

func (cmd *XStreamSliceCmd) Val() []XStream

type Z

type Z struct {
	Score  float64
	Member interface{}
}

Z represents sorted set member.

type ZRangeBy

type ZRangeBy struct {
	Min, Max      string
	Offset, Count int64
}

type ZSliceCmd

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

func NewZSliceCmd

func NewZSliceCmd(ctx context.Context, args ...interface{}) *ZSliceCmd

func NewZSliceCmdResult

func NewZSliceCmdResult(val []Z, err error) *ZSliceCmd

NewZSliceCmdResult returns a ZSliceCmd initialised with val and err for testing.

func (*ZSliceCmd) Args

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

func (*ZSliceCmd) Err

func (cmd *ZSliceCmd) Err() error

func (*ZSliceCmd) FullName

func (cmd *ZSliceCmd) FullName() string

func (*ZSliceCmd) Name

func (cmd *ZSliceCmd) Name() string

func (*ZSliceCmd) Result

func (cmd *ZSliceCmd) Result() ([]Z, error)

func (*ZSliceCmd) SetErr

func (cmd *ZSliceCmd) SetErr(e error)

func (*ZSliceCmd) String

func (cmd *ZSliceCmd) String() string

func (*ZSliceCmd) Val

func (cmd *ZSliceCmd) Val() []Z

type ZStore

type ZStore struct {
	Keys    []string
	Weights []float64
	// Can be SUM, MIN or MAX.
	Aggregate string
}

ZStore is used as an arg to ZInterStore and ZUnionStore.

type ZWithKey

type ZWithKey struct {
	Z
	Key string
}

ZWithKey represents sorted set member including the name of the key where it was popped.

type ZWithKeyCmd

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

func NewZWithKeyCmd

func NewZWithKeyCmd(ctx context.Context, args ...interface{}) *ZWithKeyCmd

func NewZWithKeyCmdResult

func NewZWithKeyCmdResult(val *ZWithKey, err error) *ZWithKeyCmd

NewZWithKeyCmdResult returns a NewZWithKeyCmd initialised with val and err for testing.

func (*ZWithKeyCmd) Args

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

func (*ZWithKeyCmd) Err

func (cmd *ZWithKeyCmd) Err() error

func (*ZWithKeyCmd) FullName

func (cmd *ZWithKeyCmd) FullName() string

func (*ZWithKeyCmd) Name

func (cmd *ZWithKeyCmd) Name() string

func (*ZWithKeyCmd) Result

func (cmd *ZWithKeyCmd) Result() (*ZWithKey, error)

func (*ZWithKeyCmd) SetErr

func (cmd *ZWithKeyCmd) SetErr(e error)

func (*ZWithKeyCmd) String

func (cmd *ZWithKeyCmd) String() string

func (*ZWithKeyCmd) Val

func (cmd *ZWithKeyCmd) Val() *ZWithKey

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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