redis

package module
v0.0.0-...-58f0d11 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2014 License: BSD-3-Clause Imports: 14 Imported by: 0

README

New version

Make sure to check new version of the client that got better API and timeout support: https://github.com/vmihailenco/redis/tree/master/v2

Redis client for Golang

Supports:

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

API docs: http://godoc.org/github.com/vmihailenco/redis

Installation

Install:

go get github.com/vmihailenco/redis

Getting started

Let's start with connecting to Redis using TCP:

password := ""  // no password set
db := int64(-1) // use default DB
client := redis.NewTCPClient("localhost:6379", password, db)
defer client.Close()

ping := client.Ping()
fmt.Println(ping.Err(), ping.Val())
// Output: <nil> PONG

or using Unix socket:

client := redis.NewUnixClient("/tmp/redis.sock", "", -1)
defer client.Close()

ping := client.Ping()
fmt.Println(ping.Err(), ping.Val())
// Output: <nil> PONG

Then we can start sending commands:

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

get := client.Get("foo")
fmt.Println(get.Err(), get.Val())

// Output: <nil> OK
// <nil> bar

We can also pipeline two commands together:

var set *redis.StatusReq
var get *redis.StringReq
reqs, err := client.Pipelined(func(c *redis.PipelineClient) {
    set = c.Set("key1", "hello1")
    get = c.Get("key2")
})
fmt.Println(err, reqs)
fmt.Println(set)
fmt.Println(get)
// Output: <nil> [SET key1 hello1: OK GET key2: (nil)]
// SET key1 hello1: OK
// GET key2: (nil)

or:

var set *redis.StatusReq
var get *redis.StringReq
reqs, err := client.Pipelined(func(c *redis.PipelineClient) {
    set = c.Set("key1", "hello1")
    get = c.Get("key2")
})
fmt.Println(err, reqs)
fmt.Println(set)
fmt.Println(get)
// Output: <nil> [SET key1 hello1 GET key2]
// SET key1 hello1
// GET key2

We can also send several commands in transaction:

func transaction(multi *redis.MultiClient) ([]redis.Req, error) {
    get := multi.Get("key")
    if err := get.Err(); err != nil && err != redis.Nil {
        return nil, err
    }

    val, _ := strconv.ParseInt(get.Val(), 10, 64)

    reqs, err := multi.Exec(func() {
        multi.Set("key", strconv.FormatInt(val+1, 10))
    })
    // Transaction failed. Repeat.
    if err == redis.Nil {
        return transaction(multi)
    }
    return reqs, err
}

multi, err := client.MultiClient()
_ = err
defer multi.Close()

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

reqs, err := transaction(multi)
fmt.Println(err, reqs)

// Output: <nil> [SET key 1: OK]

To subscribe to the channel:

pubsub, err := client.PubSubClient()
defer pubsub.Close()

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

subscribeMsg := <-ch
fmt.Println(subscribeMsg.Err, subscribeMsg.Name)

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

msg := <-ch
fmt.Println(msg.Err, msg.Message)

// Output: <nil> subscribe
// <nil> hello

You can also write custom commands:

func Get(client *redis.Client, key string) *redis.StringReq {
    req := redis.NewStringReq("GET", key)
    client.Process(req)
    return req
}

get := Get(client, "key_does_not_exist")
fmt.Println(get.Err(), get.Val())
// Output: (nil)

Client uses connection pool to send commands. You can change maximum number of connections with:

client.ConnPool.(*redis.MultiConnPool).MaxCap = 1

Look and feel

Some corner cases:

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

ZRANGEBYSCORE zset -inf +inf WITHSCORES LIMIT 0 2
client.ZRangeByScoreWithScores("zset", "-inf", "+inf", 0, 2)

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

EVAL "return {KEYS[1],ARGV[1]}" 1 "key" "hello"
client.Eval("return {KEYS[1],ARGV[1]}", []string{"key"}, []string{"hello"})

Contributing

Configure Redis to allow maximum 10 clients:

maxclients 10

Run tests:

go test -gocheck.v

Run benchmarks:

go test -gocheck.b

Documentation

Overview

Package github.com/vmihailenco/redis implements a Redis client.

Let's start with connecting to Redis using TCP:

password := ""  // no password set
db := int64(-1) // use default DB
client := redis.NewTCPClient("localhost:6379", password, db)
defer client.Close()

ping := client.Ping()
fmt.Println(ping.Err(), ping.Val())
// Output: <nil> PONG

or using Unix socket:

client := redis.NewUnixClient("/tmp/redis.sock", "", -1)
defer client.Close()

ping := client.Ping()
fmt.Println(ping.Err(), ping.Val())
// Output: <nil> PONG

Then we can start sending commands:

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

get := client.Get("foo")
fmt.Println(get.Err(), get.Val())

// Output: <nil> OK
// <nil> bar

We can also pipeline two commands together:

var set *redis.StatusReq
var get *redis.StringReq
reqs, err := client.Pipelined(func(c *redis.PipelineClient) {
    set = c.Set("key1", "hello1")
    get = c.Get("key2")
})
fmt.Println(err, reqs)
fmt.Println(set)
fmt.Println(get)
// Output: <nil> [SET key1 hello1: OK GET key2: (nil)]
// SET key1 hello1: OK
// GET key2: (nil)

or:

var set *redis.StatusReq
var get *redis.StringReq
reqs, err := client.Pipelined(func(c *redis.PipelineClient) {
    set = c.Set("key1", "hello1")
    get = c.Get("key2")
})
fmt.Println(err, reqs)
fmt.Println(set)
fmt.Println(get)
// Output: <nil> [SET key1 hello1 GET key2]
// SET key1 hello1
// GET key2

We can also send several commands in transaction:

func transaction(multi *redis.MultiClient) ([]redis.Req, error) {
    get := multi.Get("key")
    if err := get.Err(); err != nil && err != redis.Nil {
        return nil, err
    }

    val, _ := strconv.ParseInt(get.Val(), 10, 64)

    reqs, err := multi.Exec(func() {
        multi.Set("key", strconv.FormatInt(val+1, 10))
    })
    // Transaction failed. Repeat.
    if err == redis.Nil {
        return transaction(multi)
    }
    return reqs, err
}

multi, err := client.MultiClient()
_ = err
defer multi.Close()

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

reqs, err := transaction(multi)
fmt.Println(err, reqs)

// Output: <nil> [SET key 1: OK]

To subscribe to the channel:

pubsub, err := client.PubSubClient()
defer pubsub.Close()

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

subscribeMsg := <-ch
fmt.Println(subscribeMsg.Err, subscribeMsg.Name)

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

msg := <-ch
fmt.Println(msg.Err, msg.Message)

// Output: <nil> subscribe
// <nil> hello

You can also write custom commands:

func Get(client *redis.Client, key string) *redis.StringReq {
    req := redis.NewStringReq("GET", key)
    client.Process(req)
    return req
}

get := Get(client, "key_does_not_exist")
fmt.Println(get.Err(), get.Val())
// Output: (nil)

Client uses connection pool to send commands. You can change maximum number of connections with:

client.ConnPool.(*redis.MultiConnPool).MaxCap = 1

Index

Constants

This section is empty.

Variables

View Source
var Logger = log.New(os.Stdout, "redis: ", log.Ldate|log.Ltime)

Package logger.

View Source
var Nil = errors.New("(nil)")

Represents Redis nil reply.

Functions

func ParseReq

func ParseReq(rd reader) ([]string, error)

Types

type BaseClient

type BaseClient struct {
	ConnPool ConnPool
	InitConn InitConnFunc
	// contains filtered or unexported fields
}

func (*BaseClient) Close

func (c *BaseClient) Close() error

func (*BaseClient) Process

func (c *BaseClient) Process(req Req)

func (*BaseClient) Queue

func (c *BaseClient) Queue(req Req)

Queues request to be executed later.

func (*BaseClient) Run

func (c *BaseClient) Run(req Req)

func (*BaseClient) WriteReq

func (c *BaseClient) WriteReq(conn *Conn, reqs ...Req) error

type BaseReq

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

func NewBaseReq

func NewBaseReq(args ...string) *BaseReq

func (*BaseReq) Args

func (r *BaseReq) Args() []string

func (*BaseReq) Err

func (r *BaseReq) Err() error

func (*BaseReq) IfaceVal

func (r *BaseReq) IfaceVal() interface{}

func (*BaseReq) ParseReply

func (r *BaseReq) ParseReply(rd reader) (interface{}, error)

func (*BaseReq) SetErr

func (r *BaseReq) SetErr(err error)

func (*BaseReq) SetVal

func (r *BaseReq) SetVal(val interface{})

func (*BaseReq) String

func (r *BaseReq) String() string

type BitCount

type BitCount struct {
	Start, End int64
}

type BoolReq

type BoolReq struct {
	*BaseReq
}

func NewBoolReq

func NewBoolReq(args ...string) *BoolReq

func (*BoolReq) ParseReply

func (r *BoolReq) ParseReply(rd reader) (interface{}, error)

func (*BoolReq) Val

func (r *BoolReq) Val() bool

type BoolSliceReq

type BoolSliceReq struct {
	*BaseReq
}

func NewBoolSliceReq

func NewBoolSliceReq(args ...string) *BoolSliceReq

func (*BoolSliceReq) ParseReply

func (r *BoolSliceReq) ParseReply(rd reader) (interface{}, error)

func (*BoolSliceReq) Val

func (r *BoolSliceReq) Val() []bool

type Client

type Client struct {
	*BaseClient
}

func NewClient

func NewClient(openConn OpenConnFunc, closeConn CloseConnFunc, initConn InitConnFunc) *Client

func NewTCPClient

func NewTCPClient(addr string, password string, db int64) *Client

func NewTLSClient

func NewTLSClient(addr string, tlsConfig *tls.Config, password string, db int64) *Client

func NewUnixClient

func NewUnixClient(addr string, password string, db int64) *Client

func (*Client) Append

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

func (*Client) Auth

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

func (*Client) BLPop

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

func (*Client) BRPop

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

func (*Client) BRPopLPush

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

func (*Client) BgRewriteAOF

func (c *Client) BgRewriteAOF() *StatusReq

func (*Client) BgSave

func (c *Client) BgSave() *StatusReq

func (*Client) BitCount

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

func (*Client) BitOpAnd

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

func (*Client) BitOpNot

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

func (*Client) BitOpOr

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

func (*Client) BitOpXor

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

func (*Client) ClientKill

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

func (*Client) ClientList

func (c *Client) ClientList() *StringReq

func (*Client) ConfigGet

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

func (*Client) ConfigResetStat

func (c *Client) ConfigResetStat() *StatusReq

func (*Client) ConfigSet

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

func (*Client) DbSize

func (c *Client) DbSize() *IntReq

func (*Client) Decr

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

func (*Client) DecrBy

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

func (*Client) Del

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

func (*Client) Dump

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

func (*Client) Echo

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

func (*Client) Eval

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

func (*Client) EvalSha

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

func (*Client) Exists

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

func (*Client) Expire

func (c *Client) Expire(key string, seconds int64) *BoolReq

func (*Client) ExpireAt

func (c *Client) ExpireAt(key string, timestamp int64) *BoolReq

func (*Client) FlushAll

func (c *Client) FlushAll() *StatusReq

func (*Client) FlushDb

func (c *Client) FlushDb() *StatusReq

func (*Client) Get

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

func (*Client) GetBit

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

func (*Client) GetRange

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

func (*Client) GetSet

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

func (*Client) HDel

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

func (*Client) HExists

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

func (*Client) HGet

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

func (*Client) HGetAll

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

func (*Client) HGetAllMap

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

func (*Client) HIncrBy

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

func (*Client) HIncrByFloat

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

func (*Client) HKeys

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

func (*Client) HLen

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

func (*Client) HMGet

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

func (*Client) HMSet

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

func (*Client) HSet

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

func (*Client) HSetNX

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

func (*Client) HVals

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

func (*Client) Incr

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

func (*Client) IncrBy

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

func (*Client) IncrByFloat

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

func (*Client) Info

func (c *Client) Info() *StringReq

func (*Client) Keys

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

func (*Client) LIndex

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

func (*Client) LInsert

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

func (*Client) LLen

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

func (*Client) LPop

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

func (*Client) LPush

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

func (*Client) LPushX

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

func (*Client) LRange

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

func (*Client) LRem

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

func (*Client) LSet

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

func (*Client) LTrim

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

func (*Client) LastSave

func (c *Client) LastSave() *IntReq

func (*Client) MGet

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

func (*Client) MSet

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

func (*Client) MSetNX

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

func (*Client) Migrate

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

func (*Client) Monitor

func (c *Client) Monitor()

func (*Client) Move

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

func (*Client) MultiClient

func (c *Client) MultiClient() (*MultiClient, error)

func (*Client) ObjectEncoding

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

func (*Client) ObjectIdleTime

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

func (*Client) ObjectRefCount

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

func (*Client) PExpire

func (c *Client) PExpire(key string, milliseconds int64) *BoolReq

func (*Client) PExpireAt

func (c *Client) PExpireAt(key string, milliseconds int64) *BoolReq

func (*Client) PSetEx

func (c *Client) PSetEx(key string, milliseconds int64, value string) *StatusReq

func (*Client) PTTL

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

func (*Client) Persist

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

func (*Client) Ping

func (c *Client) Ping() *StatusReq

func (*Client) PipelineClient

func (c *Client) PipelineClient() (*PipelineClient, error)

func (*Client) Pipelined

func (c *Client) Pipelined(do func(*PipelineClient)) ([]Req, error)

func (*Client) PubSubClient

func (c *Client) PubSubClient() (*PubSubClient, error)

func (*Client) Publish

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

func (*Client) Quit

func (c *Client) Quit() *StatusReq

func (*Client) RPop

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

func (*Client) RPopLPush

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

func (*Client) RPush

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

func (*Client) RPushX

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

func (*Client) RandomKey

func (c *Client) RandomKey() *StringReq

func (*Client) Rename

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

func (*Client) RenameNX

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

func (*Client) Restore

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

func (*Client) SAdd

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

func (*Client) SCard

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

func (*Client) SDiff

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

func (*Client) SDiffStore

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

func (*Client) SInter

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

func (*Client) SInterStore

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

func (*Client) SIsMember

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

func (*Client) SMembers

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

func (*Client) SMove

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

func (*Client) SPop

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

func (*Client) SRandMember

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

func (*Client) SRem

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

func (*Client) SUnion

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

func (*Client) SUnionStore

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

func (*Client) Save

func (c *Client) Save() *StatusReq

func (*Client) ScriptExists

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

func (*Client) ScriptFlush

func (c *Client) ScriptFlush() *StatusReq

func (*Client) ScriptKill

func (c *Client) ScriptKill() *StatusReq

func (*Client) ScriptLoad

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

func (*Client) Select

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

func (*Client) Set

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

func (*Client) SetBit

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

func (*Client) SetEx

func (c *Client) SetEx(key string, seconds int64, value string) *StatusReq

func (*Client) SetNX

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

func (*Client) SetRange

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

func (*Client) Shutdown

func (c *Client) Shutdown() *StatusReq

func (*Client) ShutdownNoSave

func (c *Client) ShutdownNoSave() *StatusReq

func (*Client) ShutdownSave

func (c *Client) ShutdownSave() *StatusReq

func (*Client) SlaveOf

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

func (*Client) SlowLog

func (c *Client) SlowLog()

func (*Client) Sort

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

func (*Client) StrLen

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

func (*Client) Sync

func (c *Client) Sync()

func (*Client) TTL

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

func (*Client) Time

func (c *Client) Time() *StringSliceReq

func (*Client) Type

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

func (*Client) ZAdd

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

func (*Client) ZCard

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

func (*Client) ZCount

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

func (*Client) ZIncrBy

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

func (*Client) ZInterStore

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

func (*Client) ZRange

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

func (*Client) ZRangeByScore

func (c *Client) ZRangeByScore(key string, min, max string, offset, count int64) *StringSliceReq

func (*Client) ZRangeByScoreWithScores

func (c *Client) ZRangeByScoreWithScores(key, min, max string, offset, count int64) *StringSliceReq

func (*Client) ZRangeByScoreWithScoresMap

func (c *Client) ZRangeByScoreWithScoresMap(
	key string, min, max string, offset, count int64) *StringFloatMapReq

func (*Client) ZRangeWithScores

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

func (*Client) ZRangeWithScoresMap

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

func (*Client) ZRank

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

func (*Client) ZRem

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

func (*Client) ZRemRangeByRank

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

func (*Client) ZRemRangeByScore

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

func (*Client) ZRevRange

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

func (*Client) ZRevRangeByScore

func (c *Client) ZRevRangeByScore(key, start, stop string, offset, count int64) *StringSliceReq

func (*Client) ZRevRangeByScoreWithScores

func (c *Client) ZRevRangeByScoreWithScores(key, start, stop string, offset, count int64) *StringSliceReq

func (*Client) ZRevRangeByScoreWithScoresMap

func (c *Client) ZRevRangeByScoreWithScoresMap(
	key, start, stop string, offset, count int64) *StringFloatMapReq

func (*Client) ZRevRangeWithScores

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

func (*Client) ZRevRangeWithScoresMap

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

func (*Client) ZRevRank

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

func (*Client) ZScore

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

func (*Client) ZUnionStore

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

type CloseConnFunc

type CloseConnFunc func(net.Conn) error

type Conn

type Conn struct {
	RW net.Conn
	Rd reader
}

func NewConn

func NewConn(rw net.Conn) *Conn

type ConnPool

type ConnPool interface {
	Get() (*Conn, bool, error)
	Add(*Conn) error
	Remove(*Conn) error
	Len() int
	Close() error
}

type FloatReq

type FloatReq struct {
	*BaseReq
}

func NewFloatReq

func NewFloatReq(args ...string) *FloatReq

func (*FloatReq) ParseReply

func (r *FloatReq) ParseReply(rd reader) (interface{}, error)

func (*FloatReq) Val

func (r *FloatReq) Val() float64

type IfaceReq

type IfaceReq struct {
	*BaseReq
}

func NewIfaceReq

func NewIfaceReq(args ...string) *IfaceReq

func (*IfaceReq) Val

func (r *IfaceReq) Val() interface{}

type IfaceSliceReq

type IfaceSliceReq struct {
	*BaseReq
}

func NewIfaceSliceReq

func NewIfaceSliceReq(args ...string) *IfaceSliceReq

func (*IfaceSliceReq) Val

func (r *IfaceSliceReq) Val() []interface{}

type InitConnFunc

type InitConnFunc func(*Client) error

func AuthSelectFunc

func AuthSelectFunc(password string, db int64) InitConnFunc

type IntReq

type IntReq struct {
	*BaseReq
}

func NewIntReq

func NewIntReq(args ...string) *IntReq

func (*IntReq) Val

func (r *IntReq) Val() int64

type Message

type Message struct {
	Name, Channel, ChannelPattern, Message string
	Number                                 int64

	Err error
}

type MultiClient

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

func (*MultiClient) Close

func (c *MultiClient) Close() error

func (*MultiClient) Discard

func (c *MultiClient) Discard()

func (*MultiClient) Exec

func (c *MultiClient) Exec(do func()) ([]Req, error)

func (*MultiClient) ExecReqs

func (c *MultiClient) ExecReqs(reqs []Req, conn *Conn) error

func (*MultiClient) Unwatch

func (c *MultiClient) Unwatch(keys ...string) *StatusReq

func (*MultiClient) Watch

func (c *MultiClient) Watch(keys ...string) *StatusReq

type MultiConnPool

type MultiConnPool struct {
	Logger *log.Logger

	OpenConn  OpenConnFunc
	CloseConn CloseConnFunc
	MaxCap    int
	// contains filtered or unexported fields
}

func NewMultiConnPool

func NewMultiConnPool(openConn OpenConnFunc, closeConn CloseConnFunc, maxCap int) *MultiConnPool

func (*MultiConnPool) Add

func (p *MultiConnPool) Add(conn *Conn) error

func (*MultiConnPool) Close

func (p *MultiConnPool) Close() error

func (*MultiConnPool) Get

func (p *MultiConnPool) Get() (*Conn, bool, error)

func (*MultiConnPool) Len

func (p *MultiConnPool) Len() int

func (*MultiConnPool) Remove

func (p *MultiConnPool) Remove(conn *Conn) error

type OpenConnFunc

type OpenConnFunc func() (net.Conn, error)

func TCPConnector

func TCPConnector(addr string) OpenConnFunc

func TLSConnector

func TLSConnector(addr string, tlsConfig *tls.Config) OpenConnFunc

func UnixConnector

func UnixConnector(addr string) OpenConnFunc

type PipelineClient

type PipelineClient struct {
	*Client
}

func (*PipelineClient) Close

func (c *PipelineClient) Close() error

func (*PipelineClient) DiscardQueued

func (c *PipelineClient) DiscardQueued()

func (*PipelineClient) RunQueued

func (c *PipelineClient) RunQueued() ([]Req, error)

func (*PipelineClient) RunReqs

func (c *PipelineClient) RunReqs(reqs []Req, conn *Conn) error

type PubSubClient

type PubSubClient struct {
	*BaseClient
	// contains filtered or unexported fields
}

func (*PubSubClient) PSubscribe

func (c *PubSubClient) PSubscribe(patterns ...string) (chan *Message, error)

func (*PubSubClient) PUnsubscribe

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

func (*PubSubClient) Subscribe

func (c *PubSubClient) Subscribe(channels ...string) (chan *Message, error)

func (*PubSubClient) Unsubscribe

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

type Req

type Req interface {
	Args() []string
	ParseReply(reader) (interface{}, error)
	SetErr(error)
	Err() error
	SetVal(interface{})
	IfaceVal() interface{}
}

type Script

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

func NewScript

func NewScript(src string) *Script

func (*Script) Eval

func (s *Script) Eval(c *Client, keys []string, args []string) *IfaceReq

func (*Script) EvalSha

func (s *Script) EvalSha(c *Client, keys []string, args []string) *IfaceReq

func (*Script) Exists

func (s *Script) Exists(c *Client) *BoolSliceReq

func (*Script) Load

func (s *Script) Load(c *Client) *StringReq

func (*Script) Run

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

type SingleConnPool

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

func NewSingleConnPool

func NewSingleConnPool(pool ConnPool, isReusable bool) *SingleConnPool

func NewSingleConnPoolConn

func NewSingleConnPoolConn(pool ConnPool, conn *Conn, isReusable bool) *SingleConnPool

func (*SingleConnPool) Add

func (p *SingleConnPool) Add(conn *Conn) error

func (*SingleConnPool) Close

func (p *SingleConnPool) Close() error

func (*SingleConnPool) Get

func (p *SingleConnPool) Get() (*Conn, bool, error)

func (*SingleConnPool) Len

func (p *SingleConnPool) Len() int

func (*SingleConnPool) Remove

func (p *SingleConnPool) Remove(conn *Conn) error

type Sort

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

type StatusReq

type StatusReq struct {
	*BaseReq
}

func NewStatusReq

func NewStatusReq(args ...string) *StatusReq

func (*StatusReq) Val

func (r *StatusReq) Val() string

type StringFloatMapReq

type StringFloatMapReq struct {
	*BaseReq
}

func NewStringFloatMapReq

func NewStringFloatMapReq(args ...string) *StringFloatMapReq

func (*StringFloatMapReq) ParseReply

func (r *StringFloatMapReq) ParseReply(rd reader) (interface{}, error)

func (*StringFloatMapReq) Val

func (r *StringFloatMapReq) Val() map[string]float64

type StringReq

type StringReq struct {
	*BaseReq
}

func NewStringReq

func NewStringReq(args ...string) *StringReq

func (*StringReq) Val

func (r *StringReq) Val() string

type StringSliceReq

type StringSliceReq struct {
	*BaseReq
}

func NewStringSliceReq

func NewStringSliceReq(args ...string) *StringSliceReq

func (*StringSliceReq) ParseReply

func (r *StringSliceReq) ParseReply(rd reader) (interface{}, error)

func (*StringSliceReq) Val

func (r *StringSliceReq) Val() []string

type StringStringMapReq

type StringStringMapReq struct {
	*BaseReq
}

func NewStringStringMapReq

func NewStringStringMapReq(args ...string) *StringStringMapReq

func (*StringStringMapReq) ParseReply

func (r *StringStringMapReq) ParseReply(rd reader) (interface{}, error)

func (*StringStringMapReq) Val

func (r *StringStringMapReq) Val() map[string]string

type Z

type Z struct {
	Score  float64
	Member string
}

type ZStore

type ZStore struct {
	Weights   []int64
	Aggregate string
}

Directories

Path Synopsis
Package github.com/vmihailenco/redis/v2 implements a Redis client.
Package github.com/vmihailenco/redis/v2 implements a Redis client.

Jump to

Keyboard shortcuts

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