redis

package
v3.0.2+incompatible Latest Latest
Warning

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

Go to latest
Published: May 16, 2016 License: BSD-3-Clause, Apache-2.0 Imports: 14 Imported by: 0

README

Redis client for Golang Build Status

Supports:

  • Redis 2.8 commands except QUIT, MONITOR, SLOWLOG and SYNC.
  • Pub/sub.
  • Transactions.
  • Pipelining.
  • Connection pool.
  • TLS connections.
  • Thread safety.
  • Timeouts.
  • Redis Sentinel.

API docs: http://godoc.org/gopkg.in/redis.v2. Examples: http://godoc.org/gopkg.in/redis.v2#pkg-examples.

Installation

Install:

go get gopkg.in/redis.v2

Look and feel

Some corner cases:

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

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

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

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

Documentation

Overview

Package redis implements a Redis client.

Example (CustomCommand)
Get := func(client *redis.Client, key string) *redis.StringCmd {
	cmd := redis.NewStringCmd("GET", key)
	client.Process(cmd)
	return cmd
}

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

"" redis: nil

Index

Examples

Constants

This section is empty.

Variables

View Source
var Nil = errorf("redis: nil")

Redis nil reply.

View Source
var TxFailedErr = errorf("redis: transaction failed")

Redis transaction failed.

Functions

This section is empty.

Types

type BitCount

type BitCount struct {
	Start, End int64
}

type BoolCmd

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

func NewBoolCmd

func NewBoolCmd(args ...string) *BoolCmd

func (BoolCmd) Err

func (cmd BoolCmd) Err() error

func (*BoolCmd) Result

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

func (*BoolCmd) String

func (cmd *BoolCmd) String() string

func (*BoolCmd) Val

func (cmd *BoolCmd) Val() bool

type BoolSliceCmd

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

func NewBoolSliceCmd

func NewBoolSliceCmd(args ...string) *BoolSliceCmd

func (BoolSliceCmd) Err

func (cmd BoolSliceCmd) Err() error

func (*BoolSliceCmd) Result

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

func (*BoolSliceCmd) String

func (cmd *BoolSliceCmd) String() string

func (*BoolSliceCmd) Val

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

type Client

type Client struct {
	// contains filtered or unexported fields
}
Example
if err := client.Set("foo", "bar").Err(); err != nil {
	panic(err)
}

v, err := client.Get("hello").Result()
fmt.Printf("%q %q %v", v, err, err == redis.Nil)
Output:

"" "redis: nil" true

func NewClient

func NewClient(clOpt *Options) *Client

func NewFailoverClient

func NewFailoverClient(failoverOpt *FailoverOptions) *Client
Example
client := redis.NewFailoverClient(&redis.FailoverOptions{
	MasterName:    "master",
	SentinelAddrs: []string{":26379"},
})

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

PONG <nil>

func NewTCPClient

func NewTCPClient(opt *Options) *Client

Deprecated. Use NewClient instead.

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

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

PONG <nil>

func NewUnixClient

func NewUnixClient(opt *Options) *Client

Deprecated. Use NewClient instead.

func (*Client) Append

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

func (*Client) Auth

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

func (*Client) BLPop

func (c *Client) BLPop(timeout int64, keys ...string) *StringSliceCmd

func (*Client) BRPop

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

func (*Client) BRPopLPush

func (c *Client) BRPopLPush(source, destination string, timeout int64) *StringCmd

func (*Client) BgRewriteAOF

func (c *Client) BgRewriteAOF() *StatusCmd

func (*Client) BgSave

func (c *Client) BgSave() *StatusCmd

func (*Client) BitCount

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

func (*Client) BitOpAnd

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

func (*Client) BitOpNot

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

func (*Client) BitOpOr

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

func (*Client) BitOpXor

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

func (*Client) ClientKill

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

func (*Client) ClientList

func (c *Client) ClientList() *StringCmd

func (Client) Close

func (c Client) Close() error

Close closes the client, releasing any open resources.

func (*Client) ConfigGet

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

func (*Client) ConfigResetStat

func (c *Client) ConfigResetStat() *StatusCmd

func (*Client) ConfigSet

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

func (*Client) DbSize

func (c *Client) DbSize() *IntCmd

func (*Client) DebugObject

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

func (*Client) Decr

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

func (*Client) DecrBy

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

func (*Client) Del

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

func (*Client) Dump

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

func (*Client) Echo

func (c *Client) Echo(message string) *StringCmd

func (*Client) Eval

func (c *Client) Eval(script string, keys []string, args []string) *Cmd

func (*Client) EvalSha

func (c *Client) EvalSha(sha1 string, keys []string, args []string) *Cmd

func (*Client) Exists

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

func (*Client) Expire

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

func (*Client) ExpireAt

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

func (*Client) FlushAll

func (c *Client) FlushAll() *StatusCmd

func (*Client) FlushDb

func (c *Client) FlushDb() *StatusCmd

func (*Client) Get

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

func (*Client) GetBit

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

func (*Client) GetRange

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

func (*Client) GetSet

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

func (*Client) HDel

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

func (*Client) HExists

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

func (*Client) HGet

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

func (*Client) HGetAll

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

func (*Client) HGetAllMap

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

func (*Client) HIncrBy

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

func (*Client) HIncrByFloat

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

func (*Client) HKeys

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

func (*Client) HLen

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

func (*Client) HMGet

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

func (*Client) HMSet

func (c *Client) HMSet(key, field, value string, pairs ...string) *StatusCmd

func (*Client) HScan

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

func (*Client) HSet

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

func (*Client) HSetNX

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

func (*Client) HVals

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

func (*Client) Incr

func (c *Client) Incr(key string) *IntCmd
Example
if err := client.Incr("counter").Err(); err != nil {
	panic(err)
}

n, err := client.Get("counter").Int64()
fmt.Println(n, err)
Output:

1 <nil>

func (*Client) IncrBy

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

func (*Client) IncrByFloat

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

func (*Client) Info

func (c *Client) Info() *StringCmd

func (*Client) Keys

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

func (*Client) LIndex

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

func (*Client) LInsert

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

func (*Client) LLen

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

func (*Client) LPop

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

func (*Client) LPush

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

func (*Client) LPushX

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

func (*Client) LRange

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

func (*Client) LRem

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

func (*Client) LSet

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

func (*Client) LTrim

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

func (*Client) LastSave

func (c *Client) LastSave() *IntCmd

func (*Client) MGet

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

func (*Client) MSet

func (c *Client) MSet(pairs ...string) *StatusCmd

func (*Client) MSetNX

func (c *Client) MSetNX(pairs ...string) *BoolCmd

func (*Client) Migrate

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

func (*Client) Move

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

func (*Client) Multi

func (c *Client) Multi() *Multi

func (*Client) ObjectEncoding

func (c *Client) ObjectEncoding(keys ...string) *StringCmd

func (*Client) ObjectIdleTime

func (c *Client) ObjectIdleTime(keys ...string) *DurationCmd

func (*Client) ObjectRefCount

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

func (*Client) PExpire

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

func (*Client) PExpireAt

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

func (*Client) PSetEx

func (c *Client) PSetEx(key string, dur time.Duration, value string) *StatusCmd

func (*Client) PTTL

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

func (*Client) Persist

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

func (*Client) Ping

func (c *Client) Ping() *StatusCmd

func (*Client) Pipeline

func (c *Client) Pipeline() *Pipeline

func (*Client) Pipelined

func (c *Client) Pipelined(f func(*Pipeline) error) ([]Cmder, error)
Example
cmds, err := client.Pipelined(func(c *redis.Pipeline) error {
	c.Set("key1", "hello1")
	c.Get("key1")
	return nil
})
fmt.Println(err)
set := cmds[0].(*redis.StatusCmd)
fmt.Println(set)
get := cmds[1].(*redis.StringCmd)
fmt.Println(get)
Output:

<nil>
SET key1 hello1: OK
GET key1: hello1

func (Client) Process

func (c Client) Process(cmd Cmder)

func (*Client) PubSub

func (c *Client) PubSub() *PubSub

func (*Client) PubSubChannels

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

func (*Client) PubSubNumPat

func (c *Client) PubSubNumPat() *IntCmd

func (*Client) PubSubNumSub

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

func (*Client) Publish

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

func (*Client) Quit

func (c *Client) Quit() *StatusCmd

func (*Client) RPop

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

func (*Client) RPopLPush

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

func (*Client) RPush

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

func (*Client) RPushX

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

func (*Client) RandomKey

func (c *Client) RandomKey() *StringCmd

func (*Client) Rename

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

func (*Client) RenameNX

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

func (*Client) Restore

func (c *Client) Restore(key string, ttl int64, value string) *StatusCmd

func (*Client) SAdd

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

func (*Client) SCard

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

func (*Client) SDiff

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

func (*Client) SDiffStore

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

func (*Client) SInter

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

func (*Client) SInterStore

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

func (*Client) SIsMember

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

func (*Client) SMembers

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

func (*Client) SMove

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

func (*Client) SPop

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

func (*Client) SRandMember

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

func (*Client) SRem

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

func (*Client) SScan

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

func (*Client) SUnion

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

func (*Client) SUnionStore

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

func (*Client) Save

func (c *Client) Save() *StatusCmd

func (*Client) Scan

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

func (*Client) ScriptExists

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

func (*Client) ScriptFlush

func (c *Client) ScriptFlush() *StatusCmd

func (*Client) ScriptKill

func (c *Client) ScriptKill() *StatusCmd

func (*Client) ScriptLoad

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

func (*Client) Select

func (c *Client) Select(index int64) *StatusCmd

func (*Client) Set

func (c *Client) Set(key, value string) *StatusCmd

func (*Client) SetBit

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

func (*Client) SetEx

func (c *Client) SetEx(key string, dur time.Duration, value string) *StatusCmd

func (*Client) SetNX

func (c *Client) SetNX(key, value string) *BoolCmd

func (*Client) SetRange

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

func (*Client) Shutdown

func (c *Client) Shutdown() *StatusCmd

func (*Client) ShutdownNoSave

func (c *Client) ShutdownNoSave() *StatusCmd

func (*Client) ShutdownSave

func (c *Client) ShutdownSave() *StatusCmd

func (*Client) SlaveOf

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

func (*Client) SlowLog

func (c *Client) SlowLog()

func (*Client) Sort

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

func (*Client) StrLen

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

func (*Client) Sync

func (c *Client) Sync()

func (*Client) TTL

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

func (*Client) Time

func (c *Client) Time() *StringSliceCmd

func (*Client) Type

func (c *Client) Type(key string) *StatusCmd

func (*Client) ZAdd

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

func (*Client) ZCard

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

func (*Client) ZCount

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

func (*Client) ZIncrBy

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

func (*Client) ZInterStore

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

func (*Client) ZRange

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

func (*Client) ZRangeByScore

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

func (*Client) ZRangeByScoreWithScores

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

func (*Client) ZRangeWithScores

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

func (*Client) ZRank

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

func (*Client) ZRem

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

func (*Client) ZRemRangeByRank

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

func (*Client) ZRemRangeByScore

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

func (*Client) ZRevRange

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

func (*Client) ZRevRangeByScore

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

func (*Client) ZRevRangeByScoreWithScores

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

func (*Client) ZRevRangeWithScores

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

func (*Client) ZRevRank

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

func (*Client) ZScan

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

func (*Client) ZScore

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

func (*Client) ZUnionStore

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

type Cmd

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

func NewCmd

func NewCmd(args ...string) *Cmd

func (Cmd) Err

func (cmd Cmd) Err() error

func (*Cmd) Result

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

func (*Cmd) String

func (cmd *Cmd) String() string

func (*Cmd) Val

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

type Cmder

type Cmder interface {
	Err() error
	String() string
	// contains filtered or unexported methods
}

type DurationCmd

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

func NewDurationCmd

func NewDurationCmd(precision time.Duration, args ...string) *DurationCmd

func (DurationCmd) Err

func (cmd DurationCmd) Err() error

func (*DurationCmd) Result

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

func (*DurationCmd) String

func (cmd *DurationCmd) String() string

func (*DurationCmd) Val

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

type FailoverOptions

type FailoverOptions struct {
	MasterName    string
	SentinelAddrs []string

	Password string
	DB       int64

	PoolSize int

	DialTimeout  time.Duration
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
	IdleTimeout  time.Duration
}

type FloatCmd

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

func NewFloatCmd

func NewFloatCmd(args ...string) *FloatCmd

func (FloatCmd) Err

func (cmd FloatCmd) Err() error

func (*FloatCmd) String

func (cmd *FloatCmd) String() string

func (*FloatCmd) Val

func (cmd *FloatCmd) Val() float64

type IntCmd

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

func NewIntCmd

func NewIntCmd(args ...string) *IntCmd

func (IntCmd) Err

func (cmd IntCmd) Err() error

func (*IntCmd) Result

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

func (*IntCmd) String

func (cmd *IntCmd) String() string

func (*IntCmd) Val

func (cmd *IntCmd) Val() int64

type Message

type Message struct {
	Channel string
	Payload string
}

func (*Message) String

func (m *Message) String() string

type Multi

type Multi struct {
	*Client
}

Not thread-safe.

Example
incr := func(tx *redis.Multi) ([]redis.Cmder, error) {
	s, err := tx.Get("key").Result()
	if err != nil && err != redis.Nil {
		return nil, err
	}
	n, _ := strconv.ParseInt(s, 10, 64)

	return tx.Exec(func() error {
		tx.Set("key", strconv.FormatInt(n+1, 10))
		return nil
	})
}

client.Del("key")

tx := client.Multi()
defer tx.Close()

watch := tx.Watch("key")
_ = watch.Err()

for {
	cmds, err := incr(tx)
	if err == redis.TxFailedErr {
		continue
	} else if err != nil {
		panic(err)
	}
	fmt.Println(cmds, err)
	break
}
Output:

[SET key 1: OK] <nil>

func (*Multi) Close

func (c *Multi) Close() error

func (*Multi) Discard

func (c *Multi) Discard() error

func (*Multi) Exec

func (c *Multi) Exec(f func() error) ([]Cmder, error)

Exec always returns list of commands. If transaction fails TxFailedErr is returned. Otherwise Exec returns error of the first failed command or nil.

func (Multi) Process

func (c Multi) Process(cmd Cmder)

func (*Multi) Unwatch

func (c *Multi) Unwatch(keys ...string) *StatusCmd

func (*Multi) Watch

func (c *Multi) Watch(keys ...string) *StatusCmd

type Options

type Options struct {
	Network string
	Addr    string

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

	Password string
	DB       int64

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

	PoolSize    int
	IdleTimeout time.Duration
}

type PMessage

type PMessage struct {
	Channel string
	Pattern string
	Payload string
}

func (*PMessage) String

func (m *PMessage) String() string

type Pipeline

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

Not thread-safe.

Example
pipeline := client.Pipeline()
set := pipeline.Set("key1", "hello1")
get := pipeline.Get("key1")
cmds, err := pipeline.Exec()
fmt.Println(cmds, err)
fmt.Println(set)
fmt.Println(get)
Output:

[SET key1 hello1: OK GET key1: hello1] <nil>
SET key1 hello1: OK
GET key1: hello1

func (*Pipeline) Close

func (c *Pipeline) Close() error

func (*Pipeline) Discard

func (c *Pipeline) Discard() error

func (*Pipeline) Exec

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

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

func (Pipeline) Process

func (c Pipeline) Process(cmd Cmder)

type PubSub

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

Not thread-safe.

Example
pubsub := client.PubSub()
defer pubsub.Close()

err := pubsub.Subscribe("mychannel")
_ = err

msg, err := pubsub.Receive()
fmt.Println(msg, err)

pub := client.Publish("mychannel", "hello")
_ = pub.Err()

msg, err = pubsub.Receive()
fmt.Println(msg, err)
Output:

subscribe: mychannel <nil>
Message<mychannel: hello> <nil>

func (PubSub) Close

func (c PubSub) Close() error

Close closes the client, releasing any open resources.

func (*PubSub) PSubscribe

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

func (*PubSub) PUnsubscribe

func (c *PubSub) PUnsubscribe(patterns ...string) error

func (PubSub) Process

func (c PubSub) Process(cmd Cmder)

func (*PubSub) Receive

func (c *PubSub) Receive() (interface{}, error)

func (*PubSub) ReceiveTimeout

func (c *PubSub) ReceiveTimeout(timeout time.Duration) (interface{}, error)

func (*PubSub) Subscribe

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

func (*PubSub) Unsubscribe

func (c *PubSub) Unsubscribe(channels ...string) error

type ScanCmd

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

func NewScanCmd

func NewScanCmd(args ...string) *ScanCmd

func (ScanCmd) Err

func (cmd ScanCmd) Err() error

func (*ScanCmd) Result

func (cmd *ScanCmd) Result() (int64, []string, error)

func (*ScanCmd) String

func (cmd *ScanCmd) String() string

func (*ScanCmd) Val

func (cmd *ScanCmd) Val() (int64, []string)

type Script

type Script struct {
	// contains filtered or unexported fields
}
Example
setnx := redis.NewScript(`
        if redis.call("get", KEYS[1]) == false then
            redis.call("set", KEYS[1], ARGV[1])
            return 1
        end
        return 0
    `)

v1, err := setnx.Run(client, []string{"keynx"}, []string{"foo"}).Result()
fmt.Println(v1.(int64), err)

v2, err := setnx.Run(client, []string{"keynx"}, []string{"bar"}).Result()
fmt.Println(v2.(int64), err)

get := client.Get("keynx")
fmt.Println(get)
Output:

1 <nil>
0 <nil>
GET keynx: foo

func NewScript

func NewScript(src string) *Script

func (*Script) Eval

func (s *Script) Eval(c scripter, keys []string, args []string) *Cmd

func (*Script) EvalSha

func (s *Script) EvalSha(c scripter, keys []string, args []string) *Cmd

func (*Script) Exists

func (s *Script) Exists(c scripter) *BoolSliceCmd

func (*Script) Load

func (s *Script) Load(c scripter) *StringCmd

func (*Script) Run

func (s *Script) Run(c *Client, keys []string, args []string) *Cmd

type SliceCmd

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

func NewSliceCmd

func NewSliceCmd(args ...string) *SliceCmd

func (SliceCmd) Err

func (cmd SliceCmd) Err() error

func (*SliceCmd) Result

func (cmd *SliceCmd) Result() ([]interface{}, error)

func (*SliceCmd) String

func (cmd *SliceCmd) String() string

func (*SliceCmd) Val

func (cmd *SliceCmd) Val() []interface{}

type Sort

type Sort struct {
	By            string
	Offset, Count float64
	Get           []string
	Order         string
	IsAlpha       bool
	Store         string
}

type StatusCmd

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

func NewStatusCmd

func NewStatusCmd(args ...string) *StatusCmd

func (StatusCmd) Err

func (cmd StatusCmd) Err() error

func (*StatusCmd) Result

func (cmd *StatusCmd) Result() (string, 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(args ...string) *StringCmd

func (StringCmd) Err

func (cmd StringCmd) Err() error

func (*StringCmd) Float64

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

func (*StringCmd) Int64

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

func (*StringCmd) Result

func (cmd *StringCmd) Result() (string, error)

func (*StringCmd) String

func (cmd *StringCmd) String() string

func (*StringCmd) Uint64

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

func (*StringCmd) Val

func (cmd *StringCmd) Val() string

type StringSliceCmd

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

func NewStringSliceCmd

func NewStringSliceCmd(args ...string) *StringSliceCmd

func (StringSliceCmd) Err

func (cmd StringSliceCmd) Err() error

func (*StringSliceCmd) Result

func (cmd *StringSliceCmd) Result() ([]string, 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(args ...string) *StringStringMapCmd

func (StringStringMapCmd) Err

func (cmd StringStringMapCmd) Err() error

func (*StringStringMapCmd) Result

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

func (*StringStringMapCmd) String

func (cmd *StringStringMapCmd) String() string

func (*StringStringMapCmd) Val

func (cmd *StringStringMapCmd) Val() map[string]string

type Subscription

type Subscription struct {
	Kind    string
	Channel string
	Count   int
}

func (*Subscription) String

func (m *Subscription) String() string

type Z

type Z struct {
	Score  float64
	Member string
}

type ZRangeByScore

type ZRangeByScore struct {
	Min, Max string

	Offset, Count int64
}

type ZSliceCmd

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

func NewZSliceCmd

func NewZSliceCmd(args ...string) *ZSliceCmd

func (ZSliceCmd) Err

func (cmd ZSliceCmd) Err() error

func (*ZSliceCmd) Result

func (cmd *ZSliceCmd) Result() ([]Z, error)

func (*ZSliceCmd) String

func (cmd *ZSliceCmd) String() string

func (*ZSliceCmd) Val

func (cmd *ZSliceCmd) Val() []Z

type ZStore

type ZStore struct {
	Weights   []int64
	Aggregate string
}

Jump to

Keyboard shortcuts

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