godis

package module
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: May 12, 2020 License: MIT Imports: 12 Imported by: 4

README

godis

Go Doc Build Status Go Report codecov License

redis client implement by golang, refers to jedis.
this library implements most of redis command, include normal redis command, cluster command, sentinel command, pipeline command and transaction command.
if you've ever used jedis, then you can use godis easily, godis almost has the same method of jedis.
especially, godis implements distributed lock in single mode and cluster mode, godis's lock is much more faster than redisson, on my computer(i7,8core,32g), run 100,000 loop, use 8 threads, the business code is just count++, redisson need 18s-20s, while godis just need 7 second.
godis has done many test case to make sure it's stable.

I am glad you made any suggestions, and I will actively iterate over the project.

Features

  • cluster
  • pipeline
  • transaction
  • distributed lock
  • other feature under development

Installation

go get -u github.com/piaohao/godis

or use go.mod:

require github.com/piaohao/godis latest

Documentation

Quick Start

  1. basic example

    package main
    
    import (
        "github.com/piaohao/godis"
    )
    
    func main() {
        redis := godis.NewRedis(&godis.Option{
            Host: "localhost",
            Port: 6379,
            Db:   0,
        })
        defer redis.Close()
        redis.Set("godis", "1")
        arr, _ := redis.Get("godis")
        println(arr)
    }
    
  2. use pool

    package main
    
    import (
        "github.com/piaohao/godis"
    )
    
    func main() {
        option:=&godis.Option{
            Host: "localhost",
            Port: 6379,
            Db:   0,
        }
        pool := godis.NewPool(&godis.PoolConfig{}, option)
        redis, _ := pool.GetResource()
        defer redis.Close()
        redis.Set("godis", "1")
        arr, _ := redis.Get("godis")
        println(arr)
    }
    
  3. pubsub

    package main
    
    import (
        "github.com/piaohao/godis"
        "time"
    )
    
    func main() {
        option:=&godis.Option{
            Host: "localhost",
            Port: 6379,
            Db:   0,
        }
        pool := godis.NewPool(&godis.PoolConfig{}, option)
        go func() {
            redis, _ := pool.GetResource()
            defer redis.Close()
            pubsub := &godis.RedisPubSub{
                OnMessage: func(channel, message string) {
                    println(channel, message)
                },
                OnSubscribe: func(channel string, subscribedChannels int) {
                    println(channel, subscribedChannels)
                },
                OnPong: func(channel string) {
                    println("recieve pong")
                },
            }
            redis.Subscribe(pubsub, "godis")
        }()
        time.Sleep(1 * time.Second)
        {
            redis, _ := pool.GetResource()
            defer redis.Close()
            redis.Publish("godis", "godis pubsub")
            redis.Close()
        }
        time.Sleep(1 * time.Second)
    }
    
  4. cluster

    package main
    
    import (
        "github.com/piaohao/godis"
        "time"
    )
    
    func main() {
        cluster := godis.NewRedisCluster(&godis.ClusterOption{
            Nodes:             []string{"localhost:7000", "localhost:7001", "localhost:7002", "localhost:7003", "localhost:7004", "localhost:7005"},
            ConnectionTimeout: 0,
            SoTimeout:         0,
            MaxAttempts:       0,
            Password:          "",
            PoolConfig:        &godis.PoolConfig{},
        })
        cluster.Set("cluster", "godis cluster")
        reply, _ := cluster.Get("cluster")
        println(reply)
    }
    
  5. pipeline

    package main
    
    import (
        "github.com/piaohao/godis"
        "time"
    )
    
    func main() {
        option:=&godis.Option{
            Host: "localhost",
            Port: 6379,
            Db:   0,
        }
        pool := godis.NewPool(&godis.PoolConfig{}, option)
        redis, _ := pool.GetResource()
        defer redis.Close()
        p := redis.Pipelined()
        infoResp, _ := p.Info()
        timeResp, _ := p.Time()
        p.Sync()
        timeList, _ := timeResp.Get()
        println(timeList)
        info, _ := infoResp.Get()
        println(info)
    }
    
  6. transaction

    package main
    
    import (
        "github.com/piaohao/godis"
        "time"
    )
    
    func main() {
        option:=&godis.Option{
            Host: "localhost",
            Port: 6379,
            Db:   0,
        }
        pool := godis.NewPool(nil, option)
        redis, _ := pool.GetResource()
        defer redis.Close()
        p, _ := redis.Multi()
        infoResp, _ := p.Info()
        timeResp, _ := p.Time()
        p.Exec()
        timeList, _ := timeResp.Get()
        println(timeList)
        info, _ := infoResp.Get()
        println(info)
    }
    
  7. distribute lock

    • single redis
         package main
      
         import (
             "github.com/piaohao/godis"
             "time"
         )
      
         func main() {
             locker := godis.NewLocker(&godis.Option{
                   Host: "localhost",
                   Port: 6379,
                   Db:   0,
               }, &godis.LockOption{
                   Timeout: 5*time.Second,
               })
             lock, err := locker.TryLock("lock")
             if err == nil && lock!=nil {
                 //do something
                 locker.UnLock(lock)
             }
      
         }
      
    • redis cluster
         package main
      
         import (
             "github.com/piaohao/godis"
             "time"
         )
      
         func main() {
             locker := godis.NewClusterLocker(&godis.ClusterOption{
             	Nodes:             []string{"localhost:7000", "localhost:7001", "localhost:7002", "localhost:7003", "localhost:7004", "localhost:7005"},
                 ConnectionTimeout: 0,
                 SoTimeout:         0,
                 MaxAttempts:       0,
                 Password:          "",
                 PoolConfig:        &godis.PoolConfig{},
             },&godis.LockOption{
                 Timeout: 5*time.Second,
             })
             lock, err := locker.TryLock("lock")
             if err == nil && lock!=nil {
                 //do something
                 locker.UnLock(lock)
             }
         }
      

License

godis is licensed under the MIT License, 100% free and open-source, forever.

Thanks

Contact

piao.hao@qq.com

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//ListOptionBefore insert an new element before designated element
	ListOptionBefore = newListOption("BEFORE")
	//ListOptionAfter insert an new element after designated element
	ListOptionAfter = newListOption("AFTER")
)
View Source
var (
	//GeoUnitMi calculate distance use mi unit
	GeoUnitMi = newGeoUnit("mi")
	//GeoUnitM calculate distance use m unit
	GeoUnitM = newGeoUnit("m")
	//GeoUnitKm calculate distance use km unit
	GeoUnitKm = newGeoUnit("km")
	//GeoUnitFt calculate distance use ft unit
	GeoUnitFt = newGeoUnit("ft")
)
View Source
var (
	//AggregateSum aggregate result with sum operation
	AggregateSum = newAggregate("SUM")
	//AggregateMin aggregate result with min operation
	AggregateMin = newAggregate("MIN")
	//AggregateMax aggregate result with max operation
	AggregateMax = newAggregate("MAX")
)
View Source
var (
	//BitOpAnd 'and' bit operation,&
	BitOpAnd = newBitOP("AND")
	//BitOpOr 'or' bit operation,|
	BitOpOr = newBitOP("OR")
	//BitOpXor 'xor' bit operation,X xor Y -> (X || Y) && !(X && Y)
	BitOpXor = newBitOP("XOR")
	//BitOpNot 'not' bit operation,^
	BitOpNot = newBitOP("NOT")
)
View Source
var (
	//ResetSoft soft reset
	ResetSoft = newReset("SOFT")
	//ResetHard hard reset
	ResetHard = newReset("HARD")
)
View Source
var (
	//StrBuilder convert interface to string
	StrBuilder = newStrBuilder()
	//Int64Builder convert interface to int64
	Int64Builder = newInt64Builder()
	//StrArrBuilder convert interface to string array
	StrArrBuilder = newStringArrayBuilder()
)
View Source
var (
	//ErrClosed when pool is closed,continue operate pool will return this error
	ErrClosed = errors.New("pool is closed")
)
View Source
var ErrLockTimeOut = errors.New("get lock timeout")

ErrLockTimeOut when get lock exceed the timeout,then return error

Functions

func BoolToByteArr added in v0.0.11

func BoolToByteArr(a bool) []byte

BoolToByteArr convert bool to byte array

func ByteArrToFloat64 added in v0.0.11

func ByteArrToFloat64(bytes []byte) float64

ByteArrToFloat64 convert byte array to float64

func ByteArrToStrReply added in v0.0.11

func ByteArrToStrReply(reply []byte, err error) (string, error)

ByteArrToStrReply convert byte array reply to string reply

func Float64ToByteArr added in v0.0.11

func Float64ToByteArr(a float64) []byte

Float64ToByteArr convert float64 to byte array

func Float64ToStr added in v0.0.11

func Float64ToStr(a float64) string

Float64ToStr convert float64 to string

func Int64ToBoolReply

func Int64ToBoolReply(reply int64, err error) (bool, error)

Int64ToBoolReply convert int64 reply to bool reply

func Int64ToByteArr added in v0.0.11

func Int64ToByteArr(a int64) []byte

Int64ToByteArr convert int64 to byte array

func IntToByteArr added in v0.0.11

func IntToByteArr(a int) []byte

IntToByteArr convert int to byte array

func ObjArrToMapArrayReply added in v0.0.11

func ObjArrToMapArrayReply(reply []interface{}, err error) ([]map[string]string, error)

ObjArrToMapArrayReply convert object array reply to map array reply

func ObjToEvalResult added in v0.0.11

func ObjToEvalResult(reply interface{}, err error) (interface{}, error)

ObjToEvalResult resolve response data when use script command

func StrArrToByteArrArr added in v0.0.11

func StrArrToByteArrArr(arr []string) [][]byte

StrArrToByteArrArr convert string array to byte array list

func StrArrToMapReply added in v0.0.11

func StrArrToMapReply(reply []string, err error) (map[string]string, error)

StrArrToMapReply convert string array reply to map reply

func StrStrArrToByteArrArr added in v0.0.11

func StrStrArrToByteArrArr(str string, arr []string) [][]byte

StrStrArrToByteArrArr convert string and string array to byte array

func StrStrArrToStrArr added in v0.0.11

func StrStrArrToStrArr(str string, arr []string) []string

StrStrArrToStrArr convert string and string array to string array

func StrToFloat64Reply added in v0.0.11

func StrToFloat64Reply(reply string, err error) (float64, error)

StrToFloat64Reply convert string reply to float64 reply

func ToBoolArrReply added in v0.0.11

func ToBoolArrReply(reply interface{}, err error) ([]bool, error)

ToBoolArrReply convert object reply to bool array reply

func ToBoolReply

func ToBoolReply(reply interface{}, err error) (bool, error)

ToBoolReply convert object reply to bool reply

func ToFloat64Reply

func ToFloat64Reply(reply interface{}, err error) (float64, error)

ToFloat64Reply convert object reply to float64 reply

func ToInt64ArrReply added in v0.0.11

func ToInt64ArrReply(reply interface{}, err error) ([]int64, error)

ToInt64ArrReply convert object reply to int64 array reply

func ToInt64Reply

func ToInt64Reply(reply interface{}, err error) (int64, error)

ToInt64Reply convert object reply to int64 reply

func ToMapReply

func ToMapReply(reply interface{}, err error) (map[string]string, error)

ToMapReply convert object reply to map reply

func ToStrArrReply added in v0.0.11

func ToStrArrReply(reply interface{}, err error) ([]string, error)

ToStrArrReply convert object reply to string array reply

func ToStrReply added in v0.0.11

func ToStrReply(reply interface{}, err error) (string, error)

ToStrReply convert object reply to string reply

Types

type Aggregate added in v0.0.11

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

Aggregate aggregate,sum|min|max

type AskDataError added in v0.0.5

type AskDataError struct {
	Message string
	Host    string
	Port    int
	Slot    int
}

AskDataError ask data error

func (*AskDataError) Error added in v0.0.5

func (e *AskDataError) Error() string

type BitOP

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

BitOP bit operation struct

type BitPosParams

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

BitPosParams bitpos params

type Builder

type Builder interface {
	// contains filtered or unexported methods
}

Builder convert pipeline|transaction response data

type BusyError added in v0.0.5

type BusyError struct {
	Message string
}

BusyError operation is busy error

func (*BusyError) Error added in v0.0.5

func (e *BusyError) Error() string

type ClusterError added in v0.0.5

type ClusterError struct {
	Message string
}

ClusterError cluster basic error

func (*ClusterError) Error added in v0.0.5

func (e *ClusterError) Error() string

type ClusterLocker added in v0.0.11

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

ClusterLocker cluster lock client

func NewClusterLocker added in v0.0.6

func NewClusterLocker(option *ClusterOption, lockOption *LockOption) *ClusterLocker

NewClusterLocker create new cluster locker

func (*ClusterLocker) TryLock added in v0.0.11

func (l *ClusterLocker) TryLock(key string) (*Lock, error)

TryLock acquire a lock,when it returns a non nil locker,get lock success, otherwise, it returns an error,get lock failed

func (*ClusterLocker) UnLock added in v0.0.11

func (l *ClusterLocker) UnLock(lock *Lock) error

UnLock when your business end,then release the locker

type ClusterMaxAttemptsError added in v0.0.7

type ClusterMaxAttemptsError struct {
	Message string
}

ClusterMaxAttemptsError cluster operation exceed max attempts errror

func (*ClusterMaxAttemptsError) Error added in v0.0.7

func (e *ClusterMaxAttemptsError) Error() string

type ClusterOperationError added in v0.0.7

type ClusterOperationError struct {
	Message string
}

ClusterOperationError cluster operation error

func (*ClusterOperationError) Error added in v0.0.7

func (e *ClusterOperationError) Error() string

type ClusterOption added in v0.0.6

type ClusterOption struct {
	Nodes             []string      //cluster nodes, for example: []string{"localhost:7000","localhost:7001"}
	ConnectionTimeout time.Duration //redis connect timeout
	SoTimeout         time.Duration //redis read timeout
	MaxAttempts       int           //when operation or socket is not alright,then program will attempt retry
	Password          string        //cluster redis password
	PoolConfig        *PoolConfig   //redis connection pool config
}

ClusterOption when you create a new cluster instance ,then you need set some option

type ConnectError added in v0.0.5

type ConnectError struct {
	Message string
}

ConnectError redis connection error,such as io timeout

func (*ConnectError) Error added in v0.0.5

func (e *ConnectError) Error() string

type DataError added in v0.0.5

type DataError struct {
	Message string
}

DataError data error

func (*DataError) Error added in v0.0.5

func (e *DataError) Error() string

type DebugParams

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

DebugParams debug params

func NewDebugParamsObject added in v0.0.5

func NewDebugParamsObject(key string) *DebugParams

NewDebugParamsObject create debug paramas with key

func NewDebugParamsReload added in v0.0.5

func NewDebugParamsReload() *DebugParams

NewDebugParamsReload create debug params with reload

func NewDebugParamsSegfault added in v0.0.5

func NewDebugParamsSegfault() *DebugParams

NewDebugParamsSegfault create debug prams with segfault

type GeoCoordinate

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

GeoCoordinate geo coordinate struct

func ObjArrToGeoCoordinateReply added in v0.0.11

func ObjArrToGeoCoordinateReply(reply []interface{}, err error) ([]*GeoCoordinate, error)

ObjArrToGeoCoordinateReply convert object array reply to GeoCoordinate reply

func ToGeoCoordArrReply added in v0.0.11

func ToGeoCoordArrReply(reply interface{}, err error) ([]*GeoCoordinate, error)

ToGeoCoordArrReply convert object reply to geocoordinate array reply

type GeoRadiusParams added in v0.0.11

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

GeoRadiusParams geo radius param

func NewGeoRadiusParam added in v0.0.7

func NewGeoRadiusParam() *GeoRadiusParams

NewGeoRadiusParam create a new geo radius param instance

func (*GeoRadiusParams) Contains added in v0.0.11

func (p *GeoRadiusParams) Contains(key string) bool

Contains test geo param contains the key

func (*GeoRadiusParams) Count added in v0.0.11

func (p *GeoRadiusParams) Count(count int) *GeoRadiusParams

Count fill the geo result with count

func (*GeoRadiusParams) SortAscending added in v0.0.11

func (p *GeoRadiusParams) SortAscending() *GeoRadiusParams

SortAscending sort th geo result in ascending order

func (*GeoRadiusParams) SortDescending added in v0.0.11

func (p *GeoRadiusParams) SortDescending() *GeoRadiusParams

SortDescending sort the geo result in descending order

func (*GeoRadiusParams) WithCoord added in v0.0.11

func (p *GeoRadiusParams) WithCoord() *GeoRadiusParams

WithCoord fill the geo result with coordinate

func (*GeoRadiusParams) WithDist added in v0.0.11

func (p *GeoRadiusParams) WithDist() *GeoRadiusParams

WithDist fill the geo result with distance

type GeoRadiusResponse

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

GeoRadiusResponse geo radius response

func ObjArrToGeoRadiusResponseReply added in v0.0.11

func ObjArrToGeoRadiusResponseReply(reply []interface{}, err error) ([]GeoRadiusResponse, error)

ObjArrToGeoRadiusResponseReply convert object array reply to GeoRadiusResponse reply

func ToGeoRespArrReply added in v0.0.11

func ToGeoRespArrReply(reply interface{}, err error) ([]GeoRadiusResponse, error)

ToGeoRespArrReply convert object reply to GeoRadiusResponse array reply

type GeoUnit

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

GeoUnit geo unit,m|mi|km|ft

type ListOption

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

ListOption list option

type Lock added in v0.0.11

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

Lock different keys with different lock

type LockOption added in v0.0.5

type LockOption struct {
	Timeout time.Duration //lock wait timeout
}

LockOption locker options

type Locker added in v0.0.5

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

Locker the lock client

func NewLocker added in v0.0.6

func NewLocker(option *Option, lockOption *LockOption) *Locker

NewLocker create new locker

func (*Locker) TryLock added in v0.0.5

func (l *Locker) TryLock(key string) (*Lock, error)

TryLock acquire a lock,when it returns a non nil locker,get lock success, otherwise, it returns an error,get lock failed

func (*Locker) UnLock added in v0.0.5

func (l *Locker) UnLock(lock *Lock) error

UnLock when your business end,then release the locker

type MovedDataError added in v0.0.5

type MovedDataError struct {
	Message string
	Host    string
	Port    int
	Slot    int
}

MovedDataError cluster move data error

func (*MovedDataError) Error added in v0.0.5

func (e *MovedDataError) Error() string

type NoReachableClusterNodeError added in v0.0.6

type NoReachableClusterNodeError struct {
	Message string
}

NoReachableClusterNodeError have no reachable cluster node error

func (*NoReachableClusterNodeError) Error added in v0.0.6

type NoScriptError added in v0.0.5

type NoScriptError struct {
	Message string
}

NoScriptError has no script error

func (*NoScriptError) Error added in v0.0.5

func (e *NoScriptError) Error() string

type Option added in v0.0.3

type Option struct {
	Host              string        // redis host
	Port              int           // redis port
	ConnectionTimeout time.Duration // connect timeout
	SoTimeout         time.Duration // read timeout
	Password          string        // redis password,if empty,then without auth
	Db                int           // which db to connect
}

Option connect options

type Pipeline

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

Pipeline redis pipeline struct

func (Pipeline) BLPop added in v0.0.11

func (p Pipeline) BLPop(args ...string) (*Response, error)

BLPop see redis command

func (Pipeline) BLPopTimeout added in v0.0.11

func (p Pipeline) BLPopTimeout(timeout int, keys ...string) (*Response, error)

BLPopTimeout see redis command

func (Pipeline) BRPop added in v0.0.11

func (p Pipeline) BRPop(args ...string) (*Response, error)

BRPop see redis command

func (Pipeline) BRPopLPush added in v0.0.11

func (p Pipeline) BRPopLPush(source, destination string, timeout int) (*Response, error)

BRPopLPush see redis command

func (Pipeline) BRPopTimeout added in v0.0.11

func (p Pipeline) BRPopTimeout(timeout int, keys ...string) (*Response, error)

BRPopTimeout see redis command

func (Pipeline) BgRewriteAof added in v0.0.11

func (p Pipeline) BgRewriteAof() (*Response, error)

BgRewriteAof see redis command

func (Pipeline) BgSave added in v0.0.11

func (p Pipeline) BgSave() (*Response, error)

BgSave see redis command

func (Pipeline) BitOp added in v0.0.11

func (p Pipeline) BitOp(op BitOP, destKey string, srcKeys ...string) (*Response, error)

BitOp see redis command

func (Pipeline) ClusterAddSlots added in v0.0.11

func (p Pipeline) ClusterAddSlots(slots ...int) (*Response, error)

ClusterAddSlots see redis command

func (Pipeline) ClusterDelSlots added in v0.0.11

func (p Pipeline) ClusterDelSlots(slots ...int) (*Response, error)

ClusterDelSlots see redis command

func (Pipeline) ClusterGetKeysInSlot added in v0.0.11

func (p Pipeline) ClusterGetKeysInSlot(slot int, count int) (*Response, error)

ClusterGetKeysInSlot see redis command

func (Pipeline) ClusterInfo added in v0.0.11

func (p Pipeline) ClusterInfo() (*Response, error)

ClusterInfo see redis command

func (Pipeline) ClusterMeet added in v0.0.11

func (p Pipeline) ClusterMeet(ip string, port int) (*Response, error)

ClusterMeet see redis command

func (Pipeline) ClusterNodes added in v0.0.11

func (p Pipeline) ClusterNodes() (*Response, error)

ClusterNodes see redis command

func (Pipeline) ClusterSetSlotImporting added in v0.0.11

func (p Pipeline) ClusterSetSlotImporting(slot int, nodeID string) (*Response, error)

ClusterSetSlotImporting see redis command

func (Pipeline) ClusterSetSlotMigrating added in v0.0.11

func (p Pipeline) ClusterSetSlotMigrating(slot int, nodeID string) (*Response, error)

ClusterSetSlotMigrating see redis command

func (Pipeline) ClusterSetSlotNode added in v0.0.11

func (p Pipeline) ClusterSetSlotNode(slot int, nodeID string) (*Response, error)

ClusterSetSlotNode see redis command

func (Pipeline) ConfigGet added in v0.0.11

func (p Pipeline) ConfigGet(pattern string) (*Response, error)

ConfigGet see redis command

func (Pipeline) ConfigResetStat added in v0.0.11

func (p Pipeline) ConfigResetStat() (*Response, error)

ConfigResetStat see redis command

func (Pipeline) ConfigSet added in v0.0.11

func (p Pipeline) ConfigSet(parameter, value string) (*Response, error)

ConfigSet see redis command

func (Pipeline) DbSize added in v0.0.11

func (p Pipeline) DbSize() (*Response, error)

DbSize see redis command

func (Pipeline) Del added in v0.0.11

func (p Pipeline) Del(keys ...string) (*Response, error)

Del see redis command

func (Pipeline) Eval added in v0.0.11

func (p Pipeline) Eval(script string, keyCount int, params ...string) (*Response, error)

Eval see redis command

func (Pipeline) EvalSha added in v0.0.11

func (p Pipeline) EvalSha(sha1 string, keyCount int, params ...string) (*Response, error)

EvalSha see redis command

func (Pipeline) Exists added in v0.0.11

func (p Pipeline) Exists(keys ...string) (*Response, error)

Exists see redis command

func (Pipeline) FlushAll added in v0.0.11

func (p Pipeline) FlushAll() (*Response, error)

FlushAll see redis command

func (Pipeline) FlushDB added in v0.0.11

func (p Pipeline) FlushDB() (*Response, error)

FlushDB see redis command

func (Pipeline) Info added in v0.0.11

func (p Pipeline) Info() (*Response, error)

Info see redis command

func (Pipeline) Keys added in v0.0.11

func (p Pipeline) Keys(pattern string) (*Response, error)

Keys see redis command

func (Pipeline) LastSave added in v0.0.11

func (p Pipeline) LastSave() (*Response, error)

LastSave see redis command

func (Pipeline) MGet added in v0.0.11

func (p Pipeline) MGet(keys ...string) (*Response, error)

MGet see redis command

func (Pipeline) MSet added in v0.0.11

func (p Pipeline) MSet(kvs ...string) (*Response, error)

MSet see redis command

func (Pipeline) MSetNx added in v0.0.11

func (p Pipeline) MSetNx(kvs ...string) (*Response, error)

MSetNx see redis command

func (Pipeline) PfCount added in v0.0.11

func (p Pipeline) PfCount(keys ...string) (*Response, error)

PfCount see redis command

func (Pipeline) PfMerge added in v0.0.11

func (p Pipeline) PfMerge(destKey string, srcKeys ...string) (*Response, error)

PfMerge see redis command

func (Pipeline) Ping added in v0.0.11

func (p Pipeline) Ping() (*Response, error)

Ping see redis command

func (Pipeline) Publish added in v0.0.11

func (p Pipeline) Publish(channel, message string) (*Response, error)

Publish see redis command

func (Pipeline) RPopLPush added in v0.0.11

func (p Pipeline) RPopLPush(srcKey, destKey string) (*Response, error)

RPopLPush see redis command

func (Pipeline) RandomKey added in v0.0.11

func (p Pipeline) RandomKey() (*Response, error)

RandomKey see redis command

func (Pipeline) Rename added in v0.0.11

func (p Pipeline) Rename(oldkey, newkey string) (*Response, error)

Rename see redis command

func (Pipeline) RenameNx added in v0.0.11

func (p Pipeline) RenameNx(oldkey, newkey string) (*Response, error)

RenameNx see redis command

func (Pipeline) SDiff added in v0.0.11

func (p Pipeline) SDiff(keys ...string) (*Response, error)

SDiff see redis command

func (Pipeline) SDiffStore added in v0.0.11

func (p Pipeline) SDiffStore(destKey string, keys ...string) (*Response, error)

SDiffStore see redis command

func (Pipeline) SInter added in v0.0.11

func (p Pipeline) SInter(keys ...string) (*Response, error)

SInter see redis command

func (Pipeline) SInterStore added in v0.0.11

func (p Pipeline) SInterStore(destKey string, keys ...string) (*Response, error)

SInterStore see redis command

func (Pipeline) SMove added in v0.0.11

func (p Pipeline) SMove(srcKey, destKey, member string) (*Response, error)

SMove see redis command

func (Pipeline) SUnion added in v0.0.11

func (p Pipeline) SUnion(keys ...string) (*Response, error)

SUnion see redis command

func (Pipeline) SUnionStore added in v0.0.11

func (p Pipeline) SUnionStore(destKey string, keys ...string) (*Response, error)

SUnionStore see redis command

func (Pipeline) Save added in v0.0.11

func (p Pipeline) Save() (*Response, error)

Save see redis command

func (Pipeline) Select added in v0.0.11

func (p Pipeline) Select(index int) (*Response, error)

Select see redis command

func (Pipeline) Shutdown added in v0.0.11

func (p Pipeline) Shutdown() (*Response, error)

Shutdown see redis command

func (Pipeline) SortStore added in v0.0.11

func (p Pipeline) SortStore(key string, destKey string, params ...*SortParams) (*Response, error)

SortMulti see redis command

func (*Pipeline) Sync

func (p *Pipeline) Sync() error

Sync see redis command

func (Pipeline) Time added in v0.0.11

func (p Pipeline) Time() (*Response, error)

Time see redis command

func (Pipeline) Watch added in v0.0.11

func (p Pipeline) Watch(keys ...string) (*Response, error)

Watch see redis command

func (Pipeline) ZInterStore added in v0.0.11

func (p Pipeline) ZInterStore(destKey string, sets ...string) (*Response, error)

ZInterStore see redis command

func (Pipeline) ZInterStoreWithParams added in v0.0.11

func (p Pipeline) ZInterStoreWithParams(destKey string, params *ZParams, sets ...string) (*Response, error)

ZInterStoreWithParams see redis command

func (Pipeline) ZUnionStore added in v0.0.11

func (p Pipeline) ZUnionStore(destKey string, sets ...string) (*Response, error)

ZUnionStore see redis command

func (Pipeline) ZUnionStoreWithParams added in v0.0.11

func (p Pipeline) ZUnionStoreWithParams(destKey string, params *ZParams, sets ...string) (*Response, error)

ZUnionStoreWithParams see redis command

type Pool

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

Pool redis pool

func NewPool

func NewPool(config *PoolConfig, option *Option) *Pool

NewPool create new pool

func (*Pool) Destroy

func (p *Pool) Destroy()

Destroy destroy pool

func (*Pool) GetResource

func (p *Pool) GetResource() (*Redis, error)

GetResource get redis instance from pool

type PoolConfig

type PoolConfig struct {
	MaxTotal int //The cap on the number of objects that can be allocated
	MaxIdle  int //The cap on the number of "idle" instances in the pool
	MinIdle  int //The minimum number of idle objects to maintain in the pool

	LIFO               bool //Whether the pool has LIFO (last in, first out) behaviour
	TestOnBorrow       bool //Whether objects borrowed from the pool will be validated before being returned from the ObjectPool.BorrowObject() method
	TestWhileIdle      bool //Whether objects sitting idle in the pool will be validated by the idle object evictor (if any - see TimeBetweenEvictionRuns )
	TestOnReturn       bool //Whether objects borrowed from the pool will be validated when they are returned to the pool via the ObjectPool.ReturnObject() method
	TestOnCreate       bool //Whether objects created for the pool will be validated before being returned from the ObjectPool.BorrowObject() method.
	BlockWhenExhausted bool //Whether to block when the ObjectPool.BorrowObject() method is invoked when the pool is exhausted

	MinEvictableIdleTime     time.Duration //The minimum amount of time an object may sit idle in the pool
	SoftMinEvictableIdleTime time.Duration //if MinEvictableIdleTime is positive, then SoftMinEvictableIdleTime is ignored
	TimeBetweenEvictionRuns  time.Duration //The amount of time sleep between runs of the idle object evictor goroutine.
	EvictionPolicyName       string        //The name of the EvictionPolicy implementation
	NumTestsPerEvictionRun   int           //The maximum number of objects to examine during each run
}

PoolConfig redis pool config, see go-commons-pool ObjectPoolConfig

type RedirectError added in v0.0.7

type RedirectError struct {
	Message string
}

RedirectError cluster operation redirect error

func (*RedirectError) Error added in v0.0.7

func (e *RedirectError) Error() string

type Redis

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

Redis redis client tool

func NewRedis

func NewRedis(option *Option) *Redis

NewRedis constructor for creating new redis

func (*Redis) Append

func (r *Redis) Append(key, value string) (int64, error)

Append If the key already exists and is a string, this command appends the provided value at the end of the string. If the key does not exist it is created and set as an empty string, so APPEND will be very similar to SET in this special case.

Time complexity: O(1). The amortized time complexity is O(1) assuming the appended value is small and the already present value is of any size, since the dynamic string library used by Redis will double the free space available on every reallocation.

return Integer reply, specifically the total length of the string after the append operation.

func (*Redis) Asking

func (r *Redis) Asking() (string, error)

Asking ...

func (*Redis) Auth

func (r *Redis) Auth(password string) (string, error)

Auth when server is set password,then you need to auth password.

func (*Redis) BLPop added in v0.0.11

func (r *Redis) BLPop(args ...string) ([]string, error)

BLPop BLPOP (and BRPOP) is a blocking list pop primitive. You can see this commands as blocking versions of LPOP and RPOP able to block if the specified keys don't exist or contain empty lists.

The following is a description of the exact semantic. We describe BLPOP but the two commands are identical, the only difference is that BLPOP pops the element from the left (head) of the list, and BRPOP pops from the right (tail).

<b>Non blocking behavior</b>

When BLPOP is called, if at least one of the specified keys contain a non empty list, an element is popped from the head of the list and returned to the caller together with the name of the key (BLPOP returns a two elements array, the first element is the key, the second the popped value).

Keys are scanned from left to right, so for instance if you issue BLPOP list1 list2 list3 0 against a dataset where list1 does not exist but list2 and list3 contain non empty lists, BLPOP guarantees to return an element from the list stored at list2 (since it is the first non empty list starting from the left).

<b>Blocking behavior</b>

If none of the specified keys exist or contain non empty lists, BLPOP blocks until some other client performs a LPUSH or an RPUSH operation against one of the lists.

Once new data is present on one of the lists, the client finally returns with the name of the key unblocking it and the popped value.

When blocking, if a non-zero timeout is specified, the client will unblock returning a nil special value if the specified amount of seconds passed without a push operation against at least one of the specified keys.

The timeout argument is interpreted as an integer value. A timeout of zero means instead to block forever.

<b>Multiple clients blocking for the same keys</b>

Multiple clients can block for the same key. They are put into a queue, so the first to be served will be the one that started to wait earlier, in a first-blpopping first-served fashion.

<b>blocking POP inside a MULTI/EXEC transaction</b>

BLPOP and BRPOP can be used with pipelining (sending multiple commands and reading the replies in batch), but it does not make sense to use BLPOP or BRPOP inside a MULTI/EXEC block (a Redis transaction).

The behavior of BLPOP inside MULTI/EXEC when the list is empty is to return a multi-bulk nil reply, exactly what happens when the timeout is reached. If you like science fiction, think at it like if inside MULTI/EXEC the time will flow at infinite speed :)

return BLPOP returns a two-elements array via a multi bulk reply in order to return both the

unblocking key and the popped value.

When a non-zero timeout is specified, and the BLPOP operation timed out, the return
value is a nil multi bulk reply. Most client values will return false or nil
accordingly to the programming language used.

func (*Redis) BLPopTimeout added in v0.0.11

func (r *Redis) BLPopTimeout(timeout int, keys ...string) ([]string, error)

BLPopTimeout ...

func (*Redis) BRPop added in v0.0.11

func (r *Redis) BRPop(args ...string) ([]string, error)

BRPop see blpop

func (*Redis) BRPopLPush added in v0.0.11

func (r *Redis) BRPopLPush(srcKey, destKey string, timeout int) (string, error)

BRPopLPush ...

func (*Redis) BRPopTimeout added in v0.0.11

func (r *Redis) BRPopTimeout(timeout int, keys ...string) ([]string, error)

BRPopTimeout ...

func (*Redis) BgRewriteAof added in v0.0.11

func (r *Redis) BgRewriteAof() (string, error)

BgRewriteAof ...

func (*Redis) BgSave added in v0.0.11

func (r *Redis) BgSave() (string, error)

BgSave ...

func (*Redis) BitCount added in v0.0.11

func (r *Redis) BitCount(key string) (int64, error)

BitCount Count the number of set bits (population counting) in a string.

By default all the bytes contained in the string are examined. It is possible to specify the counting operation only in an interval passing the additional arguments start and end.

Like for the GETRANGE command start and end can contain negative values in order to index bytes starting from the end of the string, where -1 is the last byte, -2 is the penultimate, and so forth.

Non-existent keys are treated as empty strings, so the command will return zero.

Return value Integer reply The number of bits set to 1.

func (*Redis) BitCountRange added in v0.0.11

func (r *Redis) BitCountRange(key string, start, end int64) (int64, error)

BitCountRange see BitCount()

func (*Redis) BitField added in v0.0.11

func (r *Redis) BitField(key string, arguments ...string) ([]int64, error)

BitField The command treats a Redis string as a array of bits, and is capable of addressing specific integer fields of varying bit widths and arbitrary non (necessary) aligned offset.

func (*Redis) BitOp added in v0.0.11

func (r *Redis) BitOp(op BitOP, destKey string, srcKeys ...string) (int64, error)

BitOp ...

func (*Redis) BitPos added in v0.0.11

func (r *Redis) BitPos(key string, value bool, params ...*BitPosParams) (int64, error)

BitPos Return the position of the first bit set to 1 or 0 in a string.

func (*Redis) Close

func (r *Redis) Close() error

Close close redis connection

func (*Redis) ClusterAddSlots

func (r *Redis) ClusterAddSlots(slots ...int) (string, error)

ClusterAddSlots ...

func (*Redis) ClusterCountKeysInSlot

func (r *Redis) ClusterCountKeysInSlot(slot int) (int64, error)

ClusterCountKeysInSlot ...

func (*Redis) ClusterDelSlots

func (r *Redis) ClusterDelSlots(slots ...int) (string, error)

ClusterDelSlots ...

func (*Redis) ClusterFailOver added in v0.0.11

func (r *Redis) ClusterFailOver() (string, error)

ClusterFailOver This command, that can only be sent to a Redis Cluster replica node, forces the replica to start a manual failover of its master instance.

func (*Redis) ClusterFlushSlots

func (r *Redis) ClusterFlushSlots() (string, error)

ClusterFlushSlots ...

func (*Redis) ClusterForget

func (r *Redis) ClusterForget(nodeID string) (string, error)

ClusterForget ...

func (*Redis) ClusterGetKeysInSlot

func (r *Redis) ClusterGetKeysInSlot(slot int, count int) ([]string, error)

ClusterGetKeysInSlot ...

func (*Redis) ClusterInfo

func (r *Redis) ClusterInfo() (string, error)

ClusterInfo ...

func (*Redis) ClusterKeySlot

func (r *Redis) ClusterKeySlot(key string) (int64, error)

ClusterKeySlot ...

func (*Redis) ClusterMeet

func (r *Redis) ClusterMeet(ip string, port int) (string, error)

ClusterMeet ...

func (*Redis) ClusterNodes

func (r *Redis) ClusterNodes() (string, error)

ClusterNodes Each node in a Redis Cluster has its view of the current cluster configuration, given by the set of known nodes, the state of the connection we have with such nodes, their flags, properties and assigned slots, and so forth.

func (*Redis) ClusterReplicate

func (r *Redis) ClusterReplicate(nodeID string) (string, error)

ClusterReplicate ...

func (*Redis) ClusterReset

func (r *Redis) ClusterReset(resetType Reset) (string, error)

ClusterReset ...

func (*Redis) ClusterSaveConfig

func (r *Redis) ClusterSaveConfig() (string, error)

ClusterSaveConfig ...

func (*Redis) ClusterSetSlotImporting

func (r *Redis) ClusterSetSlotImporting(slot int, nodeID string) (string, error)

ClusterSetSlotImporting ...

func (*Redis) ClusterSetSlotMigrating

func (r *Redis) ClusterSetSlotMigrating(slot int, nodeID string) (string, error)

ClusterSetSlotMigrating ...

func (*Redis) ClusterSetSlotNode

func (r *Redis) ClusterSetSlotNode(slot int, nodeID string) (string, error)

ClusterSetSlotNode ...

func (*Redis) ClusterSetSlotStable

func (r *Redis) ClusterSetSlotStable(slot int) (string, error)

ClusterSetSlotStable ...

func (*Redis) ClusterSlaves

func (r *Redis) ClusterSlaves(nodeID string) ([]string, error)

ClusterSlaves ...

func (*Redis) ClusterSlots

func (r *Redis) ClusterSlots() ([]interface{}, error)

ClusterSlots ...

func (*Redis) ConfigGet

func (r *Redis) ConfigGet(pattern string) ([]string, error)

ConfigGet The CONFIG GET command is used to read the configuration parameters of a running Redis server. Not all the configuration parameters are supported in Redis 2.4, while Redis 2.6 can read the whole configuration of a server using this command.

func (*Redis) ConfigResetStat

func (r *Redis) ConfigResetStat() (string, error)

ConfigResetStat ...

func (*Redis) ConfigSet

func (r *Redis) ConfigSet(parameter, value string) (string, error)

ConfigSet The CONFIG SET command is used in order to reconfigure the server at run time without the need to restart Redis. You can change both trivial parameters or switch from one to another persistence option using this command.

func (*Redis) Connect

func (r *Redis) Connect() error

Connect connect to redis

func (*Redis) DbSize

func (r *Redis) DbSize() (int64, error)

DbSize return key count of current db

func (*Redis) Debug

func (r *Redis) Debug(params DebugParams) (string, error)

Debug ...

func (*Redis) Decr

func (r *Redis) Decr(key string) (int64, error)

Decr Decrement the number stored at key by one. If the key does not exist or contains a value of a wrong type, set the key to the value of "0" before to perform the decrement operation.

INCR commands are limited to 64 bit signed integers.

Note: this is actually a string operation, that is, in Redis there are not "integer" types. Simply the string stored at the key is parsed as a base 10 64 bit signed integer, incremented, and then converted back as a string.

return Integer reply, this commands will reply with the new value of key after the increment.

func (*Redis) DecrBy

func (r *Redis) DecrBy(key string, decrement int64) (int64, error)

DecrBy work just like {@link #decr(String) INCR} but instead to decrement by 1 the decrement is integer.

INCR commands are limited to 64 bit signed integers.

Note: this is actually a string operation, that is, in Redis there are not "integer" types. Simply the string stored at the key is parsed as a base 10 64 bit signed integer, incremented, and then converted back as a string.

return Integer reply, this commands will reply with the new value of key after the increment.

func (*Redis) Del

func (r *Redis) Del(keys ...string) (int64, error)

Del Remove the specified keys. If a given key does not exist no operation is performed for this key. The command returns the number of keys removed. param keys return Integer reply, specifically: an integer greater than 0 if one or more keys were removed

0 if none of the specified key existed

func (*Redis) Echo

func (r *Redis) Echo(string string) (string, error)

Echo Returns message.

Return value Bulk string reply

func (*Redis) Eval

func (r *Redis) Eval(script string, keyCount int, params ...string) (interface{}, error)

Eval evaluate scripts using the Lua interpreter built into Redis

func (*Redis) EvalByKeyArgs added in v0.0.5

func (r *Redis) EvalByKeyArgs(script string, keys []string, args []string) (interface{}, error)

EvalByKeyArgs evaluate scripts using the Lua interpreter built into Redis

func (*Redis) EvalSha added in v0.0.11

func (r *Redis) EvalSha(sha1 string, keyCount int, params ...string) (interface{}, error)

EvalSha Evaluates a script cached on the server side by its SHA1 digest. Scripts are cached on the server side using the SCRIPT LOAD command. The command is otherwise identical to EVAL.

func (*Redis) Exists

func (r *Redis) Exists(keys ...string) (int64, error)

Exists Test if the specified key exists. The command returns the number of keys existed param keys return Integer reply, specifically: an integer greater than 0 if one or more keys were removed

0 if none of the specified key existed

func (*Redis) Expire

func (r *Redis) Expire(key string, seconds int) (int64, error)

Expire Set a timeout on the specified key. After the timeout the key will be automatically deleted by the server. A key with an associated timeout is said to be volatile in Redis terminology.

Voltile keys are stored on disk like the other keys, the timeout is persistent too like all the other aspects of the dataset. Saving a dataset containing expires and stopping the server does not stop the flow of time as Redis stores on disk the time when the key will no longer be available as Unix time, and not the remaining seconds.

Since Redis 2.1.3 you can update the value of the timeout of a key already having an expire set. It is also possible to undo the expire at all turning the key into a normal key using the {@link #persist(String) PERSIST} command.

return Integer reply, specifically: 1: the timeout was set. 0: the timeout was not set since

the key already has an associated timeout (this may happen only in Redis versions &lt;
2.1.3, Redis &gt;= 2.1.3 will happily update the timeout), or the key does not exist.

func (*Redis) ExpireAt

func (r *Redis) ExpireAt(key string, unixTimeSeconds int64) (int64, error)

ExpireAt EXPIREAT works exctly like {@link #expire(String, int) EXPIRE} but instead to get the number of seconds representing the Time To Live of the key as a second argument (that is a relative way of specifying the TTL), it takes an absolute one in the form of a UNIX timestamp (Number of seconds elapsed since 1 Gen 1970).

EXPIREAT was introduced in order to implement the Append Only File persistence mode so that EXPIRE commands are automatically translated into EXPIREAT commands for the append only file. Of course EXPIREAT can also used by programmers that need a way to simply specify that a given key should expire at a given time in the future.

Since Redis 2.1.3 you can update the value of the timeout of a key already having an expire set. It is also possible to undo the expire at all turning the key into a normal key using the {@link #persist(String) PERSIST} command.

return Integer reply, specifically: 1: the timeout was set. 0: the timeout was not set since

the key already has an associated timeout (this may happen only in Redis versions &lt;
2.1.3, Redis &gt;= 2.1.3 will happily update the timeout), or the key does not exist.

func (*Redis) FlushAll

func (r *Redis) FlushAll() (string, error)

FlushAll it will clear whole keys in whole db

func (*Redis) FlushDB

func (r *Redis) FlushDB() (string, error)

FlushDB it will clear whole keys in current db

func (*Redis) GeoAdd added in v0.0.11

func (r *Redis) GeoAdd(key string, longitude, latitude float64, member string) (int64, error)

GeoAdd add geo point

func (*Redis) GeoAddByMap added in v0.0.11

func (r *Redis) GeoAddByMap(key string, memberCoordinateMap map[string]GeoCoordinate) (int64, error)

GeoAddByMap add geo point by map Return value Integer reply, specifically: The number of elements added to the sorted set, not including elements already existing for which the score was updated.

func (*Redis) GeoDist added in v0.0.11

func (r *Redis) GeoDist(key, member1, member2 string, unit ...*GeoUnit) (float64, error)

GeoDist calculate distance of geo points

func (*Redis) GeoHash added in v0.0.11

func (r *Redis) GeoHash(key string, members ...string) ([]string, error)

GeoHash get geo point hash

func (*Redis) GeoPos added in v0.0.11

func (r *Redis) GeoPos(key string, members ...string) ([]*GeoCoordinate, error)

GeoPos get geo points

func (*Redis) GeoRadius added in v0.0.11

func (r *Redis) GeoRadius(key string, longitude, latitude, radius float64, unit *GeoUnit, param ...*GeoRadiusParams) ([]GeoRadiusResponse, error)

GeoRadius get members in certain range

func (*Redis) GeoRadiusByMember added in v0.0.11

func (r *Redis) GeoRadiusByMember(key, member string, radius float64, unit *GeoUnit, param ...*GeoRadiusParams) ([]GeoRadiusResponse, error)

GeoRadiusByMember get members in certain range

func (*Redis) Get

func (r *Redis) Get(key string) (string, error)

Get the value of the specified key. If the key does not exist null is returned. If the value stored at key is not a string an error is returned because GET can only handle string values. param key return Bulk reply

func (*Redis) GetBit added in v0.0.11

func (r *Redis) GetBit(key string, offset int64) (bool, error)

GetBit Returns the bit value at offset in the string value stored at key.

When offset is beyond the string length, the string is assumed to be a contiguous space with 0 bits. When key does not exist it is assumed to be an empty string, so offset is always out of range and the value is also assumed to be a contiguous space with 0 bits.

Return value Integer reply: the bit value stored at offset.

func (*Redis) GetRange added in v0.0.11

func (r *Redis) GetRange(key string, start, end int64) (string, error)

GetRange Warning: this command was renamed to GETRANGE, it is called SUBSTR in Redis versions <= 2.0. Returns the substring of the string value stored at key, determined by the offsets start and end (both are inclusive). Negative offsets can be used in order to provide an offset starting from the end of the string. So -1 means the last character, -2 the penultimate and so forth.

The function handles out of range requests by limiting the resulting range to the actual length of the string.

Return value Bulk string reply

func (*Redis) GetSet

func (r *Redis) GetSet(key, value string) (string, error)

GetSet GETSET is an atomic set this value and return the old value command. Set key to the string value and return the old value stored at key. The string can't be longer than 1073741824 bytes (1 GB).

return Bulk reply

func (*Redis) HDel added in v0.0.11

func (r *Redis) HDel(key string, fields ...string) (int64, error)

HDel Remove the specified field from an hash stored at key.

return If the field was present in the hash it is deleted and 1 is returned, otherwise 0 is returned and no operation is performed.

func (*Redis) HExists added in v0.0.11

func (r *Redis) HExists(key, field string) (bool, error)

HExists Test for existence of a specified field in a hash.

Return 1 if the hash stored at key contains the specified field. Return 0 if the key is not found or the field is not present.

func (*Redis) HGet added in v0.0.11

func (r *Redis) HGet(key, field string) (string, error)

HGet If key holds a hash, retrieve the value associated to the specified field.

If the field is not found or the key does not exist, a special 'nil' value is returned.

return Bulk reply

func (*Redis) HGetAll added in v0.0.11

func (r *Redis) HGetAll(key string) (map[string]string, error)

HGetAll Return all the fields and associated values in a hash.

return All the fields and values contained into a hash.

func (*Redis) HIncrBy added in v0.0.11

func (r *Redis) HIncrBy(key, field string, value int64) (int64, error)

HIncrBy Increment the number stored at field in the hash at key by value. If key does not exist, a new key holding a hash is created. If field does not exist or holds a string, the value is set to 0 before applying the operation. Since the value argument is signed you can use this command to perform both increments and decrements.

The range of values supported by HINCRBY is limited to 64 bit signed integers.

return Integer reply The new value at field after the increment operation.

func (*Redis) HIncrByFloat added in v0.0.11

func (r *Redis) HIncrByFloat(key, field string, increment float64) (float64, error)

HIncrByFloat Increment the number stored at field in the hash at key by a double precision floating point value. If key does not exist, a new key holding a hash is created. If field does not exist or holds a string, the value is set to 0 before applying the operation. Since the value argument is signed you can use this command to perform both increments and decrements.

The range of values supported by HINCRBYFLOAT is limited to double precision floating point values.

return Double precision floating point reply The new value at field after the increment

operation.

func (*Redis) HKeys added in v0.0.11

func (r *Redis) HKeys(key string) ([]string, error)

HKeys Return all the fields in a hash.

return All the fields names contained into a hash.

func (*Redis) HLen added in v0.0.11

func (r *Redis) HLen(key string) (int64, error)

HLen Return the number of items in a hash.

return The number of entries (fields) contained in the hash stored at key. If the specified key does not exist, 0 is returned assuming an empty hash.

func (*Redis) HMGet added in v0.0.11

func (r *Redis) HMGet(key string, fields ...string) ([]string, error)

HMGet Retrieve the values associated to the specified fields.

If some of the specified fields do not exist, nil values are returned. Non existing keys are considered like empty hashes.

return Multi Bulk Reply specifically a list of all the values associated with the specified

fields, in the same order of the request.

func (*Redis) HMSet added in v0.0.11

func (r *Redis) HMSet(key string, hash map[string]string) (string, error)

HMSet Set the respective fields to the respective values. HMSET replaces old values with new values.

If key does not exist, a new key holding a hash is created.

return Return OK or Exception if hash is empty

func (*Redis) HScan added in v0.0.11

func (r *Redis) HScan(key, cursor string, params ...*ScanParams) (*ScanResult, error)

HScan scan keys of hash , see scan

func (*Redis) HSet added in v0.0.11

func (r *Redis) HSet(key, field, value string) (int64, error)

HSet Set the specified hash field to the specified value.

If key does not exist, a new key holding a hash is created.

return If the field already exists, and the HSET just produced an update of the value, 0 is

returned, otherwise if a new field is created 1 is returned.

func (*Redis) HSetNx added in v0.0.11

func (r *Redis) HSetNx(key, field, value string) (int64, error)

HSetNx Set the specified hash field to the specified value if the field not exists.

return If the field already exists, 0 is returned, otherwise if a new field is created 1 is returned.

func (*Redis) HVals added in v0.0.11

func (r *Redis) HVals(key string) ([]string, error)

HVals Return all the values in a hash.

return All the fields values contained into a hash.

func (*Redis) Incr

func (r *Redis) Incr(key string) (int64, error)

Incr Increment the number stored at key by one. If the key does not exist or contains a value of a wrong type, set the key to the value of "0" before to perform the increment operation.

INCR commands are limited to 64 bit signed integers.

Note: this is actually a string operation, that is, in Redis there are not "integer" types. Simply the string stored at the key is parsed as a base 10 64 bit signed integer, incremented, and then converted back as a string.

return Integer reply, this commands will reply with the new value of key after the increment.

func (*Redis) IncrBy

func (r *Redis) IncrBy(key string, increment int64) (int64, error)

IncrBy work just like {@link #incr(String) INCR} but instead to increment by 1 the increment is integer.

INCR commands are limited to 64 bit signed integers.

Note: this is actually a string operation, that is, in Redis there are not "integer" types. Simply the string stored at the key is parsed as a base 10 64 bit signed integer, incremented, and then converted back as a string.

return Integer reply, this commands will reply with the new value of key after the increment.

func (*Redis) IncrByFloat

func (r *Redis) IncrByFloat(key string, increment float64) (float64, error)

IncrByFloat commands are limited to double precision floating point values.

Note: this is actually a string operation, that is, in Redis there are not "double" types. Simply the string stored at the key is parsed as a base double precision floating point value, incremented, and then converted back as a string. There is no DECRYBYFLOAT but providing a negative value will work as expected.

return Double reply, this commands will reply with the new value of key after the increment.

func (*Redis) Info

func (r *Redis) Info(section ...string) (string, error)

Info ...

func (*Redis) Keys

func (r *Redis) Keys(pattern string) ([]string, error)

Keys Returns all the keys matching the glob-style pattern as space separated strings. For example if you have in the database the keys "foo" and "foobar" the command "KEYS foo*" will return "foo foobar".

Note that while the time complexity for this operation is O(n) the constant times are pretty low. For example Redis running on an entry level laptop can scan a 1 million keys database in 40 milliseconds. <b>Still it's better to consider this one of the slow commands that may ruin the DB performance if not used with care.</b>

In other words this command is intended only for debugging and special operations like creating a script to change the DB schema. Don't use it in your normal code. Use Redis Sets in order to group together a subset of objects.

Glob style patterns examples: <ul> <li>h?llo will match hello hallo hhllo <li>h*llo will match hllo heeeello <li>h[ae]llo will match hello and hallo, but not hillo </ul>

Use \ to escape special chars if you want to match them verbatim.

return Multi bulk reply

func (*Redis) LIndex added in v0.0.11

func (r *Redis) LIndex(key string, index int64) (string, error)

LIndex Return the specified element of the list stored at the specified key. 0 is the first element, 1 the second and so on. Negative indexes are supported, for example -1 is the last element, -2 the penultimate and so on.

If the value stored at key is not of list type an error is returned. If the index is out of range a 'nil' reply is returned.

return Bulk reply, specifically the requested element

func (*Redis) LInsert added in v0.0.11

func (r *Redis) LInsert(key string, where *ListOption, pivot, value string) (int64, error)

LInsert Inserts value in the list stored at key either before or after the reference value pivot. When key does not exist, it is considered an empty list and no operation is performed. An error is returned when key exists but does not hold a list value.

Return value Integer reply: the length of the list after the insert operation, or -1 when the value pivot was not found.

func (*Redis) LLen added in v0.0.11

func (r *Redis) LLen(key string) (int64, error)

LLen Return the length of the list stored at the specified key. If the key does not exist zero is returned (the same behaviour as for empty lists). If the value stored at key is not a list an error is returned.

return The length of the list.

func (*Redis) LPop added in v0.0.11

func (r *Redis) LPop(key string) (string, error)

LPop Atomically return and remove the first (LPOP) or last (RPOP) element of the list. For example if the list contains the elements "a","b","c" LPOP will return "a" and the list will become "b","c".

If the key does not exist or the list is already empty the special value 'nil' is returned.

return Bulk reply

func (*Redis) LPush added in v0.0.11

func (r *Redis) LPush(key string, members ...string) (int64, error)

LPush Add the string value to the head (LPUSH) or tail (RPUSH) of the list stored at key. If the key does not exist an empty list is created just before the append operation. If the key exists but is not a List an error is returned.

return Integer reply, specifically, the number of elements inside the list after the push

operation.

func (*Redis) LPushX added in v0.0.11

func (r *Redis) LPushX(key string, members ...string) (int64, error)

LPushX Inserts value at the head of the list stored at key, only if key already exists and holds a list. In contrary to LPUSH, no operation will be performed when key does not yet exist. Return value Integer reply: the length of the list after the push operation.

func (*Redis) LRange added in v0.0.11

func (r *Redis) LRange(key string, start, stop int64) ([]string, error)

LRange Return the specified elements of the list stored at the specified key. Start and end are zero-based indexes. 0 is the first element of the list (the list head), 1 the next element and so on.

For example LRANGE foobar 0 2 will return the first three elements of the list.

start and end can also be negative numbers indicating offsets from the end of the list. For example -1 is the last element of the list, -2 the penultimate element and so on.

<b>Consistency with range functions in various programming languages</b>

Note that if you have a list of numbers from 0 to 100, LRANGE 0 10 will return 11 elements, that is, rightmost item is included. This may or may not be consistent with behavior of range-related functions in your programming language of choice (think Ruby's Range.new, Array#slice or Python's range() function).

LRANGE behavior is consistent with one of Tcl.

Indexes out of range will not produce an error: if start is over the end of the list, or start &gt; end, an empty list is returned. If end is over the end of the list Redis will threat it just like the last element of the list.

return Multi bulk reply, specifically a list of elements in the specified range.

func (*Redis) LRem added in v0.0.11

func (r *Redis) LRem(key string, count int64, value string) (int64, error)

LRem Remove the first count occurrences of the value element from the list. If count is zero all the elements are removed. If count is negative elements are removed from tail to head, instead to go from head to tail that is the normal behaviour. So for example LREM with count -2 and hello as value to remove against the list (a,b,c,hello,x,hello,hello) will lave the list (a,b,c,hello,x). The number of removed elements is returned as an integer, see below for more information about the returned value. Note that non existing keys are considered like empty lists by LREM, so LREM against non existing keys will always return 0.

return Integer Reply, specifically: The number of removed elements if the operation succeeded

func (*Redis) LSet added in v0.0.11

func (r *Redis) LSet(key string, index int64, value string) (string, error)

LSet Set a new value as the element at index position of the List at key.

Out of range indexes will generate an error.

Similarly to other list commands accepting indexes, the index can be negative to access elements starting from the end of the list. So -1 is the last element, -2 is the penultimate, and so forth.

return Status code reply

func (*Redis) LTrim added in v0.0.11

func (r *Redis) LTrim(key string, start, stop int64) (string, error)

LTrim Trim an existing list so that it will contain only the specified range of elements specified. Start and end are zero-based indexes. 0 is the first element of the list (the list head), 1 the next element and so on.

For example LTRIM foobar 0 2 will modify the list stored at foobar key so that only the first three elements of the list will remain.

start and end can also be negative numbers indicating offsets from the end of the list. For example -1 is the last element of the list, -2 the penultimate element and so on.

Indexes out of range will not produce an error: if start is over the end of the list, or start &gt; end, an empty list is left as value. If end over the end of the list Redis will threat it just like the last element of the list.

Hint: the obvious use of LTRIM is together with LPUSH/RPUSH. For example:

{@code lpush("mylist", "someelement"); ltrim("mylist", 0, 99); //}

The above two commands will push elements in the list taking care that the list will not grow without limits. This is very useful when using Redis to store logs for example. It is important to note that when used in this way LTRIM is an O(1) operation because in the average case just one element is removed from the tail of the list.

return Status code reply

func (*Redis) LastSave added in v0.0.11

func (r *Redis) LastSave() (int64, error)

LastSave ...

func (*Redis) MGet added in v0.0.11

func (r *Redis) MGet(keys ...string) ([]string, error)

MGet Get the values of all the specified keys. If one or more keys dont exist or is not of type String, a 'nil' value is returned instead of the value of the specified key, but the operation never fails.

return Multi bulk reply

func (*Redis) MSet added in v0.0.11

func (r *Redis) MSet(kvs ...string) (string, error)

MSet Set the the respective keys to the respective values. MSET will replace old values with new values, while {@link #msetnx(String...) MSETNX} will not perform any operation at all even if just a single key already exists.

Because of this semantic MSETNX can be used in order to set different keys representing different fields of an unique logic object in a way that ensures that either all the fields or none at all are set.

Both MSET and MSETNX are atomic operations. This means that for instance if the keys A and B are modified, another client talking to Redis can either see the changes to both A and B at once, or no modification at all. return Status code reply Basically +OK as MSET can't fail

func (*Redis) MSetNx added in v0.0.11

func (r *Redis) MSetNx(kvs ...string) (int64, error)

MSetNx Set the the respective keys to the respective values. {@link #mset(String...) MSET} will replace old values with new values, while MSETNX will not perform any operation at all even if just a single key already exists.

Because of this semantic MSETNX can be used in order to set different keys representing different fields of an unique logic object in a way that ensures that either all the fields or none at all are set.

Both MSET and MSETNX are atomic operations. This means that for instance if the keys A and B are modified, another client talking to Redis can either see the changes to both A and B at once, or no modification at all. return Integer reply, specifically: 1 if the all the keys were set 0 if no key was set (at

least one key already existed)

func (*Redis) Move

func (r *Redis) Move(key string, dbIndex int) (int64, error)

Move key from the currently selected database (see SELECT) to the specified destination database. When key already exists in the destination database, or it does not exist in the source database, it does nothing. It is possible to use MOVE as a locking primitive because of this.

Return value Integer reply, specifically:

1 if key was moved. 0 if key was not moved.

func (*Redis) Multi

func (r *Redis) Multi() (*Transaction, error)

Multi get transaction of redis client ,when use transaction mode, you need to invoke this first

func (*Redis) ObjectEncoding

func (r *Redis) ObjectEncoding(str string) (string, error)

ObjectEncoding returns the kind of internal representation used in order to store the value associated with a key.

func (*Redis) ObjectIdleTime added in v0.0.11

func (r *Redis) ObjectIdleTime(str string) (int64, error)

ObjectIdleTime returns the number of seconds since the object stored at the specified key is idle (not requested by read or write operations). While the value is returned in seconds the actual resolution of this timer is 10 seconds, but may vary in future implementations. This subcommand is available when maxmemory-policy is set to an LRU policy or noeviction.

func (*Redis) ObjectRefCount added in v0.0.11

func (r *Redis) ObjectRefCount(str string) (int64, error)

ObjectRefCount returns the number of references of the value associated with the specified key. This command is mainly useful for debugging.

func (*Redis) PExpire added in v0.0.11

func (r *Redis) PExpire(key string, milliseconds int64) (int64, error)

PExpire This command works exactly like EXPIRE but the time to live of the key is specified in milliseconds instead of seconds.

Return value Integer reply, specifically:

1 if the timeout was set. 0 if key does not exist.

func (*Redis) PExpireAt added in v0.0.11

func (r *Redis) PExpireAt(key string, millisecondsTimestamp int64) (int64, error)

PExpireAt has the same effect and semantic as EXPIREAT, but the Unix time at which the key will expire is specified in milliseconds instead of seconds.

Return value Integer reply, specifically:

1 if the timeout was set. 0 if key does not exist.

func (*Redis) PSetEx added in v0.0.11

func (r *Redis) PSetEx(key string, milliseconds int64, value string) (string, error)

PSetEx works exactly like SETEX with the sole difference that the expire time is specified in milliseconds instead of seconds.

func (*Redis) PSubscribe added in v0.0.11

func (r *Redis) PSubscribe(redisPubSub *RedisPubSub, patterns ...string) error

PSubscribe ...

func (*Redis) PTTL added in v0.0.11

func (r *Redis) PTTL(key string) (int64, error)

PTTL Like TTL this command returns the remaining time to live of a key that has an expire set, with the sole difference that TTL returns the amount of remaining time in seconds while PTTL returns it in milliseconds. In Redis 2.6 or older the command returns -1 if the key does not exist or if the key exist but has no associated expire. Starting with Redis 2.8 the return value in case of error changed: The command returns -2 if the key does not exist. The command returns -1 if the key exists but has no associated expire.

Integer reply: TTL in milliseconds, or a negative value in order to signal an error (see the description above).

func (*Redis) Persist

func (r *Redis) Persist(key string) (int64, error)

Persist Undo a {@link #expire(String, int) expire} at turning the expire key into a normal key.

return Integer reply, specifically: 1: the key is now persist. 0: the key is not persist (only

happens when key not set).

func (*Redis) PfAdd added in v0.0.11

func (r *Redis) PfAdd(key string, elements ...string) (int64, error)

PfAdd Adds all the element arguments to the HyperLogLog data structure stored at the variable name specified as first argument. Return value Integer reply, specifically:

1 if at least 1 HyperLogLog internal register was altered. 0 otherwise.

func (*Redis) PfCount added in v0.0.11

func (r *Redis) PfCount(keys ...string) (int64, error)

PfCount When called with a single key, returns the approximated cardinality computed by the HyperLogLog data structure stored at the specified variable, which is 0 if the variable does not exist. Return value Integer reply, specifically:

The approximated number of unique elements observed via PFADD.

func (*Redis) PfMerge added in v0.0.11

func (r *Redis) PfMerge(destKey string, srcKeys ...string) (string, error)

PfMerge Merge multiple HyperLogLog values into an unique value that will approximate the cardinality of the union of the observed Sets of the source HyperLogLog structures.

The computed merged HyperLogLog is set to the destination variable, which is created if does not exist (defaulting to an empty HyperLogLog).

Return value Simple string reply: The command just returns OK.

func (*Redis) Ping

func (r *Redis) Ping() (string, error)

Ping send ping command to redis server if the sever is running well,then it will return PONG.

func (*Redis) Pipelined

func (r *Redis) Pipelined() *Pipeline

Pipelined get pipeline of redis client ,when use pipeline mode, you need to invoke this first

func (*Redis) PubSubChannels added in v0.0.11

func (r *Redis) PubSubChannels(pattern string) ([]string, error)

PubSubChannels ...

func (*Redis) Publish

func (r *Redis) Publish(channel, message string) (int64, error)

Publish ...

func (*Redis) Quit

func (r *Redis) Quit() (string, error)

Quit Ask the server to close the connection. The connection is closed as soon as all pending replies have been written to the client.

Return value Simple string reply: always OK.

func (*Redis) RPop added in v0.0.11

func (r *Redis) RPop(key string) (string, error)

RPop Atomically return and remove the first (LPOP) or last (RPOP) element of the list. For example if the list contains the elements "a","b","c" RPOP will return "c" and the list will become "a","b".

If the key does not exist or the list is already empty the special value 'nil' is returned.

return Bulk reply

func (*Redis) RPopLPush added in v0.0.11

func (r *Redis) RPopLPush(srcKey, destKey string) (string, error)

RPopLPush Atomically return and remove the last (tail) element of the srcKey list, and push the element as the first (head) element of the destKey list. For example if the source list contains the elements "a","b","c" and the destination list contains the elements "foo","bar" after an RPOPLPUSH command the content of the two lists will be "a","b" and "c","foo","bar".

If the key does not exist or the list is already empty the special value 'nil' is returned. If the srcKey and destKey are the same the operation is equivalent to removing the last element from the list and pusing it as first element of the list, so it's a "list rotation" command.

return Bulk reply

func (*Redis) RPush added in v0.0.11

func (r *Redis) RPush(key string, members ...string) (int64, error)

RPush Add the string value to the head (LPUSH) or tail (RPUSH) of the list stored at key. If the key does not exist an empty list is created just before the append operation. If the key exists but is not a List an error is returned.

return Integer reply, specifically, the number of elements inside the list after the push

operation.

func (*Redis) RPushX added in v0.0.11

func (r *Redis) RPushX(key string, members ...string) (int64, error)

RPushX Inserts value at the tail of the list stored at key, only if key already exists and holds a list. In contrary to RPUSH, no operation will be performed when key does not yet exist.

Return value Integer reply: the length of the list after the push operation.

func (*Redis) RandomKey

func (r *Redis) RandomKey() (string, error)

RandomKey ...

func (*Redis) Readonly

func (r *Redis) Readonly() (string, error)

Readonly Enables read queries for a connection to a Redis Cluster replica node. Normally replica nodes will redirect clients to the authoritative master for the hash slot involved in a given command, however clients can use replicas in order to scale reads using the READONLY command.

READONLY tells a Redis Cluster replica node that the client is willing to read possibly stale data and is not interested in running write queries.

When the connection is in readonly mode, the cluster will send a redirection to the client only if the operation involves keys not served by the replica's master node. This may happen because:

The client sent a command about hash slots never served by the master of this replica. The cluster was reconfigured (for example resharded) and the replica is no longer able to serve commands for a given hash slot. Return value Simple string reply

func (*Redis) Receive added in v0.0.5

func (r *Redis) Receive() (interface{}, error)

Receive receive reply from redis

func (*Redis) Rename

func (r *Redis) Rename(oldKey, newKey string) (string, error)

Rename Atomically renames the key oldKey to newKey. If the source and destination name are the same an error is returned. If newKey already exists it is overwritten.

return Status code repy

func (*Redis) RenameNx added in v0.0.11

func (r *Redis) RenameNx(oldKey, newKey string) (int64, error)

RenameNx Rename oldKey into newKey but fails if the destination key newKey already exists.

return Integer reply, specifically: 1 if the key was renamed 0 if the target key already exist

func (*Redis) SAdd added in v0.0.11

func (r *Redis) SAdd(key string, members ...string) (int64, error)

SAdd Add the specified member to the set value stored at key. If member is already a member of the set no operation is performed. If key does not exist a new set with the specified member as sole member is created. If the key exists but does not hold a set value an error is returned.

return Integer reply, specifically: 1 if the new element was added 0 if the element was

already a member of the set

func (*Redis) SCard added in v0.0.11

func (r *Redis) SCard(key string) (int64, error)

SCard Return the set cardinality (number of elements). If the key does not exist 0 is returned, like for empty sets. return Integer reply, specifically: the cardinality (number of elements) of the set as an

integer.

func (*Redis) SDiff added in v0.0.11

func (r *Redis) SDiff(keys ...string) ([]string, error)

SDiff Return the difference between the Set stored at key1 and all the Sets key2, ..., keyN

<b>Example:</b> <pre> key1 = [x, a, b, c] key2 = [c] key3 = [a, d] SDIFF key1,key2,key3 =&gt; [x, b] </pre> Non existing keys are considered like empty sets.

return Return the members of a set resulting from the difference between the first set

provided and all the successive sets.

func (*Redis) SDiffStore added in v0.0.11

func (r *Redis) SDiffStore(destKey string, srcKeys ...string) (int64, error)

SDiffStore This command works exactly like {@link #sdiff(String...) SDIFF} but instead of being returned the resulting set is stored in destKey. return Status code reply

func (*Redis) SInter added in v0.0.11

func (r *Redis) SInter(keys ...string) ([]string, error)

SInter Return the members of a set resulting from the intersection of all the sets hold at the specified keys. Like in {@link #lrange(String, long, long) LRANGE} the result is sent to the client as a multi-bulk reply (see the protocol specification for more information). If just a single key is specified, then this command produces the same result as {@link #smembers(String) SMEMBERS}. Actually SMEMBERS is just syntax sugar for SINTER.

Non existing keys are considered like empty sets, so if one of the keys is missing an empty set is returned (since the intersection with an empty set always is an empty set).

return Multi bulk reply, specifically the list of common elements.

func (*Redis) SInterStore added in v0.0.11

func (r *Redis) SInterStore(destKey string, srcKeys ...string) (int64, error)

SInterStore This commnad works exactly like {@link #sinter(String...) SINTER} but instead of being returned the resulting set is sotred as destKey.

return Status code reply

func (*Redis) SIsMember added in v0.0.11

func (r *Redis) SIsMember(key, member string) (bool, error)

SIsMember Return 1 if member is a member of the set stored at key, otherwise 0 is returned.

return Integer reply, specifically: 1 if the element is a member of the set 0 if the element

is not a member of the set OR if the key does not exist

func (*Redis) SMembers added in v0.0.11

func (r *Redis) SMembers(key string) ([]string, error)

SMembers Return all the members (elements) of the set value stored at key.

return Multi bulk reply

func (*Redis) SMove added in v0.0.11

func (r *Redis) SMove(srcKey, destKey, member string) (int64, error)

SMove Move the specifided member from the set at srcKey to the set at destKey. This operation is atomic, in every given moment the element will appear to be in the source or destination set for accessing clients.

If the source set does not exist or does not contain the specified element no operation is performed and zero is returned, otherwise the element is removed from the source set and added to the destination set. On success one is returned, even if the element was already present in the destination set.

An error is raised if the source or destination keys contain a non Set value.

return Integer reply, specifically: 1 if the element was moved 0 if the element was not found

on the first set and no operation was performed

func (*Redis) SPop added in v0.0.11

func (r *Redis) SPop(key string) (string, error)

SPop Remove a random element from a Set returning it as return value. If the Set is empty or the key does not exist, a nil object is returned.

The {@link #srandmember(String)} command does a similar work but the returned element is not removed from the Set.

return Bulk reply

func (*Redis) SPopBatch added in v0.0.11

func (r *Redis) SPopBatch(key string, count int64) ([]string, error)

SPopBatch remove multi random element see SPop(key string)

func (*Redis) SRandMember added in v0.0.11

func (r *Redis) SRandMember(key string) (string, error)

SRandMember Return a random element from a Set, without removing the element. If the Set is empty or the key does not exist, a nil object is returned.

The SPOP command does a similar work but the returned element is popped (removed) from the Set.

return Bulk reply

func (*Redis) SRandMemberBatch added in v0.0.11

func (r *Redis) SRandMemberBatch(key string, count int) ([]string, error)

SRandMemberBatch see SRandMember(key string)

func (*Redis) SRem added in v0.0.11

func (r *Redis) SRem(key string, members ...string) (int64, error)

SRem Remove the specified member from the set value stored at key. If member was not a member of the set no operation is performed. If key does not hold a set value an error is returned.

return Integer reply, specifically: 1 if the new element was removed 0 if the new element was

not a member of the set

func (*Redis) SScan added in v0.0.11

func (r *Redis) SScan(key, cursor string, params ...*ScanParams) (*ScanResult, error)

SScan scan keys of set,see scan

func (*Redis) SUnion added in v0.0.11

func (r *Redis) SUnion(keys ...string) ([]string, error)

SUnion Return the members of a set resulting from the union of all the sets hold at the specified keys. Like in {@link #lrange(String, long, long) LRANGE} the result is sent to the client as a multi-bulk reply (see the protocol specification for more information). If just a single key is specified, then this command produces the same result as {@link #smembers(String) SMEMBERS}.

Non existing keys are considered like empty sets.

return Multi bulk reply, specifically the list of common elements.

func (*Redis) SUnionStore added in v0.0.11

func (r *Redis) SUnionStore(destKey string, srcKeys ...string) (int64, error)

SUnionStore This command works exactly like {@link #sunion(String...) SUNION} but instead of being returned the resulting set is stored as destKey. Any existing value in destKey will be over-written.

return Status code reply

func (*Redis) Save

func (r *Redis) Save() (string, error)

Save ...

func (*Redis) Scan

func (r *Redis) Scan(cursor string, params ...*ScanParams) (*ScanResult, error)

Scan ...

func (*Redis) ScriptExists

func (r *Redis) ScriptExists(sha1 ...string) ([]bool, error)

ScriptExists Returns information about the existence of the scripts in the script cache. Return value Array reply The command returns an array of integers that correspond to the specified SHA1 digest arguments. For every corresponding SHA1 digest of a script that actually exists in the script cache, an 1 is returned, otherwise 0 is returned.

func (*Redis) ScriptLoad

func (r *Redis) ScriptLoad(script string) (string, error)

ScriptLoad Load a script into the scripts cache, without executing it. After the specified command is loaded into the script cache it will be callable using EVALSHA with the correct SHA1 digest of the script, exactly like after the first successful invocation of EVAL. Return value Bulk string reply This command returns the SHA1 digest of the script added into the script cache.

func (*Redis) Select

func (r *Redis) Select(index int) (string, error)

Select send select command to change current db,normally redis server has 16 db [0,15]

func (*Redis) Send added in v0.0.5

func (r *Redis) Send(command protocolCommand, args ...[]byte) error

Send send command to redis

func (*Redis) SendByStr added in v0.0.5

func (r *Redis) SendByStr(command string, args ...[]byte) error

SendByStr send command to redis

func (*Redis) SentinelFailOver added in v0.0.11

func (r *Redis) SentinelFailOver(masterName string) (string, error)

SentinelFailOver ...

func (*Redis) SentinelGetMasterAddrByName

func (r *Redis) SentinelGetMasterAddrByName(masterName string) ([]string, error)

SentinelGetMasterAddrByName example: redis 127.0.0.1:26381&gt; sentinel get-master-addr-by-name mymaster 1) "127.0.0.1" 2) "6379" return two elements list of strings : host and port.

func (*Redis) SentinelMasters

func (r *Redis) SentinelMasters() ([]map[string]string, error)

SentinelMasters example: redis 127.0.0.1:26381&gt; sentinel masters 1) 1) "name"

  1. "mymaster"
  2. "ip"
  3. "127.0.0.1"
  4. "port"
  5. "6379"
  6. "runid"
  7. "93d4d4e6e9c06d0eea36e27f31924ac26576081d"
  8. "flags"
  9. "master"
  10. "pending-commands"
  11. "0"
  12. "last-ok-ping-reply"
  13. "423"
  14. "last-ping-reply"
  15. "423"
  16. "info-refresh"
  17. "6107"
  18. "num-slaves"
  19. "1"
  20. "num-other-sentinels"
  21. "2"
  22. "quorum"
  23. "2"

func (*Redis) SentinelMonitor

func (r *Redis) SentinelMonitor(masterName, ip string, port, quorum int) (string, error)

SentinelMonitor ...

func (*Redis) SentinelRemove

func (r *Redis) SentinelRemove(masterName string) (string, error)

SentinelRemove ...

func (*Redis) SentinelReset

func (r *Redis) SentinelReset(pattern string) (int64, error)

SentinelReset example: redis 127.0.0.1:26381&gt; sentinel reset mymaster (integer) 1

func (*Redis) SentinelSet

func (r *Redis) SentinelSet(masterName string, parameterMap map[string]string) (string, error)

SentinelSet ...

func (*Redis) SentinelSlaves

func (r *Redis) SentinelSlaves(masterName string) ([]map[string]string, error)

SentinelSlaves example: redis 127.0.0.1:26381&gt; sentinel slaves mymaster 1) 1) "name"

  1. "127.0.0.1:6380"
  2. "ip"
  3. "127.0.0.1"
  4. "port"
  5. "6380"
  6. "runid"
  7. "d7f6c0ca7572df9d2f33713df0dbf8c72da7c039"
  8. "flags"
  9. "slave"
  10. "pending-commands"
  11. "0"
  12. "last-ok-ping-reply"
  13. "47"
  14. "last-ping-reply"
  15. "47"
  16. "info-refresh"
  17. "657"
  18. "master-link-down-time"
  19. "0"
  20. "master-link-status"
  21. "ok"
  22. "master-host"
  23. "localhost"
  24. "master-port"
  25. "6379"
  26. "slave-priority"
  27. "100"

func (*Redis) Set

func (r *Redis) Set(key, value string) (string, error)

Set the string value as value of the key. The string can't be longer than 1073741824 bytes (1 GB) return Status code reply

func (*Redis) SetBit added in v0.0.11

func (r *Redis) SetBit(key string, offset int64, value string) (bool, error)

SetBit Sets or clears the bit at offset in the string value stored at key.

The bit is either set or cleared depending on value, which can be either 0 or 1. When key does not exist, a new string value is created. The string is grown to make sure it can hold a bit at offset. The offset argument is required to be greater than or equal to 0, and smaller than 232 (this limits bitmaps to 512MB). When the string at key is grown, added bits are set to 0.

Warning: When setting the last possible bit (offset equal to 232 -1) and the string value stored at key does not yet hold a string value, or holds a small string value, Redis needs to allocate all intermediate memory which can block the server for some time. On a 2010 MacBook Pro, setting bit number 232 -1 (512MB allocation) takes ~300ms, setting bit number 230 -1 (128MB allocation) takes ~80ms, setting bit number 228 -1 (32MB allocation) takes ~30ms and setting bit number 226 -1 (8MB allocation) takes ~8ms. Note that once this first allocation is done, subsequent calls to SETBIT for the same key will not have the allocation overhead.

Return value Integer reply: the original bit value stored at offset.

func (*Redis) SetBitWithBool added in v0.0.11

func (r *Redis) SetBitWithBool(key string, offset int64, value bool) (bool, error)

SetBitWithBool see SetBit(key string, offset int64, value string)

func (*Redis) SetEx added in v0.0.11

func (r *Redis) SetEx(key string, seconds int, value string) (string, error)

SetEx The command is exactly equivalent to the following group of commands: {@link #set(String, String) SET} + {@link #expire(String, int) EXPIRE}. The operation is atomic.

return Status code reply

func (*Redis) SetNx added in v0.0.11

func (r *Redis) SetNx(key, value string) (int64, error)

SetNx SETNX works exactly like {@link #set(String, String) SET} with the only difference that if the key already exists no operation is performed. SETNX actually means "SET if Not eXists".

return Integer reply, specifically: 1 if the key was set 0 if the key was not set

func (*Redis) SetRange added in v0.0.11

func (r *Redis) SetRange(key string, offset int64, value string) (int64, error)

SetRange Overwrites part of the string stored at key, starting at the specified offset, for the entire length of value. If the offset is larger than the current length of the string at key, the string is padded with zero-bytes to make offset fit. Non-existing keys are considered as empty strings, so this command will make sure it holds a string large enough to be able to set value at offset. Note that the maximum offset that you can set is 229 -1 (536870911), as Redis Strings are limited to 512 megabytes. If you need to grow beyond this size, you can use multiple keys.

Warning: When setting the last possible byte and the string value stored at key does not yet hold a string value, or holds a small string value, Redis needs to allocate all intermediate memory which can block the server for some time. On a 2010 MacBook Pro, setting byte number 536870911 (512MB allocation) takes ~300ms, setting byte number 134217728 (128MB allocation) takes ~80ms, setting bit number 33554432 (32MB allocation) takes ~30ms and setting bit number 8388608 (8MB allocation) takes ~8ms. Note that once this first allocation is done, subsequent calls to SETRANGE for the same key will not have the allocation overhead.

Return value Integer reply: the length of the string after it was modified by the command.

func (*Redis) SetWithParams

func (r *Redis) SetWithParams(key, value, nxxx string) (string, error)

SetWithParams see SetWithParamsAndTime(key, value, nxxx, expx string, time int64)

func (*Redis) SetWithParamsAndTime

func (r *Redis) SetWithParamsAndTime(key, value, nxxx, expx string, time int64) (string, error)

SetWithParamsAndTime Set the string value as value of the key. The string can't be longer than 1073741824 bytes (1 GB). param nxxx NX|XX, NX -- Only set the key if it does not already exist. XX -- Only set the key if it already exist. param expx EX|PX, expire time units: EX = seconds; PX = milliseconds param time expire time in the units of <code>expx</code> return Status code reply

func (*Redis) Shutdown

func (r *Redis) Shutdown() (string, error)

Shutdown ...

func (*Redis) SlaveOf added in v0.0.11

func (r *Redis) SlaveOf(host string, port int) (string, error)

SlaveOf ...

func (*Redis) SlaveOfNoOne added in v0.0.11

func (r *Redis) SlaveOfNoOne() (string, error)

SlaveOfNoOne ...

func (*Redis) SlowLogGet added in v0.0.11

func (r *Redis) SlowLogGet(entries ...int64) ([]SlowLog, error)

SlowLogGet The Redis Slow Log is a system to log queries that exceeded a specified execution time. The execution time does not include I/O operations like talking with the client, sending the reply and so forth, but just the time needed to actually execute the command (this is the only stage of command execution where the thread is blocked and can not serve other requests in the meantime).

func (*Redis) SlowLogLen added in v0.0.11

func (r *Redis) SlowLogLen() (int64, error)

SlowLogLen it is possible to get just the length of the slow log using the command SLOWLOG LEN.

func (*Redis) SlowLogReset added in v0.0.11

func (r *Redis) SlowLogReset() (string, error)

SlowLogReset You can reset the slow log using the SLOWLOG RESET command. Once deleted the information is lost forever.

func (*Redis) Sort

func (r *Redis) Sort(key string, params ...*SortParams) ([]string, error)

Sort a Set or a List.

Sort the elements contained in the List, Set, or Sorted Set value at key. By default sorting is numeric with elements being compared as double precision floating point numbers. This is the simplest form of SORT. return Assuming the Set/List at key contains a list of numbers, the return value will be the

list of numbers ordered from the smallest to the biggest number.

func (*Redis) SortStore added in v0.0.10

func (r *Redis) SortStore(srcKey, destKey string, params ...*SortParams) (int64, error)

SortStore sort old sets or list,then store the result to a new set or list

func (*Redis) StrLen added in v0.0.11

func (r *Redis) StrLen(key string) (int64, error)

StrLen Returns the length of the string value stored at key. An error is returned when key holds a non-string value. Return value Integer reply: the length of the string at key, or 0 when key does not exist.

func (*Redis) SubStr added in v0.0.11

func (r *Redis) SubStr(key string, start, end int) (string, error)

SubStr Return a subset of the string from offset start to offset end (both offsets are inclusive). Negative offsets can be used in order to provide an offset starting from the end of the string. So -1 means the last char, -2 the penultimate and so forth.

The function handles out of range requests without raising an error, but just limiting the resulting range to the actual length of the string.

Time complexity: O(start+n) (with start being the start index and n the total length of the requested range). Note that the lookup part of this command is O(1) so for small strings this is actually an O(1) command.

return Bulk reply

func (*Redis) Subscribe

func (r *Redis) Subscribe(redisPubSub *RedisPubSub, channels ...string) error

Subscribe ...

func (*Redis) TTL added in v0.0.11

func (r *Redis) TTL(key string) (int64, error)

TTL The TTL command returns the remaining time to live in seconds of a key that has an {@link #expire(String, int) EXPIRE} set. This introspection capability allows a Redis client to check how many seconds a given key will continue to be part of the dataset. return Integer reply, returns the remaining time to live in seconds of a key that has an

EXPIRE. In Redis 2.6 or older, if the Key does not exists or does not have an
associated expire, -1 is returned. In Redis 2.8 or newer, if the Key does not have an
associated expire, -1 is returned or if the Key does not exists, -2 is returned.

func (*Redis) Type

func (r *Redis) Type(key string) (string, error)

Type Return the type of the value stored at key in form of a string. The type can be one of "none", "string", "list", "set". "none" is returned if the key does not exist. Time complexity: O(1) param key return Status code reply, specifically: "none" if the key does not exist "string" if the key

contains a String value "list" if the key contains a List value "set" if the key
contains a Set value "zset" if the key contains a Sorted Set value "hash" if the key
contains a Hash value

func (*Redis) Unwatch

func (r *Redis) Unwatch() (string, error)

Unwatch cancel all watches for keys always return OK

func (*Redis) WaitReplicas

func (r *Redis) WaitReplicas(replicas int, timeout int64) (int64, error)

WaitReplicas Synchronous replication of Redis as described here: http://antirez.com/news/66 Since Java Object class has implemented "wait" method, we cannot use it, so I had to change the name of the method. Sorry :S

func (*Redis) Watch

func (r *Redis) Watch(keys ...string) (string, error)

Watch Marks the given keys to be watched for conditional execution of a transaction.

Return value Simple string reply: always OK.

func (*Redis) ZAdd added in v0.0.11

func (r *Redis) ZAdd(key string, score float64, member string, params ...*ZAddParams) (int64, error)

ZAdd Add the specified member having the specifeid score to the sorted set stored at key. If member is already a member of the sorted set the score is updated, and the element reinserted in the right position to ensure sorting. If key does not exist a new sorted set with the specified member as sole member is crated. If the key exists but does not hold a sorted set value an error is returned.

The score value can be the string representation of a double precision floating point number.

return Integer reply, specifically: 1 if the new element was added 0 if the element was

already a member of the sorted set and the score was updated

func (*Redis) ZAddByMap added in v0.0.11

func (r *Redis) ZAddByMap(key string, scoreMembers map[string]float64, params ...*ZAddParams) (int64, error)

ZAddByMap see ZAdd(key string, score float64, member string, mparams ...ZAddParams)

func (*Redis) ZCard added in v0.0.11

func (r *Redis) ZCard(key string) (int64, error)

ZCard Return the sorted set cardinality (number of elements). If the key does not exist 0 is returned, like for empty sorted sets.

return the cardinality (number of elements) of the set as an integer.

func (*Redis) ZCount added in v0.0.11

func (r *Redis) ZCount(key string, min, max float64) (int64, error)

ZCount Returns the number of elements in the sorted set at key with a score between min and max. The min and max arguments have the same semantic as described for ZRANGEBYSCORE. Note: the command has a complexity of just O(log(N)) because it uses elements ranks (see ZRANK) to get an idea of the range. Because of this there is no need to do a work proportional to the size of the range.

Return value Integer reply: the number of elements in the specified score range.

func (*Redis) ZIncrBy added in v0.0.11

func (r *Redis) ZIncrBy(key string, increment float64, member string, params ...*ZAddParams) (float64, error)

ZIncrBy If member already exists in the sorted set adds the increment to its score and updates the position of the element in the sorted set accordingly. If member does not already exist in the sorted set it is added with increment as score (that is, like if the previous score was virtually zero). If key does not exist a new sorted set with the specified member as sole member is crated. If the key exists but does not hold a sorted set value an error is returned.

The score value can be the string representation of a double precision floating point number. It's possible to provide a negative value to perform a decrement.

For an introduction to sorted sets check the Introduction to Redis data types page.

return The new score

func (*Redis) ZInterStore added in v0.0.11

func (r *Redis) ZInterStore(destKey string, srcKeys ...string) (int64, error)

ZInterStore Creates a union or intersection of N sorted sets given by keys k1 through kN, and stores it at destKey. It is mandatory to provide the number of input keys N, before passing the input keys and the other (optional) arguments.

As the terms imply, the {@link #zinterstore(String, String...) ZINTERSTORE} command requires an element to be present in each of the given inputs to be inserted in the result. The {@link #zunionstore(String, String...) ZUNIONSTORE} command inserts all elements across all inputs.

Using the WEIGHTS option, it is possible to add weight to each input sorted set. This means that the score of each element in the sorted set is first multiplied by this weight before being passed to the aggregation. When this option is not given, all weights default to 1.

With the AGGREGATE option, it's possible to specify how the results of the union or intersection are aggregated. This option defaults to SUM, where the score of an element is summed across the inputs where it exists. When this option is set to be either MIN or MAX, the resulting set will contain the minimum or maximum score of an element across the inputs where it exists.

return Integer reply, specifically the number of elements in the sorted set at destKey

func (*Redis) ZInterStoreWithParams added in v0.0.11

func (r *Redis) ZInterStoreWithParams(destKey string, params *ZParams, srcKeys ...string) (int64, error)

ZInterStoreWithParams ...

func (*Redis) ZLexCount added in v0.0.11

func (r *Redis) ZLexCount(key, min, max string) (int64, error)

ZLexCount When all the elements in a sorted set are inserted with the same score, in order to force lexicographical ordering, this command returns the number of elements in the sorted set at key with a value between min and max.

The min and max arguments have the same meaning as described for ZRANGEBYLEX.

Return value Integer reply: the number of elements in the specified score range.

func (*Redis) ZRange added in v0.0.11

func (r *Redis) ZRange(key string, start, stop int64) ([]string, error)

ZRange Returns the specified range of elements in the sorted set stored at key. The elements are considered to be ordered from the lowest to the highest score. Lexicographical order is used for elements with equal score. See ZREVRANGE when you need the elements ordered from highest to lowest score (and descending lexicographical order for elements with equal score). Both start and stop are zero-based indexes, where 0 is the first element, 1 is the next element and so on. They can also be negative numbers indicating offsets from the end of the sorted set, with -1 being the last element of the sorted set, -2 the penultimate element and so on. start and stop are inclusive ranges, so for example ZRANGE myzset 0 1 will return both the first and the second element of the sorted set. Out of range indexes will not produce an error. If start is larger than the largest index in the sorted set, or start > stop, an empty list is returned. If stop is larger than the end of the sorted set Redis will treat it like it is the last element of the sorted set. It is possible to pass the WITHSCORES option in order to return the scores of the elements together with the elements. The returned list will contain value1,score1,...,valueN,scoreN instead of value1,...,valueN. Client libraries are free to return a more appropriate data type (suggestion: an array with (value, score) arrays/tuples). Return value Array reply: list of elements in the specified range (optionally with their scores, in case the WITHSCORES option is given).

func (*Redis) ZRangeByLex added in v0.0.11

func (r *Redis) ZRangeByLex(key, min, max string) ([]string, error)

ZRangeByLex When all the elements in a sorted set are inserted with the same score, in order to force lexicographical ordering, this command returns all the elements in the sorted set at key with a value between min and max.

If the elements in the sorted set have different scores, the returned elements are unspecified.

The elements are considered to be ordered from lower to higher strings as compared byte-by-byte using the memcmp() C function. Longer strings are considered greater than shorter strings if the common part is identical.

The optional LIMIT argument can be used to only get a range of the matching elements (similar to SELECT LIMIT offset, count in SQL). A negative count returns all elements from the offset. Keep in mind that if offset is large, the sorted set needs to be traversed for offset elements before getting to the elements to return, which can add up to O(N) time complexity. Return value Array reply: list of elements in the specified score range.

func (*Redis) ZRangeByLexBatch added in v0.0.11

func (r *Redis) ZRangeByLexBatch(key, min, max string, offset, count int) ([]string, error)

ZRangeByLexBatch see ZRangeByLex()

func (*Redis) ZRangeByScore added in v0.0.11

func (r *Redis) ZRangeByScore(key string, min, max float64) ([]string, error)

ZRangeByScore Return the all the elements in the sorted set at key with a score between min and max (including elements with score equal to min or max).

The elements having the same score are returned sorted lexicographically as ASCII strings (this follows from a property of Redis sorted sets and does not involve further computation).

Using the optional {@link #zrangeByScore(String, double, double, int, int) LIMIT} it's possible to get only a range of the matching elements in an SQL-alike way. Note that if offset is large the commands needs to traverse the list for offset elements and this adds up to the O(M) figure.

The {@link #zcount(String, double, double) ZCOUNT} command is similar to {@link #zrangeByScore(String, double, double) ZRANGEBYSCORE} but instead of returning the actual elements in the specified interval, it just returns the number of matching elements.

<b>Exclusive intervals and infinity</b>

min and max can be -inf and +inf, so that you are not required to know what's the greatest or smallest element in order to take, for instance, elements "up to a given value".

Also while the interval is for default closed (inclusive) it's possible to specify open intervals prefixing the score with a "(" character, so for instance:

{@code ZRANGEBYSCORE zset (1.3 5}

Will return all the values with score &gt; 1.3 and &lt;= 5, while for instance:

{@code ZRANGEBYSCORE zset (5 (10}

Will return all the values with score &gt; 5 and &lt; 10 (5 and 10 excluded).

param min a double or Double.MIN_VALUE for "-inf" param max a double or Double.MAX_VALUE for "+inf" return Multi bulk reply specifically a list of elements in the specified score range.

func (*Redis) ZRangeByScoreBatch added in v0.0.11

func (r *Redis) ZRangeByScoreBatch(key string, min, max float64, offset, count int) ([]string, error)

ZRangeByScoreBatch see ZRange()

func (*Redis) ZRangeByScoreWithScores added in v0.0.11

func (r *Redis) ZRangeByScoreWithScores(key string, min, max float64) ([]Tuple, error)

ZRangeByScoreWithScores Return the all the elements in the sorted set at key with a score between min and max (including elements with score equal to min or max).

The elements having the same score are returned sorted lexicographically as ASCII strings (this follows from a property of Redis sorted sets and does not involve further computation).

Using the optional {@link #zrangeByScore(String, double, double, int, int) LIMIT} it's possible to get only a range of the matching elements in an SQL-alike way. Note that if offset is large the commands needs to traverse the list for offset elements and this adds up to the O(M) figure.

The {@link #zcount(String, double, double) ZCOUNT} command is similar to {@link #zrangeByScore(String, double, double) ZRANGEBYSCORE} but instead of returning the actual elements in the specified interval, it just returns the number of matching elements.

<b>Exclusive intervals and infinity</b>

min and max can be -inf and +inf, so that you are not required to know what's the greatest or smallest element in order to take, for instance, elements "up to a given value".

Also while the interval is for default closed (inclusive) it's possible to specify open intervals prefixing the score with a "(" character, so for instance:

{@code ZRANGEBYSCORE zset (1.3 5}

Will return all the values with score &gt; 1.3 and &lt;= 5, while for instance:

{@code ZRANGEBYSCORE zset (5 (10}

Will return all the values with score &gt; 5 and &lt; 10 (5 and 10 excluded).

return Multi bulk reply specifically a list of elements in the specified score range.

func (*Redis) ZRangeByScoreWithScoresBatch added in v0.0.11

func (r *Redis) ZRangeByScoreWithScoresBatch(key string, min, max float64, offset, count int) ([]Tuple, error)

ZRangeByScoreWithScoresBatch see ZRange()

func (*Redis) ZRangeWithScores added in v0.0.11

func (r *Redis) ZRangeWithScores(key string, start, end int64) ([]Tuple, error)

ZRangeWithScores see ZRange()

func (*Redis) ZRank added in v0.0.11

func (r *Redis) ZRank(key, member string) (int64, error)

ZRank Return the rank (or index) or member in the sorted set at key, with scores being ordered from low to high.

When the given member does not exist in the sorted set, the special value 'nil' is returned. The returned rank (or index) of the member is 0-based for both commands.

return Integer reply or a nil bulk reply, specifically: the rank of the element as an integer

reply if the element exists. A nil bulk reply if there is no such element.

func (*Redis) ZRem added in v0.0.11

func (r *Redis) ZRem(key string, members ...string) (int64, error)

ZRem Remove the specified member from the sorted set value stored at key. If member was not a member of the set no operation is performed. If key does not not hold a set value an error is returned.

return Integer reply, specifically: 1 if the new element was removed 0 if the new element was

not a member of the set

func (*Redis) ZRemRangeByLex added in v0.0.11

func (r *Redis) ZRemRangeByLex(key, min, max string) (int64, error)

ZRemRangeByLex When all the elements in a sorted set are inserted with the same score, in order to force lexicographical ordering, this command removes all elements in the sorted set stored at key between the lexicographical range specified by min and max.

The meaning of min and max are the same of the ZRANGEBYLEX command. Similarly, this command actually returns the same elements that ZRANGEBYLEX would return if called with the same min and max arguments.

Return value Integer reply: the number of elements removed.

func (*Redis) ZRemRangeByRank added in v0.0.11

func (r *Redis) ZRemRangeByRank(key string, start, stop int64) (int64, error)

ZRemRangeByRank Remove all elements in the sorted set at key with rank between start and end. Start and end are 0-based with rank 0 being the element with the lowest score. Both start and end can be negative numbers, where they indicate offsets starting at the element with the highest rank. For example: -1 is the element with the highest score, -2 the element with the second highest score and so forth.

func (*Redis) ZRemRangeByScore added in v0.0.11

func (r *Redis) ZRemRangeByScore(key string, min, max float64) (int64, error)

ZRemRangeByScore Removes all elements in the sorted set stored at key with a score between min and max (inclusive).

Since version 2.1.6, min and max can be exclusive, following the syntax of ZRANGEBYSCORE.

Return value Integer reply: the number of elements removed.

func (*Redis) ZRevRange added in v0.0.11

func (r *Redis) ZRevRange(key string, start, stop int64) ([]string, error)

ZRevRange Returns the specified range of elements in the sorted set stored at key. The elements are considered to be ordered from the highest to the lowest score. Descending lexicographical order is used for elements with equal score. Apart from the reversed ordering, ZREVRANGE is similar to ZRANGE. Return value Array reply: list of elements in the specified range (optionally with their scores).

func (*Redis) ZRevRangeByLex added in v0.0.11

func (r *Redis) ZRevRangeByLex(key, max, min string) ([]string, error)

ZRevRangeByLex When all the elements in a sorted set are inserted with the same score, in order to force lexicographical ordering, this command returns all the elements in the sorted set at key with a value between max and min.

Apart from the reversed ordering, ZREVRANGEBYLEX is similar to ZRANGEBYLEX.

Return value Array reply: list of elements in the specified score range.

func (*Redis) ZRevRangeByLexBatch added in v0.0.11

func (r *Redis) ZRevRangeByLexBatch(key, max, min string, offset, count int) ([]string, error)

ZRevRangeByLexBatch see ZRevRangeByLex()

func (*Redis) ZRevRangeByScore added in v0.0.11

func (r *Redis) ZRevRangeByScore(key string, max, min float64) ([]string, error)

ZRevRangeByScore Returns all the elements in the sorted set at key with a score between max and min (including elements with score equal to max or min). In contrary to the default ordering of sorted sets, for this command the elements are considered to be ordered from high to low scores. The elements having the same score are returned in reverse lexicographical order. Apart from the reversed ordering, ZREVRANGEBYSCORE is similar to ZRANGEBYSCORE.

Return value Array reply: list of elements in the specified score range (optionally with their scores).

func (*Redis) ZRevRangeByScoreWithScores added in v0.0.11

func (r *Redis) ZRevRangeByScoreWithScores(key string, max, min float64) ([]Tuple, error)

ZRevRangeByScoreWithScores see ZRevRangeByScore(key, max, min string)

func (*Redis) ZRevRangeByScoreWithScoresBatch added in v0.0.11

func (r *Redis) ZRevRangeByScoreWithScoresBatch(key string, max, min float64, offset, count int) ([]Tuple, error)

ZRevRangeByScoreWithScoresBatch see ZRevRange()

func (*Redis) ZRevRangeWithScores added in v0.0.11

func (r *Redis) ZRevRangeWithScores(key string, start, end int64) ([]Tuple, error)

ZRevRangeWithScores see ZRevRange()

func (*Redis) ZRevRank added in v0.0.11

func (r *Redis) ZRevRank(key, member string) (int64, error)

ZRevRank Return the rank (or index) or member in the sorted set at key, with scores being ordered from high to low.

When the given member does not exist in the sorted set, the special value 'nil' is returned. The returned rank (or index) of the member is 0-based for both commands.

return Integer reply or a nil bulk reply, specifically: the rank of the element as an integer

reply if the element exists. A nil bulk reply if there is no such element.

func (*Redis) ZScan added in v0.0.11

func (r *Redis) ZScan(key, cursor string, params ...*ScanParams) (*ScanResult, error)

ZScan scan keys of zset,see scan

func (*Redis) ZScore added in v0.0.11

func (r *Redis) ZScore(key, member string) (float64, error)

ZScore Return the score of the specified element of the sorted set at key. If the specified element does not exist in the sorted set, or the key does not exist at all, a special 'nil' value is returned.

return the score

func (*Redis) ZUnionStore added in v0.0.11

func (r *Redis) ZUnionStore(destKey string, srcKeys ...string) (int64, error)

ZUnionStore Creates a union or intersection of N sorted sets given by keys k1 through kN, and stores it at destKey. It is mandatory to provide the number of input keys N, before passing the input keys and the other (optional) arguments.

As the terms imply, the {@link #zinterstore(String, String...) ZINTERSTORE} command requires an element to be present in each of the given inputs to be inserted in the result. The {@link #zunionstore(String, String...) ZUNIONSTORE} command inserts all elements across all inputs.

Using the WEIGHTS option, it is possible to add weight to each input sorted set. This means that the score of each element in the sorted set is first multiplied by this weight before being passed to the aggregation. When this option is not given, all weights default to 1.

With the AGGREGATE option, it's possible to specify how the results of the union or intersection are aggregated. This option defaults to SUM, where the score of an element is summed across the inputs where it exists. When this option is set to be either MIN or MAX, the resulting set will contain the minimum or maximum score of an element across the inputs where it exists.

return Integer reply, specifically the number of elements in the sorted set at destKey

func (*Redis) ZUnionStoreWithParams added in v0.0.11

func (r *Redis) ZUnionStoreWithParams(destKey string, params *ZParams, srcKeys ...string) (int64, error)

ZUnionStoreWithParams ...

type RedisCluster

type RedisCluster struct {
	MaxAttempts int
	// contains filtered or unexported fields
}

RedisCluster redis cluster tool

func NewRedisCluster

func NewRedisCluster(option *ClusterOption) *RedisCluster

NewRedisCluster constructor

func (*RedisCluster) Append

func (r *RedisCluster) Append(key, value string) (int64, error)

Append see redis command

func (*RedisCluster) BLPop added in v0.0.11

func (r *RedisCluster) BLPop(args ...string) ([]string, error)

BLPop see comment in redis.go

func (*RedisCluster) BLPopTimeout added in v0.0.11

func (r *RedisCluster) BLPopTimeout(timeout int, keys ...string) ([]string, error)

BLPopTimeout see comment in redis.go

func (*RedisCluster) BRPop added in v0.0.11

func (r *RedisCluster) BRPop(args ...string) ([]string, error)

BRPop see comment in redis.go

func (*RedisCluster) BRPopLPush added in v0.0.11

func (r *RedisCluster) BRPopLPush(source, destination string, timeout int) (string, error)

BRPopLPush see redis command

func (*RedisCluster) BRPopTimeout added in v0.0.11

func (r *RedisCluster) BRPopTimeout(timeout int, keys ...string) ([]string, error)

BRPopTimeout see comment in redis.go

func (*RedisCluster) BitCount added in v0.0.11

func (r *RedisCluster) BitCount(key string) (int64, error)

BitCount see comment in redis.go

func (*RedisCluster) BitCountRange added in v0.0.11

func (r *RedisCluster) BitCountRange(key string, start int64, end int64) (int64, error)

BitCountRange see comment in redis.go

func (*RedisCluster) BitField added in v0.0.11

func (r *RedisCluster) BitField(key string, arguments ...string) ([]int64, error)

BitField see comment in redis.go

func (*RedisCluster) BitOp added in v0.0.11

func (r *RedisCluster) BitOp(op BitOP, destKey string, srcKeys ...string) (int64, error)

BitOp see redis command

func (*RedisCluster) BitPos added in v0.0.11

func (r *RedisCluster) BitPos(key string, value bool, params ...*BitPosParams) (int64, error)

BitPos see comment in redis.go

func (*RedisCluster) Decr

func (r *RedisCluster) Decr(key string) (int64, error)

Decr see redis command

func (*RedisCluster) DecrBy

func (r *RedisCluster) DecrBy(key string, decrement int64) (int64, error)

DecrBy see redis command

func (*RedisCluster) Del

func (r *RedisCluster) Del(keys ...string) (int64, error)

Del delete one or more keys return the number of deleted keys

func (*RedisCluster) Echo

func (r *RedisCluster) Echo(str string) (string, error)

Echo see comment in redis.go

func (*RedisCluster) Eval

func (r *RedisCluster) Eval(script string, keyCount int, params ...string) (interface{}, error)

Eval see redis command

func (*RedisCluster) EvalSha added in v0.0.11

func (r *RedisCluster) EvalSha(sha1 string, keyCount int, params ...string) (interface{}, error)

EvalSha see redis command

func (*RedisCluster) Exists

func (r *RedisCluster) Exists(keys ...string) (int64, error)

Exists see comment in redis.go

func (*RedisCluster) Expire

func (r *RedisCluster) Expire(key string, seconds int) (int64, error)

Expire see redis command

func (*RedisCluster) ExpireAt

func (r *RedisCluster) ExpireAt(key string, unixtime int64) (int64, error)

ExpireAt see redis command

func (*RedisCluster) GeoAdd added in v0.0.11

func (r *RedisCluster) GeoAdd(key string, longitude, latitude float64, member string) (int64, error)

GeoAdd see comment in redis.go

func (*RedisCluster) GeoAddByMap added in v0.0.11

func (r *RedisCluster) GeoAddByMap(key string, memberCoordinateMap map[string]GeoCoordinate) (int64, error)

GeoAddByMap see comment in redis.go

func (*RedisCluster) GeoDist added in v0.0.11

func (r *RedisCluster) GeoDist(key string, member1, member2 string, unit ...*GeoUnit) (float64, error)

GeoDist see comment in redis.go

func (*RedisCluster) GeoHash added in v0.0.11

func (r *RedisCluster) GeoHash(key string, members ...string) ([]string, error)

GeoHash see comment in redis.go

func (*RedisCluster) GeoPos added in v0.0.11

func (r *RedisCluster) GeoPos(key string, members ...string) ([]*GeoCoordinate, error)

GeoPos see comment in redis.go

func (*RedisCluster) GeoRadius added in v0.0.11

func (r *RedisCluster) GeoRadius(key string, longitude, latitude, radius float64, unit *GeoUnit, param ...*GeoRadiusParams) ([]GeoRadiusResponse, error)

GeoRadius see comment in redis.go

func (*RedisCluster) GeoRadiusByMember added in v0.0.11

func (r *RedisCluster) GeoRadiusByMember(key string, member string, radius float64, unit *GeoUnit, param ...*GeoRadiusParams) ([]GeoRadiusResponse, error)

GeoRadiusByMember see comment in redis.go

func (*RedisCluster) Get

func (r *RedisCluster) Get(key string) (string, error)

Get see redis command

func (*RedisCluster) GetBit added in v0.0.11

func (r *RedisCluster) GetBit(key string, offset int64) (bool, error)

GetBit see redis command

func (*RedisCluster) GetRange added in v0.0.11

func (r *RedisCluster) GetRange(key string, startOffset, endOffset int64) (string, error)

GetRange see redis command

func (*RedisCluster) GetSet

func (r *RedisCluster) GetSet(key, value string) (string, error)

GetSet see redis command

func (*RedisCluster) HDel added in v0.0.11

func (r *RedisCluster) HDel(key string, fields ...string) (int64, error)

HDel see redis command

func (*RedisCluster) HExists added in v0.0.11

func (r *RedisCluster) HExists(key, field string) (bool, error)

HExists see redis command

func (*RedisCluster) HGet added in v0.0.11

func (r *RedisCluster) HGet(key, field string) (string, error)

HGet see redis command

func (*RedisCluster) HGetAll added in v0.0.11

func (r *RedisCluster) HGetAll(key string) (map[string]string, error)

HGetAll see redis command

func (*RedisCluster) HIncrBy added in v0.0.11

func (r *RedisCluster) HIncrBy(key, field string, value int64) (int64, error)

HIncrBy see redis command

func (*RedisCluster) HIncrByFloat added in v0.0.11

func (r *RedisCluster) HIncrByFloat(key, field string, value float64) (float64, error)

HIncrByFloat see redis command

func (*RedisCluster) HKeys added in v0.0.11

func (r *RedisCluster) HKeys(key string) ([]string, error)

HKeys see redis command

func (*RedisCluster) HLen added in v0.0.11

func (r *RedisCluster) HLen(key string) (int64, error)

HLen see redis command

func (*RedisCluster) HMGet added in v0.0.11

func (r *RedisCluster) HMGet(key string, fields ...string) ([]string, error)

HMGet see redis command

func (*RedisCluster) HMSet added in v0.0.11

func (r *RedisCluster) HMSet(key string, hash map[string]string) (string, error)

HMSet see redis command

func (*RedisCluster) HScan added in v0.0.11

func (r *RedisCluster) HScan(key, cursor string, params ...*ScanParams) (*ScanResult, error)

HScan see comment in redis.go

func (*RedisCluster) HSet added in v0.0.11

func (r *RedisCluster) HSet(key, field string, value string) (int64, error)

HSet see redis command

func (*RedisCluster) HSetNx added in v0.0.11

func (r *RedisCluster) HSetNx(key, field, value string) (int64, error)

HSetNx see redis command

func (*RedisCluster) HVals added in v0.0.11

func (r *RedisCluster) HVals(key string) ([]string, error)

HVals see redis command

func (*RedisCluster) Incr

func (r *RedisCluster) Incr(key string) (int64, error)

Incr see redis command

func (*RedisCluster) IncrBy

func (r *RedisCluster) IncrBy(key string, increment int64) (int64, error)

IncrBy see redis command

func (*RedisCluster) IncrByFloat

func (r *RedisCluster) IncrByFloat(key string, increment float64) (float64, error)

IncrByFloat see redis command

func (*RedisCluster) LIndex added in v0.0.11

func (r *RedisCluster) LIndex(key string, index int64) (string, error)

LIndex see redis command

func (*RedisCluster) LInsert added in v0.0.11

func (r *RedisCluster) LInsert(key string, where *ListOption, pivot, value string) (int64, error)

LInsert see comment in redis.go

func (*RedisCluster) LLen added in v0.0.11

func (r *RedisCluster) LLen(key string) (int64, error)

LLen see redis command

func (*RedisCluster) LPop added in v0.0.11

func (r *RedisCluster) LPop(key string) (string, error)

LPop see redis command

func (*RedisCluster) LPush added in v0.0.11

func (r *RedisCluster) LPush(key string, strings ...string) (int64, error)

LPush see redis command

func (*RedisCluster) LPushX added in v0.0.11

func (r *RedisCluster) LPushX(key string, strs ...string) (int64, error)

LPushX see comment in redis.go

func (*RedisCluster) LRange added in v0.0.11

func (r *RedisCluster) LRange(key string, start, stop int64) ([]string, error)

LRange see redis command

func (*RedisCluster) LRem added in v0.0.11

func (r *RedisCluster) LRem(key string, count int64, value string) (int64, error)

LRem see redis command

func (*RedisCluster) LSet added in v0.0.11

func (r *RedisCluster) LSet(key string, index int64, value string) (string, error)

LSet see redis command

func (*RedisCluster) LTrim added in v0.0.11

func (r *RedisCluster) LTrim(key string, start, stop int64) (string, error)

LTrim see redis command

func (*RedisCluster) MGet added in v0.0.11

func (r *RedisCluster) MGet(keys ...string) ([]string, error)

MGet see comment in redis.go

func (*RedisCluster) MSet added in v0.0.11

func (r *RedisCluster) MSet(kvs ...string) (string, error)

MSet see comment in redis.go

func (*RedisCluster) MSetNx added in v0.0.11

func (r *RedisCluster) MSetNx(kvs ...string) (int64, error)

MSetNx see comment in redis.go

func (*RedisCluster) PExpire added in v0.0.11

func (r *RedisCluster) PExpire(key string, milliseconds int64) (int64, error)

PExpire see redis command

func (*RedisCluster) PExpireAt added in v0.0.11

func (r *RedisCluster) PExpireAt(key string, millisecondsTimestamp int64) (int64, error)

PExpireAt see redis command

func (*RedisCluster) PSetEx added in v0.0.11

func (r *RedisCluster) PSetEx(key string, milliseconds int64, value string) (string, error)

PSetEx see redis command

func (*RedisCluster) PSubscribe added in v0.0.11

func (r *RedisCluster) PSubscribe(redisPubSub *RedisPubSub, patterns ...string) error

PSubscribe see redis command

func (*RedisCluster) PTTL added in v0.0.11

func (r *RedisCluster) PTTL(key string) (int64, error)

PTTL see redis command

func (*RedisCluster) Persist

func (r *RedisCluster) Persist(key string) (int64, error)

Persist see redis command

func (*RedisCluster) PfAdd added in v0.0.11

func (r *RedisCluster) PfAdd(key string, elements ...string) (int64, error)

PfAdd see comment in redis.go

func (*RedisCluster) PfCount added in v0.0.11

func (r *RedisCluster) PfCount(keys ...string) (int64, error)

PfCount see redis command

func (*RedisCluster) PfMerge added in v0.0.11

func (r *RedisCluster) PfMerge(destkey string, sourcekeys ...string) (string, error)

PfMerge see redis command

func (*RedisCluster) Publish

func (r *RedisCluster) Publish(channel, message string) (int64, error)

Publish see redis command

func (*RedisCluster) RPop added in v0.0.11

func (r *RedisCluster) RPop(key string) (string, error)

RPop see redis command

func (*RedisCluster) RPopLPush added in v0.0.11

func (r *RedisCluster) RPopLPush(srcKey, destKey string) (string, error)

RPopLPush see comment in redis.go

func (*RedisCluster) RPush added in v0.0.11

func (r *RedisCluster) RPush(key string, strings ...string) (int64, error)

RPush see redis command

func (*RedisCluster) RPushX added in v0.0.11

func (r *RedisCluster) RPushX(key string, strs ...string) (int64, error)

RPushX see comment in redis.go

func (*RedisCluster) Rename

func (r *RedisCluster) Rename(oldKey, newKey string) (string, error)

Rename see comment in redis.go

func (*RedisCluster) RenameNx added in v0.0.11

func (r *RedisCluster) RenameNx(oldKey, newKey string) (int64, error)

RenameNx see comment in redis.go

func (*RedisCluster) SAdd added in v0.0.11

func (r *RedisCluster) SAdd(key string, members ...string) (int64, error)

SAdd see redis command

func (*RedisCluster) SCard added in v0.0.11

func (r *RedisCluster) SCard(key string) (int64, error)

SCard see comment in redis.go

func (*RedisCluster) SDiff added in v0.0.11

func (r *RedisCluster) SDiff(keys ...string) ([]string, error)

SDiff see comment in redis.go

func (*RedisCluster) SDiffStore added in v0.0.11

func (r *RedisCluster) SDiffStore(destKey string, keys ...string) (int64, error)

SDiffStore see comment in redis.go

func (*RedisCluster) SInter added in v0.0.11

func (r *RedisCluster) SInter(keys ...string) ([]string, error)

SInter see comment in redis.go

func (*RedisCluster) SInterStore added in v0.0.11

func (r *RedisCluster) SInterStore(destKey string, keys ...string) (int64, error)

SInterStore see comment in redis.go

func (*RedisCluster) SIsMember added in v0.0.11

func (r *RedisCluster) SIsMember(key string, member string) (bool, error)

SIsMember see comment in redis.go

func (*RedisCluster) SMembers added in v0.0.11

func (r *RedisCluster) SMembers(key string) ([]string, error)

SMembers see redis command

func (*RedisCluster) SMove added in v0.0.11

func (r *RedisCluster) SMove(srcKey, destKey, member string) (int64, error)

SMove see comment in redis.go

func (*RedisCluster) SPop added in v0.0.11

func (r *RedisCluster) SPop(key string) (string, error)

SPop see redis command

func (*RedisCluster) SPopBatch added in v0.0.11

func (r *RedisCluster) SPopBatch(key string, count int64) ([]string, error)

SPopBatch see comment in redis.go

func (*RedisCluster) SRandMember added in v0.0.11

func (r *RedisCluster) SRandMember(key string) (string, error)

SRandMember see comment in redis.go

func (*RedisCluster) SRandMemberBatch added in v0.0.11

func (r *RedisCluster) SRandMemberBatch(key string, count int) ([]string, error)

SRandMemberBatch see comment in redis.go

func (*RedisCluster) SRem added in v0.0.11

func (r *RedisCluster) SRem(key string, members ...string) (int64, error)

SRem see redis command

func (*RedisCluster) SScan added in v0.0.11

func (r *RedisCluster) SScan(key, cursor string, params ...*ScanParams) (*ScanResult, error)

SScan see comment in redis.go

func (*RedisCluster) SUnion added in v0.0.11

func (r *RedisCluster) SUnion(keys ...string) ([]string, error)

SUnion see comment in redis.go

func (*RedisCluster) SUnionStore added in v0.0.11

func (r *RedisCluster) SUnionStore(destKey string, keys ...string) (int64, error)

SUnionStore see comment in redis.go

func (*RedisCluster) Scan

func (r *RedisCluster) Scan(cursor string, params ...*ScanParams) (*ScanResult, error)

Scan see redis command

func (*RedisCluster) ScriptExists

func (r *RedisCluster) ScriptExists(key string, sha1 ...string) ([]bool, error)

ScriptExists see redis command

func (*RedisCluster) ScriptLoad

func (r *RedisCluster) ScriptLoad(key, script string) (string, error)

ScriptLoad see redis command

func (*RedisCluster) Set

func (r *RedisCluster) Set(key, value string) (string, error)

Set set key/value,without timeout

func (*RedisCluster) SetBit added in v0.0.11

func (r *RedisCluster) SetBit(key string, offset int64, value string) (bool, error)

SetBit see redis command

func (*RedisCluster) SetBitWithBool added in v0.0.11

func (r *RedisCluster) SetBitWithBool(key string, offset int64, value bool) (bool, error)

SetBitWithBool see redis command

func (*RedisCluster) SetEx added in v0.0.11

func (r *RedisCluster) SetEx(key string, seconds int, value string) (string, error)

SetEx see redis command

func (*RedisCluster) SetNx added in v0.0.11

func (r *RedisCluster) SetNx(key, value string) (int64, error)

SetNx see redis command

func (*RedisCluster) SetRange added in v0.0.11

func (r *RedisCluster) SetRange(key string, offset int64, value string) (int64, error)

SetRange see redis command

func (*RedisCluster) SetWithParams

func (r *RedisCluster) SetWithParams(key, value, nxxx string) (string, error)

SetWithParams see redis command

func (*RedisCluster) SetWithParamsAndTime

func (r *RedisCluster) SetWithParamsAndTime(key, value, nxxx, expx string, time int64) (string, error)

SetWithParamsAndTime see redis command

func (*RedisCluster) Sort

func (r *RedisCluster) Sort(key string, params ...*SortParams) ([]string, error)

Sort see comment in redis.go

func (*RedisCluster) SortStore added in v0.0.10

func (r *RedisCluster) SortStore(key, destKey string, params ...*SortParams) (int64, error)

SortStore see comment in redis.go

func (*RedisCluster) StrLen added in v0.0.11

func (r *RedisCluster) StrLen(key string) (int64, error)

StrLen see comment in redis.go

func (*RedisCluster) SubStr added in v0.0.11

func (r *RedisCluster) SubStr(key string, start, end int) (string, error)

SubStr see redis command

func (*RedisCluster) Subscribe

func (r *RedisCluster) Subscribe(redisPubSub *RedisPubSub, channels ...string) error

Subscribe see redis command

func (*RedisCluster) TTL added in v0.0.11

func (r *RedisCluster) TTL(key string) (int64, error)

TTL see redis command

func (*RedisCluster) Type

func (r *RedisCluster) Type(key string) (string, error)

Type see redis command

func (*RedisCluster) ZAdd added in v0.0.11

func (r *RedisCluster) ZAdd(key string, score float64, member string, params ...*ZAddParams) (int64, error)

ZAdd see comment in redis.go

func (*RedisCluster) ZAddByMap added in v0.0.11

func (r *RedisCluster) ZAddByMap(key string, scoreMembers map[string]float64, params ...*ZAddParams) (int64, error)

ZAddByMap see comment in redis.go

func (*RedisCluster) ZCard added in v0.0.11

func (r *RedisCluster) ZCard(key string) (int64, error)

ZCard see comment in redis.go

func (*RedisCluster) ZCount added in v0.0.11

func (r *RedisCluster) ZCount(key string, min, max float64) (int64, error)

ZCount see comment in redis.go

func (*RedisCluster) ZIncrBy added in v0.0.11

func (r *RedisCluster) ZIncrBy(key string, score float64, member string, params ...*ZAddParams) (float64, error)

ZIncrBy see comment in redis.go

func (*RedisCluster) ZInterStore added in v0.0.11

func (r *RedisCluster) ZInterStore(destKey string, sets ...string) (int64, error)

ZInterStore see comment in redis.go

func (*RedisCluster) ZInterStoreWithParams added in v0.0.11

func (r *RedisCluster) ZInterStoreWithParams(destKey string, params *ZParams, sets ...string) (int64, error)

ZInterStoreWithParams see redis command

func (*RedisCluster) ZLexCount added in v0.0.11

func (r *RedisCluster) ZLexCount(key, min, max string) (int64, error)

ZLexCount see comment in redis.go

func (*RedisCluster) ZRange added in v0.0.11

func (r *RedisCluster) ZRange(key string, start, end int64) ([]string, error)

ZRange see comment in redis.go

func (*RedisCluster) ZRangeByLex added in v0.0.11

func (r *RedisCluster) ZRangeByLex(key, min, max string) ([]string, error)

ZRangeByLex see comment in redis.go

func (*RedisCluster) ZRangeByLexBatch added in v0.0.11

func (r *RedisCluster) ZRangeByLexBatch(key, min, max string, offset, count int) ([]string, error)

ZRangeByLexBatch see comment in redis.go

func (*RedisCluster) ZRangeByScore added in v0.0.11

func (r *RedisCluster) ZRangeByScore(key string, min, max float64) ([]string, error)

ZRangeByScore see comment in redis.go

func (*RedisCluster) ZRangeByScoreBatch added in v0.0.11

func (r *RedisCluster) ZRangeByScoreBatch(key string, min, max float64, offset int, count int) ([]string, error)

ZRangeByScoreBatch see comment in redis.go

func (*RedisCluster) ZRangeByScoreWithScores added in v0.0.11

func (r *RedisCluster) ZRangeByScoreWithScores(key string, min, max float64) ([]Tuple, error)

ZRangeByScoreWithScores see comment in redis.go

func (*RedisCluster) ZRangeByScoreWithScoresBatch added in v0.0.11

func (r *RedisCluster) ZRangeByScoreWithScoresBatch(key string, min, max float64, offset, count int) ([]Tuple, error)

ZRangeByScoreWithScoresBatch see comment in redis.go

func (*RedisCluster) ZRangeWithScores added in v0.0.11

func (r *RedisCluster) ZRangeWithScores(key string, start, end int64) ([]Tuple, error)

ZRangeWithScores see comment in redis.go

func (*RedisCluster) ZRank added in v0.0.11

func (r *RedisCluster) ZRank(key, member string) (int64, error)

ZRank see comment in redis.go

func (*RedisCluster) ZRem added in v0.0.11

func (r *RedisCluster) ZRem(key string, member ...string) (int64, error)

ZRem see comment in redis.go

func (*RedisCluster) ZRemRangeByLex added in v0.0.11

func (r *RedisCluster) ZRemRangeByLex(key, min, max string) (int64, error)

ZRemRangeByLex see comment in redis.go

func (*RedisCluster) ZRemRangeByRank added in v0.0.11

func (r *RedisCluster) ZRemRangeByRank(key string, start, end int64) (int64, error)

ZRemRangeByRank see comment in redis.go

func (*RedisCluster) ZRemRangeByScore added in v0.0.11

func (r *RedisCluster) ZRemRangeByScore(key string, min, max float64) (int64, error)

ZRemRangeByScore see comment in redis.go

func (*RedisCluster) ZRevRange added in v0.0.11

func (r *RedisCluster) ZRevRange(key string, start, end int64) ([]string, error)

ZRevRange see comment in redis.go

func (*RedisCluster) ZRevRangeByLex added in v0.0.11

func (r *RedisCluster) ZRevRangeByLex(key, max, min string) ([]string, error)

ZRevRangeByLex see comment in redis.go

func (*RedisCluster) ZRevRangeByLexBatch added in v0.0.11

func (r *RedisCluster) ZRevRangeByLexBatch(key, max, min string, offset, count int) ([]string, error)

ZRevRangeByLexBatch see comment in redis.go

func (*RedisCluster) ZRevRangeByScore added in v0.0.11

func (r *RedisCluster) ZRevRangeByScore(key string, max, min float64) ([]string, error)

ZRevRangeByScore see comment in redis.go

func (*RedisCluster) ZRevRangeByScoreWithScores added in v0.0.11

func (r *RedisCluster) ZRevRangeByScoreWithScores(key string, max, min float64) ([]Tuple, error)

ZRevRangeByScoreWithScores see comment in redis.go

func (*RedisCluster) ZRevRangeByScoreWithScoresBatch added in v0.0.11

func (r *RedisCluster) ZRevRangeByScoreWithScoresBatch(key string, max, min float64, offset, count int) ([]Tuple, error)

ZRevRangeByScoreWithScoresBatch see comment in redis.go

func (*RedisCluster) ZRevRangeWithScores added in v0.0.11

func (r *RedisCluster) ZRevRangeWithScores(key string, start, end int64) ([]Tuple, error)

ZRevRangeWithScores see comment in redis.go

func (*RedisCluster) ZRevRank added in v0.0.11

func (r *RedisCluster) ZRevRank(key, member string) (int64, error)

ZRevRank see comment in redis.go

func (*RedisCluster) ZScan added in v0.0.11

func (r *RedisCluster) ZScan(key, cursor string, params ...*ScanParams) (*ScanResult, error)

ZScan see comment in redis.go

func (*RedisCluster) ZScore added in v0.0.11

func (r *RedisCluster) ZScore(key, member string) (float64, error)

ZScore see comment in redis.go

func (*RedisCluster) ZUnionStore added in v0.0.11

func (r *RedisCluster) ZUnionStore(destKey string, sets ...string) (int64, error)

ZUnionStore see redis command

func (*RedisCluster) ZUnionStoreWithParams added in v0.0.11

func (r *RedisCluster) ZUnionStoreWithParams(destKey string, params *ZParams, sets ...string) (int64, error)

ZUnionStoreWithParams see redis command

type RedisError added in v0.0.5

type RedisError struct {
	Message string
}

RedisError basic redis error

func (*RedisError) Error added in v0.0.5

func (e *RedisError) Error() string

type RedisPubSub

type RedisPubSub struct {
	OnMessage      func(channel, message string)                 //receive message
	OnPMessage     func(pattern string, channel, message string) //receive pattern message
	OnSubscribe    func(channel string, subscribedChannels int)  //listen subscribe event
	OnUnSubscribe  func(channel string, subscribedChannels int)  //listen unsubscribe event
	OnPUnSubscribe func(pattern string, subscribedChannels int)  //listen pattern unsubscribe event
	OnPSubscribe   func(pattern string, subscribedChannels int)  //listen pattern subscribe event
	OnPong         func(channel string)                          //listen heart beat event
	// contains filtered or unexported fields
}

RedisPubSub redis pubsub struct

func (*RedisPubSub) PSubscribe added in v0.0.11

func (r *RedisPubSub) PSubscribe(channels ...string) error

PSubscribe subscribe some pattern channels

func (*RedisPubSub) PUnSubscribe added in v0.0.11

func (r *RedisPubSub) PUnSubscribe(channels ...string) error

PUnSubscribe unsubscribe some pattern channels

func (*RedisPubSub) Subscribe

func (r *RedisPubSub) Subscribe(channels ...string) error

Subscribe subscribe some channels

func (*RedisPubSub) UnSubscribe added in v0.0.11

func (r *RedisPubSub) UnSubscribe(channels ...string) error

UnSubscribe unsubscribe some channels

type Reset

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

Reset reset struct

type Response

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

Response pipeline and transaction response,include replies from redis

func (*Response) Get

func (r *Response) Get() (interface{}, error)

Get get real content of response

type ScanParams

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

ScanParams scan,hscan,sscan,zscan params

func NewScanParams

func NewScanParams() *ScanParams

NewScanParams create scan params instance

func (*ScanParams) Count added in v0.0.3

func (s *ScanParams) Count(count int) *ScanParams

Count scan result count

func (ScanParams) GetMatch added in v0.0.11

func (s ScanParams) GetMatch() string

GetMatch get the match param value

func (*ScanParams) Match added in v0.0.3

func (s *ScanParams) Match(pattern string) *ScanParams

Match scan match pattern

type ScanResult

type ScanResult struct {
	Cursor  string
	Results []string
}

ScanResult scan result struct

func ObjArrToScanResultReply added in v0.0.11

func ObjArrToScanResultReply(reply []interface{}, err error) (*ScanResult, error)

ObjArrToScanResultReply convert object array reply to scanresult reply

func ToScanResultReply

func ToScanResultReply(reply interface{}, err error) (*ScanResult, error)

ToScanResultReply convert object reply to scanresult reply

type SlowLog added in v0.0.11

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

SlowLog redis slow log struct

type SortParams added in v0.0.11

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

SortParams sort params

func NewSortParams added in v0.0.11

func NewSortParams() *SortParams

NewSortParams create new sort params instance

func (*SortParams) Alpha added in v0.0.11

func (p *SortParams) Alpha() *SortParams

Alpha sort elements in alpha order

func (*SortParams) Asc added in v0.0.11

func (p *SortParams) Asc() *SortParams

Asc set asc param,then sort elements in ascending order

func (*SortParams) By added in v0.0.11

func (p *SortParams) By(pattern string) *SortParams

By set by param with pattern

func (*SortParams) Desc added in v0.0.11

func (p *SortParams) Desc() *SortParams

Desc set desc param,then sort elements in descending order

func (*SortParams) Get added in v0.0.11

func (p *SortParams) Get(patterns ...string) *SortParams

Get set get param with patterns

func (*SortParams) Limit added in v0.0.11

func (p *SortParams) Limit(start, count int) *SortParams

Limit limit the sort result,[x,y)

func (*SortParams) NoSort added in v0.0.11

func (p *SortParams) NoSort() *SortParams

NoSort set by param with nosort

type Transaction

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

Transaction redis transaction struct

func (Transaction) BLPop added in v0.0.11

func (p Transaction) BLPop(args ...string) (*Response, error)

BLPop see redis command

func (Transaction) BLPopTimeout added in v0.0.11

func (p Transaction) BLPopTimeout(timeout int, keys ...string) (*Response, error)

BLPopTimeout see redis command

func (Transaction) BRPop added in v0.0.11

func (p Transaction) BRPop(args ...string) (*Response, error)

BRPop see redis command

func (Transaction) BRPopLPush added in v0.0.11

func (p Transaction) BRPopLPush(source, destination string, timeout int) (*Response, error)

BRPopLPush see redis command

func (Transaction) BRPopTimeout added in v0.0.11

func (p Transaction) BRPopTimeout(timeout int, keys ...string) (*Response, error)

BRPopTimeout see redis command

func (Transaction) BgRewriteAof added in v0.0.11

func (p Transaction) BgRewriteAof() (*Response, error)

BgRewriteAof see redis command

func (Transaction) BgSave added in v0.0.11

func (p Transaction) BgSave() (*Response, error)

BgSave see redis command

func (Transaction) BitOp added in v0.0.11

func (p Transaction) BitOp(op BitOP, destKey string, srcKeys ...string) (*Response, error)

BitOp see redis command

func (*Transaction) Clear

func (t *Transaction) Clear() (string, error)

Clear clear

func (Transaction) ClusterAddSlots added in v0.0.11

func (p Transaction) ClusterAddSlots(slots ...int) (*Response, error)

ClusterAddSlots see redis command

func (Transaction) ClusterDelSlots added in v0.0.11

func (p Transaction) ClusterDelSlots(slots ...int) (*Response, error)

ClusterDelSlots see redis command

func (Transaction) ClusterGetKeysInSlot added in v0.0.11

func (p Transaction) ClusterGetKeysInSlot(slot int, count int) (*Response, error)

ClusterGetKeysInSlot see redis command

func (Transaction) ClusterInfo added in v0.0.11

func (p Transaction) ClusterInfo() (*Response, error)

ClusterInfo see redis command

func (Transaction) ClusterMeet added in v0.0.11

func (p Transaction) ClusterMeet(ip string, port int) (*Response, error)

ClusterMeet see redis command

func (Transaction) ClusterNodes added in v0.0.11

func (p Transaction) ClusterNodes() (*Response, error)

ClusterNodes see redis command

func (Transaction) ClusterSetSlotImporting added in v0.0.11

func (p Transaction) ClusterSetSlotImporting(slot int, nodeID string) (*Response, error)

ClusterSetSlotImporting see redis command

func (Transaction) ClusterSetSlotMigrating added in v0.0.11

func (p Transaction) ClusterSetSlotMigrating(slot int, nodeID string) (*Response, error)

ClusterSetSlotMigrating see redis command

func (Transaction) ClusterSetSlotNode added in v0.0.11

func (p Transaction) ClusterSetSlotNode(slot int, nodeID string) (*Response, error)

ClusterSetSlotNode see redis command

func (Transaction) ConfigGet added in v0.0.11

func (p Transaction) ConfigGet(pattern string) (*Response, error)

ConfigGet see redis command

func (Transaction) ConfigResetStat added in v0.0.11

func (p Transaction) ConfigResetStat() (*Response, error)

ConfigResetStat see redis command

func (Transaction) ConfigSet added in v0.0.11

func (p Transaction) ConfigSet(parameter, value string) (*Response, error)

ConfigSet see redis command

func (Transaction) DbSize added in v0.0.11

func (p Transaction) DbSize() (*Response, error)

DbSize see redis command

func (Transaction) Del added in v0.0.11

func (p Transaction) Del(keys ...string) (*Response, error)

Del see redis command

func (*Transaction) Discard

func (t *Transaction) Discard() (string, error)

Discard see redis command

func (Transaction) Eval added in v0.0.11

func (p Transaction) Eval(script string, keyCount int, params ...string) (*Response, error)

Eval see redis command

func (Transaction) EvalSha added in v0.0.11

func (p Transaction) EvalSha(sha1 string, keyCount int, params ...string) (*Response, error)

EvalSha see redis command

func (*Transaction) Exec

func (t *Transaction) Exec() ([]interface{}, error)

Exec execute transaction

func (*Transaction) ExecGetResponse

func (t *Transaction) ExecGetResponse() ([]*Response, error)

ExecGetResponse ...

func (Transaction) Exists added in v0.0.11

func (p Transaction) Exists(keys ...string) (*Response, error)

Exists see redis command

func (Transaction) FlushAll added in v0.0.11

func (p Transaction) FlushAll() (*Response, error)

FlushAll see redis command

func (Transaction) FlushDB added in v0.0.11

func (p Transaction) FlushDB() (*Response, error)

FlushDB see redis command

func (Transaction) Info added in v0.0.11

func (p Transaction) Info() (*Response, error)

Info see redis command

func (Transaction) Keys added in v0.0.11

func (p Transaction) Keys(pattern string) (*Response, error)

Keys see redis command

func (Transaction) LastSave added in v0.0.11

func (p Transaction) LastSave() (*Response, error)

LastSave see redis command

func (Transaction) MGet added in v0.0.11

func (p Transaction) MGet(keys ...string) (*Response, error)

MGet see redis command

func (Transaction) MSet added in v0.0.11

func (p Transaction) MSet(kvs ...string) (*Response, error)

MSet see redis command

func (Transaction) MSetNx added in v0.0.11

func (p Transaction) MSetNx(kvs ...string) (*Response, error)

MSetNx see redis command

func (Transaction) PfCount added in v0.0.11

func (p Transaction) PfCount(keys ...string) (*Response, error)

PfCount see redis command

func (Transaction) PfMerge added in v0.0.11

func (p Transaction) PfMerge(destKey string, srcKeys ...string) (*Response, error)

PfMerge see redis command

func (Transaction) Ping added in v0.0.11

func (p Transaction) Ping() (*Response, error)

Ping see redis command

func (Transaction) Publish added in v0.0.11

func (p Transaction) Publish(channel, message string) (*Response, error)

Publish see redis command

func (Transaction) RPopLPush added in v0.0.11

func (p Transaction) RPopLPush(srcKey, destKey string) (*Response, error)

RPopLPush see redis command

func (Transaction) RandomKey added in v0.0.11

func (p Transaction) RandomKey() (*Response, error)

RandomKey see redis command

func (Transaction) Rename added in v0.0.11

func (p Transaction) Rename(oldkey, newkey string) (*Response, error)

Rename see redis command

func (Transaction) RenameNx added in v0.0.11

func (p Transaction) RenameNx(oldkey, newkey string) (*Response, error)

RenameNx see redis command

func (Transaction) SDiff added in v0.0.11

func (p Transaction) SDiff(keys ...string) (*Response, error)

SDiff see redis command

func (Transaction) SDiffStore added in v0.0.11

func (p Transaction) SDiffStore(destKey string, keys ...string) (*Response, error)

SDiffStore see redis command

func (Transaction) SInter added in v0.0.11

func (p Transaction) SInter(keys ...string) (*Response, error)

SInter see redis command

func (Transaction) SInterStore added in v0.0.11

func (p Transaction) SInterStore(destKey string, keys ...string) (*Response, error)

SInterStore see redis command

func (Transaction) SMove added in v0.0.11

func (p Transaction) SMove(srcKey, destKey, member string) (*Response, error)

SMove see redis command

func (Transaction) SUnion added in v0.0.11

func (p Transaction) SUnion(keys ...string) (*Response, error)

SUnion see redis command

func (Transaction) SUnionStore added in v0.0.11

func (p Transaction) SUnionStore(destKey string, keys ...string) (*Response, error)

SUnionStore see redis command

func (Transaction) Save added in v0.0.11

func (p Transaction) Save() (*Response, error)

Save see redis command

func (Transaction) Select added in v0.0.11

func (p Transaction) Select(index int) (*Response, error)

Select see redis command

func (Transaction) Shutdown added in v0.0.11

func (p Transaction) Shutdown() (*Response, error)

Shutdown see redis command

func (Transaction) SortStore added in v0.0.11

func (p Transaction) SortStore(key string, destKey string, params ...*SortParams) (*Response, error)

SortMulti see redis command

func (Transaction) Time added in v0.0.11

func (p Transaction) Time() (*Response, error)

Time see redis command

func (Transaction) Watch added in v0.0.11

func (p Transaction) Watch(keys ...string) (*Response, error)

Watch see redis command

func (Transaction) ZInterStore added in v0.0.11

func (p Transaction) ZInterStore(destKey string, sets ...string) (*Response, error)

ZInterStore see redis command

func (Transaction) ZInterStoreWithParams added in v0.0.11

func (p Transaction) ZInterStoreWithParams(destKey string, params *ZParams, sets ...string) (*Response, error)

ZInterStoreWithParams see redis command

func (Transaction) ZUnionStore added in v0.0.11

func (p Transaction) ZUnionStore(destKey string, sets ...string) (*Response, error)

ZUnionStore see redis command

func (Transaction) ZUnionStoreWithParams added in v0.0.11

func (p Transaction) ZUnionStoreWithParams(destKey string, params *ZParams, sets ...string) (*Response, error)

ZUnionStoreWithParams see redis command

type Tuple

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

Tuple zset tuple

func StrArrToTupleReply added in v0.0.11

func StrArrToTupleReply(reply []string, err error) ([]Tuple, error)

StrArrToTupleReply convert string array reply to tuple array reply

func ToTupleArrReply added in v0.0.11

func ToTupleArrReply(reply interface{}, err error) ([]Tuple, error)

ToTupleArrReply convert object reply to tuple array reply

type ZAddParams

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

ZAddParams ...

func NewZAddParams added in v0.0.7

func NewZAddParams() *ZAddParams

NewZAddParams constructor

func (*ZAddParams) CH

func (p *ZAddParams) CH() *ZAddParams

CH set CH parameter, Modify the return value from the number of new elements added, to the total number of elements changed

func (*ZAddParams) Contains added in v0.0.3

func (p *ZAddParams) Contains(key string) bool

Contains return params map contains the key

func (*ZAddParams) NX

func (p *ZAddParams) NX() *ZAddParams

NX set NX parameter, Don't update already existing elements. Always add new elements.

func (*ZAddParams) XX

func (p *ZAddParams) XX() *ZAddParams

XX set XX parameter, Only update elements that already exist. Never add elements.

type ZParams

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

ZParams zset operation params

func (*ZParams) Aggregate added in v0.0.11

func (g *ZParams) Aggregate(aggregate *Aggregate) *ZParams

Aggregate Set Aggregate.

func (*ZParams) WeightsByDouble added in v0.0.11

func (g *ZParams) WeightsByDouble(weights ...float64) *ZParams

WeightsByDouble Set weights.

Jump to

Keyboard shortcuts

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