redis.v1: gopkg.in/redis.v1 Index | Examples | Files

package redis

import "gopkg.in/redis.v1"

Package gopkg.in/redis.v1 implements a Redis client.

Code:

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

Package Files

command.go commands.go doc.go error.go multi.go parser.go pipeline.go pool.go pubsub.go rate_limit.go redis.go script.go sentinel.go

Variables

var Nil = errorf("redis: nil")

Redis nil reply.

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

Redis transaction failed.

type BitCount Uses

type BitCount struct {
    Start, End int64
}

type BoolCmd Uses

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

func NewBoolCmd Uses

func NewBoolCmd(args ...string) *BoolCmd

func (BoolCmd) Err Uses

func (cmd BoolCmd) Err() error

func (*BoolCmd) Result Uses

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

func (*BoolCmd) String Uses

func (cmd *BoolCmd) String() string

func (*BoolCmd) Val Uses

func (cmd *BoolCmd) Val() bool

type BoolSliceCmd Uses

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

func NewBoolSliceCmd Uses

func NewBoolSliceCmd(args ...string) *BoolSliceCmd

func (BoolSliceCmd) Err Uses

func (cmd BoolSliceCmd) Err() error

func (*BoolSliceCmd) Result Uses

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

func (*BoolSliceCmd) String Uses

func (cmd *BoolSliceCmd) String() string

func (*BoolSliceCmd) Val Uses

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

type Client Uses

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

Code:

set := client.Set("foo", "bar")
fmt.Println(set.Err())

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

Output:

<nil>
"" redis: nil true

func NewFailoverClient Uses

func NewFailoverClient(failoverOpt *FailoverOptions) *Client

func NewTCPClient Uses

func NewTCPClient(opt *Options) *Client

Code:

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

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

Output:

PONG <nil>

func NewUnixClient Uses

func NewUnixClient(opt *Options) *Client

func (*Client) Append Uses

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

func (*Client) Auth Uses

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

func (*Client) BLPop Uses

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

func (*Client) BRPop Uses

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

func (*Client) BRPopLPush Uses

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

func (*Client) BgRewriteAOF Uses

func (c *Client) BgRewriteAOF() *StatusCmd

func (*Client) BgSave Uses

func (c *Client) BgSave() *StatusCmd

func (*Client) BitCount Uses

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

func (*Client) BitOpAnd Uses

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

func (*Client) BitOpNot Uses

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

func (*Client) BitOpOr Uses

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

func (*Client) BitOpXor Uses

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

func (*Client) ClientKill Uses

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

func (*Client) ClientList Uses

func (c *Client) ClientList() *StringCmd

func (Client) Close Uses

func (c Client) Close() error

Close closes the client, releasing any open resources.

func (*Client) ConfigGet Uses

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

func (*Client) ConfigResetStat Uses

func (c *Client) ConfigResetStat() *StatusCmd

func (*Client) ConfigSet Uses

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

func (*Client) DbSize Uses

func (c *Client) DbSize() *IntCmd

func (*Client) DebugObject Uses

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

func (*Client) Decr Uses

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

func (*Client) DecrBy Uses

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

func (*Client) Del Uses

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

func (*Client) Dump Uses

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

func (*Client) Echo Uses

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

func (*Client) Eval Uses

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

func (*Client) EvalSha Uses

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

func (*Client) Exists Uses

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

func (*Client) Expire Uses

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

func (*Client) ExpireAt Uses

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

func (*Client) FlushAll Uses

func (c *Client) FlushAll() *StatusCmd

func (*Client) FlushDb Uses

func (c *Client) FlushDb() *StatusCmd

func (*Client) Get Uses

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

func (*Client) GetBit Uses

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

func (*Client) GetRange Uses

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

func (*Client) GetSet Uses

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

func (*Client) HDel Uses

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

func (*Client) HExists Uses

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

func (*Client) HGet Uses

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

func (*Client) HGetAll Uses

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

func (*Client) HGetAllMap Uses

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

func (*Client) HIncrBy Uses

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

func (*Client) HIncrByFloat Uses

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

func (*Client) HKeys Uses

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

func (*Client) HLen Uses

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

func (*Client) HMGet Uses

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

func (*Client) HMSet Uses

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

func (*Client) HScan Uses

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

func (*Client) HSet Uses

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

func (*Client) HSetNX Uses

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

func (*Client) HVals Uses

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

func (*Client) Incr Uses

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

func (*Client) IncrBy Uses

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

func (*Client) IncrByFloat Uses

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

func (*Client) Info Uses

func (c *Client) Info() *StringCmd

func (*Client) Keys Uses

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

func (*Client) LIndex Uses

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

func (*Client) LInsert Uses

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

func (*Client) LLen Uses

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

func (*Client) LPop Uses

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

func (*Client) LPush Uses

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

func (*Client) LPushX Uses

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

func (*Client) LRange Uses

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

func (*Client) LRem Uses

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

func (*Client) LSet Uses

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

func (*Client) LTrim Uses

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

func (*Client) LastSave Uses

func (c *Client) LastSave() *IntCmd

func (*Client) MGet Uses

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

func (*Client) MSet Uses

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

func (*Client) MSetNX Uses

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

func (*Client) Migrate Uses

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

func (*Client) Move Uses

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

func (*Client) Multi Uses

func (c *Client) Multi() *Multi

func (*Client) ObjectEncoding Uses

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

func (*Client) ObjectIdleTime Uses

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

func (*Client) ObjectRefCount Uses

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

func (*Client) PExpire Uses

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

func (*Client) PExpireAt Uses

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

func (*Client) PSetEx Uses

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

func (*Client) PTTL Uses

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

func (*Client) Persist Uses

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

func (*Client) Ping Uses

func (c *Client) Ping() *StatusCmd

func (*Client) Pipeline Uses

func (c *Client) Pipeline() *Pipeline

func (*Client) Pipelined Uses

func (c *Client) Pipelined(f func(*Pipeline)) ([]Cmder, error)

Code:

cmds, err := client.Pipelined(func(c *redis.Pipeline) {
    c.Set("key1", "hello1")
    c.Get("key1")
})
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 Uses

func (c Client) Process(cmd Cmder)

func (*Client) PubSub Uses

func (c *Client) PubSub() *PubSub

func (*Client) Publish Uses

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

func (*Client) Quit Uses

func (c *Client) Quit() *StatusCmd

func (*Client) RPop Uses

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

func (*Client) RPopLPush Uses

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

func (*Client) RPush Uses

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

func (*Client) RPushX Uses

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

func (*Client) RandomKey Uses

func (c *Client) RandomKey() *StringCmd

func (*Client) Rename Uses

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

func (*Client) RenameNX Uses

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

func (*Client) Restore Uses

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

func (*Client) SAdd Uses

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

func (*Client) SCard Uses

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

func (*Client) SDiff Uses

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

func (*Client) SDiffStore Uses

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

func (*Client) SInter Uses

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

func (*Client) SInterStore Uses

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

func (*Client) SIsMember Uses

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

func (*Client) SMembers Uses

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

func (*Client) SMove Uses

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

func (*Client) SPop Uses

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

func (*Client) SRandMember Uses

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

func (*Client) SRem Uses

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

func (*Client) SScan Uses

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

func (*Client) SUnion Uses

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

func (*Client) SUnionStore Uses

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

func (*Client) Save Uses

func (c *Client) Save() *StatusCmd

func (*Client) Scan Uses

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

func (*Client) ScriptExists Uses

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

func (*Client) ScriptFlush Uses

func (c *Client) ScriptFlush() *StatusCmd

func (*Client) ScriptKill Uses

func (c *Client) ScriptKill() *StatusCmd

func (*Client) ScriptLoad Uses

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

func (*Client) Select Uses

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

func (*Client) Set Uses

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

func (*Client) SetBit Uses

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

func (*Client) SetEx Uses

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

func (*Client) SetNX Uses

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

func (*Client) SetRange Uses

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

func (*Client) Shutdown Uses

func (c *Client) Shutdown() *StatusCmd

func (*Client) ShutdownNoSave Uses

func (c *Client) ShutdownNoSave() *StatusCmd

func (*Client) ShutdownSave Uses

func (c *Client) ShutdownSave() *StatusCmd

func (*Client) SlaveOf Uses

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

func (*Client) SlowLog Uses

func (c *Client) SlowLog()

func (*Client) Sort Uses

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

func (*Client) StrLen Uses

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

func (*Client) Sync Uses

func (c *Client) Sync()

func (*Client) TTL Uses

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

func (*Client) Time Uses

func (c *Client) Time() *StringSliceCmd

func (*Client) Type Uses

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

func (*Client) ZAdd Uses

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

func (*Client) ZCard Uses

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

func (*Client) ZCount Uses

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

func (*Client) ZIncrBy Uses

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

func (*Client) ZInterStore Uses

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

func (*Client) ZRange Uses

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

func (*Client) ZRangeByScore Uses

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

func (*Client) ZRangeByScoreWithScores Uses

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

func (*Client) ZRangeByScoreWithScoresMap Uses

func (c *Client) ZRangeByScoreWithScoresMap(key string, opt ZRangeByScore) *StringFloatMapCmd

func (*Client) ZRangeWithScores Uses

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

func (*Client) ZRangeWithScoresMap Uses

func (c *Client) ZRangeWithScoresMap(key string, start, stop int64) *StringFloatMapCmd

func (*Client) ZRank Uses

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

func (*Client) ZRem Uses

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

func (*Client) ZRemRangeByRank Uses

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

func (*Client) ZRemRangeByScore Uses

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

func (*Client) ZRevRange Uses

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

func (*Client) ZRevRangeByScore Uses

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

func (*Client) ZRevRangeByScoreWithScores Uses

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

func (*Client) ZRevRangeByScoreWithScoresMap Uses

func (c *Client) ZRevRangeByScoreWithScoresMap(key string, opt ZRangeByScore) *StringFloatMapCmd

func (*Client) ZRevRangeWithScores Uses

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

func (*Client) ZRevRangeWithScoresMap Uses

func (c *Client) ZRevRangeWithScoresMap(key, start, stop string) *StringFloatMapCmd

func (*Client) ZRevRank Uses

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

func (*Client) ZScan Uses

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

func (*Client) ZScore Uses

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

func (*Client) ZUnionStore Uses

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

type Cmd Uses

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

func NewCmd Uses

func NewCmd(args ...string) *Cmd

func (Cmd) Err Uses

func (cmd Cmd) Err() error

func (*Cmd) Result Uses

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

func (*Cmd) String Uses

func (cmd *Cmd) String() string

func (*Cmd) Val Uses

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

type Cmder Uses

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

type DurationCmd Uses

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

func NewDurationCmd Uses

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

func (DurationCmd) Err Uses

func (cmd DurationCmd) Err() error

func (*DurationCmd) Result Uses

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

func (*DurationCmd) String Uses

func (cmd *DurationCmd) String() string

func (*DurationCmd) Val Uses

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

type FailoverOptions Uses

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 Uses

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

func NewFloatCmd Uses

func NewFloatCmd(args ...string) *FloatCmd

func (FloatCmd) Err Uses

func (cmd FloatCmd) Err() error

func (*FloatCmd) String Uses

func (cmd *FloatCmd) String() string

func (*FloatCmd) Val Uses

func (cmd *FloatCmd) Val() float64

type IntCmd Uses

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

func NewIntCmd Uses

func NewIntCmd(args ...string) *IntCmd

func (IntCmd) Err Uses

func (cmd IntCmd) Err() error

func (*IntCmd) Result Uses

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

func (*IntCmd) String Uses

func (cmd *IntCmd) String() string

func (*IntCmd) Val Uses

func (cmd *IntCmd) Val() int64

type Message Uses

type Message struct {
    Channel string
    Payload string
}

func (*Message) String Uses

func (m *Message) String() string

type Multi Uses

type Multi struct {
    *Client
}

Not thread-safe.

Code:

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() {
        tx.Set("key", strconv.FormatInt(n+1, 10))
    })
}

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 Uses

func (c *Multi) Close() error

func (*Multi) Discard Uses

func (c *Multi) Discard() error

func (*Multi) Exec Uses

func (c *Multi) Exec(f func()) ([]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 Uses

func (c Multi) Process(cmd Cmder)

func (*Multi) Unwatch Uses

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

func (*Multi) Watch Uses

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

type Options Uses

type Options struct {
    Addr     string
    Password string
    DB       int64

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

    PoolSize    int
    IdleTimeout time.Duration
}

type PMessage Uses

type PMessage struct {
    Channel string
    Pattern string
    Payload string
}

func (*PMessage) String Uses

func (m *PMessage) String() string

type Pipeline Uses

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

Not thread-safe.

Code:

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 Uses

func (c *Pipeline) Close() error

func (*Pipeline) Discard Uses

func (c *Pipeline) Discard() error

func (*Pipeline) Exec Uses

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

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

func (Pipeline) Process Uses

func (c Pipeline) Process(cmd Cmder)

type PubSub Uses

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

Not thread-safe.

Code:

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 Uses

func (c PubSub) Close() error

Close closes the client, releasing any open resources.

func (*PubSub) PSubscribe Uses

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

func (*PubSub) PUnsubscribe Uses

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

func (PubSub) Process Uses

func (c PubSub) Process(cmd Cmder)

func (*PubSub) Receive Uses

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

func (*PubSub) ReceiveTimeout Uses

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

func (*PubSub) Subscribe Uses

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

func (*PubSub) Unsubscribe Uses

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

type ScanCmd Uses

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

func NewScanCmd Uses

func NewScanCmd(args ...string) *ScanCmd

func (ScanCmd) Err Uses

func (cmd ScanCmd) Err() error

func (*ScanCmd) Result Uses

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

func (*ScanCmd) String Uses

func (cmd *ScanCmd) String() string

func (*ScanCmd) Val Uses

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

type Script Uses

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

Code:

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 Uses

func NewScript(src string) *Script

func (*Script) Eval Uses

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

func (*Script) EvalSha Uses

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

func (*Script) Exists Uses

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

func (*Script) Load Uses

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

func (*Script) Run Uses

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

type SliceCmd Uses

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

func NewSliceCmd Uses

func NewSliceCmd(args ...string) *SliceCmd

func (SliceCmd) Err Uses

func (cmd SliceCmd) Err() error

func (*SliceCmd) Result Uses

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

func (*SliceCmd) String Uses

func (cmd *SliceCmd) String() string

func (*SliceCmd) Val Uses

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

type Sort Uses

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

type StatusCmd Uses

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

func NewStatusCmd Uses

func NewStatusCmd(args ...string) *StatusCmd

func (StatusCmd) Err Uses

func (cmd StatusCmd) Err() error

func (*StatusCmd) Result Uses

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

func (*StatusCmd) String Uses

func (cmd *StatusCmd) String() string

func (*StatusCmd) Val Uses

func (cmd *StatusCmd) Val() string

type StringCmd Uses

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

func NewStringCmd Uses

func NewStringCmd(args ...string) *StringCmd

func (StringCmd) Err Uses

func (cmd StringCmd) Err() error

func (*StringCmd) Result Uses

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

func (*StringCmd) String Uses

func (cmd *StringCmd) String() string

func (*StringCmd) Val Uses

func (cmd *StringCmd) Val() string

type StringFloatMapCmd Uses

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

func NewStringFloatMapCmd Uses

func NewStringFloatMapCmd(args ...string) *StringFloatMapCmd

func (StringFloatMapCmd) Err Uses

func (cmd StringFloatMapCmd) Err() error

func (*StringFloatMapCmd) Result Uses

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

func (*StringFloatMapCmd) String Uses

func (cmd *StringFloatMapCmd) String() string

func (*StringFloatMapCmd) Val Uses

func (cmd *StringFloatMapCmd) Val() map[string]float64

type StringSliceCmd Uses

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

func NewStringSliceCmd Uses

func NewStringSliceCmd(args ...string) *StringSliceCmd

func (StringSliceCmd) Err Uses

func (cmd StringSliceCmd) Err() error

func (*StringSliceCmd) Result Uses

func (cmd *StringSliceCmd) Result() ([]string, error)

func (*StringSliceCmd) String Uses

func (cmd *StringSliceCmd) String() string

func (*StringSliceCmd) Val Uses

func (cmd *StringSliceCmd) Val() []string

type StringStringMapCmd Uses

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

func NewStringStringMapCmd Uses

func NewStringStringMapCmd(args ...string) *StringStringMapCmd

func (StringStringMapCmd) Err Uses

func (cmd StringStringMapCmd) Err() error

func (*StringStringMapCmd) Result Uses

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

func (*StringStringMapCmd) String Uses

func (cmd *StringStringMapCmd) String() string

func (*StringStringMapCmd) Val Uses

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

type Subscription Uses

type Subscription struct {
    Kind    string
    Channel string
    Count   int
}

func (*Subscription) String Uses

func (m *Subscription) String() string

type Z Uses

type Z struct {
    Score  float64
    Member string
}

type ZRangeByScore Uses

type ZRangeByScore struct {
    Min, Max string

    Offset, Count int64
}

type ZStore Uses

type ZStore struct {
    Weights   []int64
    Aggregate string
}

Package redis imports 13 packages (graph) and is imported by 2 packages. Updated 2016-07-15. Refresh now. Tools for package owners.