client

package
v0.0.0-...-237ceba Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2020 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package client is a redis RESP3 protocol only client implementation in go.

Example (Client)
package main

import (
	"fmt"
	"log"

	"github.com/d024441/go-resp3/client"
)

func main() {
	// Open connection with standard host and port:
	// - if environment variablen REDIS_HOST AND REDIS_PORT are set,
	//   these values are used
	// - otherwise localhost (127.0.0.1) and Redis default port 6379 are used
	conn, err := client.Dial("")
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close()

	if err := conn.Set("mykey", "Hello Redis").Err(); err != nil {
		log.Fatal(err)
	}
	value, err := conn.Get("mykey").ToString()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(value)
}
Output:

Hello Redis
Example (Clientcache)
package main

import (
	"fmt"
	"log"

	"github.com/d024441/go-resp3/client"
)

func main() {
	mykey := client.RandomKey("mykey")

	// Create cache.
	cache := client.NewCache()

	// Create connetion providing cache.
	dialer := client.Dialer{Cache: cache}
	conn, err := dialer.Dial("")
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close()

	// Set client tracking on.
	if err := conn.ClientTracking(true, nil).Err(); err != nil {
		log.Fatal(err)
	}

	// Set key.
	conn.Set(mykey, "Hello Redis")

	// Get key.
	val, err := conn.Get(mykey).Value()
	if err != nil {
		log.Fatal(err)
	}

	// Save value in cache.
	cache.Put(mykey, val)

	// Read value from cache.
	val, ok := cache.Get(mykey)
	if !ok {
		log.Fatal("cache miss")
	}
	s, err := val.ToString()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(s)

	done := make(chan (struct{}), 0)

	// Change Key in different connection.
	go func() {
		conn, err := client.Dial("")
		if err != nil {
			log.Fatal(err)
		}
		defer conn.Close()
		// Update key.
		if err = conn.Set(mykey, "Update mykey").Err(); err != nil {
			log.Fatal(err)
		}
		close(done)
	}()

	// Wait for go-routine.
	<-done

	// Cache miss: read until cache slot is invalidated.
	for {
		if _, ok := cache.Get(mykey); !ok {
			fmt.Println("Key invalidated")
			break
		}
	}

}
Output:

Hello Redis
Key invalidated
Example (Monitor)
package main

import (
	"fmt"
	"log"

	"github.com/d024441/go-resp3/client"
)

import (
	"time"
)

func Monitor(time time.Time, db int64, addr string, cmd []string) {
	fmt.Printf("time: %s database: %d address: %s command %v\n", time, db, addr, cmd)
}

func main() {
	// Register monitor callback.
	dialer := client.Dialer{MonitorCallback: Monitor}
	conn, err := dialer.Dial("")
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close()

	// Start monitor.
	ok, err := conn.Monitor().ToBool()
	if err != nil {
		log.Fatal(err)
	}
	if !ok {
		log.Fatal("Start monitor failed")
	}

	// Process some commands in same connection.
	mykey := client.RandomKey("mykey")
	for i := 0; i < 5; i++ {
		if err = conn.Set(mykey, "myValue").Err(); err != nil {
			log.Fatal(err)
		}
	}
}
Output:

Example (Pubsub)
package main

import (
	"fmt"
	"log"

	"github.com/d024441/go-resp3/client"
)

func MsgCallback(pattern, channel, msg string) {
	fmt.Printf("Channel: %s Message: %s", channel, msg)
}

func main() {
	// Open connection with standard host and port:
	// - if environment variablen REDIS_HOST AND REDIS_PORT are set,
	//   these values are used
	// - otherwise localhost (127.0.0.1) and Redis default port 6379 are used
	conn, err := client.Dial("")
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close()

	// Subscribe channel.
	if err := conn.Subscribe([]string{"mychannel"}, MsgCallback).Err(); err != nil {
		log.Fatal(err)
	}
	// Connection allows to proceed with any other Redis commands.
	// Not limited to Subscribe, Psubscribe, Unsubscribe, Punsubscribe, Ping and Quit.
	if err := conn.Set("mykey", "Hello Redis").Err(); err != nil {
		log.Fatal(err)
	}
	value, err := conn.Get("mykey").ToString()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(value)
	// Publish message
	if err := conn.Publish("mychannel", "Hello Redis").Err(); err != nil {
		log.Fatal(err)
	}
	// Unsubscribe channel.
	if err := conn.Unsubscribe([]string{"mychannel"}).Err(); err != nil {
		log.Fatal(err)
	}
}
Output:

Hello Redis
Channel: mychannel Message: Hello Redis
Example (Redefine)
package main

// This example shows how to create custom connection and pipeline objects
// to extend the command interface or redefine commands.

import (
	"fmt"
	"log"

	"github.com/d024441/go-resp3/client"
)

// MyCommands defines redefined and additional commands.
type MyCommands interface {
	// Redefinition of Del - use variadic attribute instead slice.
	Del(keys ...interface{}) client.Result
	// Additional command Heartbeat.
	Heartbeat() client.Result
}

// Check, that connection and pipeline implement MyCommands.
var (
	_ MyCommands = (*MyConn)(nil)
	_ MyCommands = (*MyPipeline)(nil)
)

// MyConn is the custom connection.
type MyConn struct {
	client.Conn
}

// MyConn contructor.
func NewMyConn() (*MyConn, error) {
	conn, err := client.Dial("")
	if err != nil {
		return nil, err
	}
	return &MyConn{Conn: conn}, nil
}

// Pipeline overwrites the connection pipeline method.
func (c *MyConn) Pipeline() *MyPipeline {
	return NewMyPipeline(c)
}

// Del implements MyCommands interface.
func (c *MyConn) Del(keys ...interface{}) client.Result {
	// call client connection method.
	return c.Conn.Del(keys)
}

// Heartbeat implements MyCommands interface.
func (c *MyConn) Heartbeat() client.Result {
	// call client connection method
	// using the generic Do method
	return c.Conn.Do("ping", "ok")
}

// MyPipeline is the custom pipeline.
type MyPipeline struct {
	client.Pipeline
}

// MyPipeline constructor.
func NewMyPipeline(c *MyConn) *MyPipeline {
	return &MyPipeline{Pipeline: c.Conn.Pipeline()}
}

// Del implements MyCommands interface.
func (p *MyPipeline) Del(keys ...interface{}) client.Result {
	return p.Pipeline.Del(keys)
}

// Heartbeat implements MyCommands interface.
func (p *MyPipeline) Heartbeat() client.Result {
	return p.Pipeline.Do("ping", "ok")
}

func main() {
	// Use custom connection.
	conn, err := NewMyConn()
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close()

	if err := conn.Set("mykey", "myvalue").Err(); err != nil {
		log.Fatal(err)
	}
	// Use of redefined connection method.
	removedKeys, err := conn.Del("mykey").ToInt64()
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(removedKeys)

	// Use of extended connection method.
	ok, err := conn.Heartbeat().ToString()
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(ok)

	// Use custom pipeline.
	pipeline := conn.Pipeline()

	set := pipeline.Set("mykey", "myvalue")
	// Use of redefined pipeline method.
	del := pipeline.Del("mykey")
	// Use of extended pipeline method.
	heartbeat := conn.Heartbeat()

	pipeline.Flush()

	if err := set.Err(); err != nil {
		log.Fatal(err)
	}
	removedKeys, err = del.ToInt64()
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(removedKeys)

	ok, err = heartbeat.ToString()
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(ok)
}
Output:

1
ok
1
ok

Index

Examples

Constants

View Source
const (
	EnvHost = "REDIS_HOST"
	EnvPort = "REDIS_PORT"
)

Environment variables.

View Source
const (
	LocalHost        = "127.0.0.1"
	DefaultRedisPort = "6379"
)

Default redis host and port.

View Source
const (
	GroupCluster      = "Cluster"
	GroupConnection   = "Connection"
	GroupGeneric      = "Generic"
	GroupGeo          = "Geo"
	GroupHash         = "Hash"
	GroupHyperloglog  = "Hyperloglog"
	GroupList         = "List"
	GroupPubsub       = "Pubsub"
	GroupScripting    = "Scripting"
	GroupServer       = "Server"
	GroupSet          = "Set"
	GroupSortedSet    = "SortedSet"
	GroupStream       = "Stream"
	GroupString       = "String"
	GroupTransactions = "Transactions"
)
View Source
const (
	CmdAclCat                     = "AclCat"
	CmdAclDeluser                 = "AclDeluser"
	CmdAclGenpass                 = "AclGenpass"
	CmdAclGetuser                 = "AclGetuser"
	CmdAclHelp                    = "AclHelp"
	CmdAclList                    = "AclList"
	CmdAclLoad                    = "AclLoad"
	CmdAclSave                    = "AclSave"
	CmdAclSetuser                 = "AclSetuser"
	CmdAclUsers                   = "AclUsers"
	CmdAclWhoami                  = "AclWhoami"
	CmdAppend                     = "Append"
	CmdAuth                       = "Auth"
	CmdBgrewriteaof               = "Bgrewriteaof"
	CmdBgsave                     = "Bgsave"
	CmdBitcount                   = "Bitcount"
	CmdBitfield                   = "Bitfield"
	CmdBitopAnd                   = "BitopAnd"
	CmdBitopNot                   = "BitopNot"
	CmdBitopOr                    = "BitopOr"
	CmdBitopXor                   = "BitopXor"
	CmdBitpos                     = "Bitpos"
	CmdBlpop                      = "Blpop"
	CmdBrpop                      = "Brpop"
	CmdBrpoplpush                 = "Brpoplpush"
	CmdBzpopmax                   = "Bzpopmax"
	CmdBzpopmin                   = "Bzpopmin"
	CmdClientGetname              = "ClientGetname"
	CmdClientId                   = "ClientId"
	CmdClientKill                 = "ClientKill"
	CmdClientList                 = "ClientList"
	CmdClientPause                = "ClientPause"
	CmdClientReply                = "ClientReply"
	CmdClientSetname              = "ClientSetname"
	CmdClientTracking             = "ClientTracking"
	CmdClientUnblock              = "ClientUnblock"
	CmdClusterAddslots            = "ClusterAddslots"
	CmdClusterBumpepoch           = "ClusterBumpepoch"
	CmdClusterCountFailureReports = "ClusterCountFailureReports"
	CmdClusterCountkeysinslot     = "ClusterCountkeysinslot"
	CmdClusterDelslots            = "ClusterDelslots"
	CmdClusterFailover            = "ClusterFailover"
	CmdClusterFlushslots          = "ClusterFlushslots"
	CmdClusterForget              = "ClusterForget"
	CmdClusterGetkeysinslot       = "ClusterGetkeysinslot"
	CmdClusterInfo                = "ClusterInfo"
	CmdClusterKeyslot             = "ClusterKeyslot"
	CmdClusterMeet                = "ClusterMeet"
	CmdClusterMyid                = "ClusterMyid"
	CmdClusterNodes               = "ClusterNodes"
	CmdClusterReplicas            = "ClusterReplicas"
	CmdClusterReplicate           = "ClusterReplicate"
	CmdClusterReset               = "ClusterReset"
	CmdClusterSaveconfig          = "ClusterSaveconfig"
	CmdClusterSetConfigEpoch      = "ClusterSetConfigEpoch"
	CmdClusterSetslotImporting    = "ClusterSetslotImporting"
	CmdClusterSetslotMigrating    = "ClusterSetslotMigrating"
	CmdClusterSetslotNode         = "ClusterSetslotNode"
	CmdClusterSetslotStable       = "ClusterSetslotStable"
	CmdClusterSlaves              = "ClusterSlaves"
	CmdClusterSlots               = "ClusterSlots"
	CmdCommand                    = "Command"
	CmdCommandCount               = "CommandCount"
	CmdCommandGetkeys             = "CommandGetkeys"
	CmdCommandInfo                = "CommandInfo"
	CmdConfigGet                  = "ConfigGet"
	CmdConfigResetstat            = "ConfigResetstat"
	CmdConfigRewrite              = "ConfigRewrite"
	CmdConfigSet                  = "ConfigSet"
	CmdDbsize                     = "Dbsize"
	CmdDebugObject                = "DebugObject"
	CmdDebugSegfault              = "DebugSegfault"
	CmdDecr                       = "Decr"
	CmdDecrby                     = "Decrby"
	CmdDel                        = "Del"
	CmdDiscard                    = "Discard"
	CmdDo                         = "Do"
	CmdDump                       = "Dump"
	CmdEcho                       = "Echo"
	CmdEval                       = "Eval"
	CmdEvalsha                    = "Evalsha"
	CmdExec                       = "Exec"
	CmdExists                     = "Exists"
	CmdExpire                     = "Expire"
	CmdExpireat                   = "Expireat"
	CmdFlushall                   = "Flushall"
	CmdFlushdb                    = "Flushdb"
	CmdGeoadd                     = "Geoadd"
	CmdGeodist                    = "Geodist"
	CmdGeohash                    = "Geohash"
	CmdGeopos                     = "Geopos"
	CmdGeoradius                  = "Georadius"
	CmdGeoradiusbymember          = "Georadiusbymember"
	CmdGet                        = "Get"
	CmdGetbit                     = "Getbit"
	CmdGetrange                   = "Getrange"
	CmdGetset                     = "Getset"
	CmdHdel                       = "Hdel"
	CmdHello                      = "Hello"
	CmdHexists                    = "Hexists"
	CmdHget                       = "Hget"
	CmdHgetall                    = "Hgetall"
	CmdHincrby                    = "Hincrby"
	CmdHincrbyfloat               = "Hincrbyfloat"
	CmdHkeys                      = "Hkeys"
	CmdHlen                       = "Hlen"
	CmdHmget                      = "Hmget"
	CmdHscan                      = "Hscan"
	CmdHset                       = "Hset"
	CmdHsetNx                     = "HsetNx"
	CmdHstrlen                    = "Hstrlen"
	CmdHvals                      = "Hvals"
	CmdIncr                       = "Incr"
	CmdIncrby                     = "Incrby"
	CmdIncrbyfloat                = "Incrbyfloat"
	CmdInfo                       = "Info"
	CmdKeys                       = "Keys"
	CmdLastsave                   = "Lastsave"
	CmdLatencyDoctor              = "LatencyDoctor"
	CmdLatencyGraph               = "LatencyGraph"
	CmdLatencyHelp                = "LatencyHelp"
	CmdLatencyHistory             = "LatencyHistory"
	CmdLatencyLatest              = "LatencyLatest"
	CmdLatencyReset               = "LatencyReset"
	CmdLindex                     = "Lindex"
	CmdLinsert                    = "Linsert"
	CmdLlen                       = "Llen"
	CmdLolwut                     = "Lolwut"
	CmdLpop                       = "Lpop"
	CmdLpush                      = "Lpush"
	CmdLpushx                     = "Lpushx"
	CmdLrange                     = "Lrange"
	CmdLrem                       = "Lrem"
	CmdLset                       = "Lset"
	CmdLtrim                      = "Ltrim"
	CmdMemoryDoctor               = "MemoryDoctor"
	CmdMemoryHelp                 = "MemoryHelp"
	CmdMemoryMallocStats          = "MemoryMallocStats"
	CmdMemoryPurge                = "MemoryPurge"
	CmdMemoryStats                = "MemoryStats"
	CmdMemoryUsage                = "MemoryUsage"
	CmdMget                       = "Mget"
	CmdMigrate                    = "Migrate"
	CmdModuleList                 = "ModuleList"
	CmdModuleLoad                 = "ModuleLoad"
	CmdModuleUnload               = "ModuleUnload"
	CmdMonitor                    = "Monitor"
	CmdMove                       = "Move"
	CmdMset                       = "Mset"
	CmdMsetNx                     = "MsetNx"
	CmdMulti                      = "Multi"
	CmdObjectEncoding             = "ObjectEncoding"
	CmdObjectFreq                 = "ObjectFreq"
	CmdObjectHelp                 = "ObjectHelp"
	CmdObjectIdletime             = "ObjectIdletime"
	CmdObjectRefcount             = "ObjectRefcount"
	CmdPTTL                       = "PTTL"
	CmdPersist                    = "Persist"
	CmdPexpire                    = "Pexpire"
	CmdPexpireat                  = "Pexpireat"
	CmdPfadd                      = "Pfadd"
	CmdPfcount                    = "Pfcount"
	CmdPfmerge                    = "Pfmerge"
	CmdPing                       = "Ping"
	CmdPsubscribe                 = "Psubscribe"
	CmdPsync                      = "Psync"
	CmdPublish                    = "Publish"
	CmdPubsubChannels             = "PubsubChannels"
	CmdPubsubNumpat               = "PubsubNumpat"
	CmdPubsubNumsub               = "PubsubNumsub"
	CmdPunsubscribe               = "Punsubscribe"
	CmdQuit                       = "Quit"
	CmdRandomkey                  = "Randomkey"
	CmdReadonly                   = "Readonly"
	CmdReadwrite                  = "Readwrite"
	CmdRename                     = "Rename"
	CmdRenameNx                   = "RenameNx"
	CmdReplicaof                  = "Replicaof"
	CmdRestore                    = "Restore"
	CmdRole                       = "Role"
	CmdRpop                       = "Rpop"
	CmdRpoplpush                  = "Rpoplpush"
	CmdRpush                      = "Rpush"
	CmdRpushx                     = "Rpushx"
	CmdSadd                       = "Sadd"
	CmdSave                       = "Save"
	CmdScan                       = "Scan"
	CmdScard                      = "Scard"
	CmdScriptDebug                = "ScriptDebug"
	CmdScriptExists               = "ScriptExists"
	CmdScriptFlush                = "ScriptFlush"
	CmdScriptKill                 = "ScriptKill"
	CmdScriptLoad                 = "ScriptLoad"
	CmdSdiff                      = "Sdiff"
	CmdSdiffstore                 = "Sdiffstore"
	CmdSelect                     = "Select"
	CmdSet                        = "Set"
	CmdSetEx                      = "SetEx"
	CmdSetExNx                    = "SetExNx"
	CmdSetExXx                    = "SetExXx"
	CmdSetNx                      = "SetNx"
	CmdSetPx                      = "SetPx"
	CmdSetPxNx                    = "SetPxNx"
	CmdSetPxXx                    = "SetPxXx"
	CmdSetXx                      = "SetXx"
	CmdSetbit                     = "Setbit"
	CmdSetrange                   = "Setrange"
	CmdShutdown                   = "Shutdown"
	CmdSinter                     = "Sinter"
	CmdSinterstore                = "Sinterstore"
	CmdSismember                  = "Sismember"
	CmdSlowlogGet                 = "SlowlogGet"
	CmdSlowlogLen                 = "SlowlogLen"
	CmdSlowlogReset               = "SlowlogReset"
	CmdSmembers                   = "Smembers"
	CmdSmove                      = "Smove"
	CmdSort                       = "Sort"
	CmdSpop                       = "Spop"
	CmdSrandmember                = "Srandmember"
	CmdSrem                       = "Srem"
	CmdSscan                      = "Sscan"
	CmdStrlen                     = "Strlen"
	CmdSubscribe                  = "Subscribe"
	CmdSunion                     = "Sunion"
	CmdSunionstore                = "Sunionstore"
	CmdSwapdb                     = "Swapdb"
	CmdTTL                        = "TTL"
	CmdTime                       = "Time"
	CmdTouch                      = "Touch"
	CmdType                       = "Type"
	CmdUnlink                     = "Unlink"
	CmdUnsubscribe                = "Unsubscribe"
	CmdUnwatch                    = "Unwatch"
	CmdWait                       = "Wait"
	CmdWatch                      = "Watch"
	CmdXack                       = "Xack"
	CmdXadd                       = "Xadd"
	CmdXclaim                     = "Xclaim"
	CmdXdel                       = "Xdel"
	CmdXgroupCreate               = "XgroupCreate"
	CmdXgroupDelconsumer          = "XgroupDelconsumer"
	CmdXgroupDestroy              = "XgroupDestroy"
	CmdXgroupHelp                 = "XgroupHelp"
	CmdXgroupSetid                = "XgroupSetid"
	CmdXinfoConsumers             = "XinfoConsumers"
	CmdXinfoGroups                = "XinfoGroups"
	CmdXinfoHelp                  = "XinfoHelp"
	CmdXinfoStream                = "XinfoStream"
	CmdXlen                       = "Xlen"
	CmdXpending                   = "Xpending"
	CmdXrange                     = "Xrange"
	CmdXread                      = "Xread"
	CmdXreadgroup                 = "Xreadgroup"
	CmdXrevrange                  = "Xrevrange"
	CmdXtrim                      = "Xtrim"
	CmdZadd                       = "Zadd"
	CmdZaddCh                     = "ZaddCh"
	CmdZaddNx                     = "ZaddNx"
	CmdZaddXx                     = "ZaddXx"
	CmdZaddXxCh                   = "ZaddXxCh"
	CmdZcard                      = "Zcard"
	CmdZcount                     = "Zcount"
	CmdZincrby                    = "Zincrby"
	CmdZinterstore                = "Zinterstore"
	CmdZlexcount                  = "Zlexcount"
	CmdZpopmax                    = "Zpopmax"
	CmdZpopmin                    = "Zpopmin"
	CmdZrange                     = "Zrange"
	CmdZrangebylex                = "Zrangebylex"
	CmdZrangebyscore              = "Zrangebyscore"
	CmdZrank                      = "Zrank"
	CmdZrem                       = "Zrem"
	CmdZremrangebylex             = "Zremrangebylex"
	CmdZremrangebyrank            = "Zremrangebyrank"
	CmdZremrangebyscore           = "Zremrangebyscore"
	CmdZrevrange                  = "Zrevrange"
	CmdZrevrangebylex             = "Zrevrangebylex"
	CmdZrevrangebyscore           = "Zrevrangebyscore"
	CmdZrevrank                   = "Zrevrank"
	CmdZscan                      = "Zscan"
	CmdZscore                     = "Zscore"
	CmdZunionstore                = "Zunionstore"
)
View Source
const (
	ReplyOK     = "OK"
	ReplyQueued = "QUEUED"
)

Redis reply constants.

Variables

View Source
var (
	// InfPos can be used as infinite positive value for Zfloat64 parameters.
	InfPos = Zclose(math.Inf(+1))
	// InfNeg can be used as infinite negative value for Zfloat64 parameters.
	InfNeg = Zclose(math.Inf(-1))
)
View Source
var CommandNames = []string{} /* 282 elements not displayed */
View Source
var ErrInShutdown = errors.New("connection is shutdown")

ErrInShutdown is returned by a command executed during client is in shutdown status.

View Source
var ErrNotFlushed = errors.New("pipeline: not flushed")

ErrNotFlushed is returned by a command executed in a unflushed pipeline.

View Source
var ErrTimeout = errors.New("timeout while waiting for result")

ErrTimeout is returned by a command after timeout is reached before a async Redis result is available.

View Source
var Groups = map[string][]string{GroupCluster: {CmdClusterAddslots, CmdClusterBumpepoch, CmdClusterCountFailureReports, CmdClusterCountkeysinslot, CmdClusterDelslots, CmdClusterFailover, CmdClusterFlushslots, CmdClusterForget, CmdClusterGetkeysinslot, CmdClusterInfo, CmdClusterKeyslot, CmdClusterMeet, CmdClusterMyid, CmdClusterNodes, CmdClusterReplicas, CmdClusterReplicate, CmdClusterReset, CmdClusterSaveconfig, CmdClusterSetConfigEpoch, CmdClusterSetslotImporting, CmdClusterSetslotMigrating, CmdClusterSetslotNode, CmdClusterSetslotStable, CmdClusterSlaves, CmdClusterSlots, CmdReadonly, CmdReadwrite}, GroupConnection: {CmdAclCat, CmdAclDeluser, CmdAclGenpass, CmdAclGetuser, CmdAclHelp, CmdAclList, CmdAclLoad, CmdAclSave, CmdAclSetuser, CmdAclUsers, CmdAclWhoami, CmdAuth, CmdEcho, CmdHello, CmdPing, CmdQuit, CmdSelect, CmdSwapdb}, GroupGeneric: {CmdDel, CmdDo, CmdDump, CmdExists, CmdExpire, CmdExpireat, CmdKeys, CmdMigrate, CmdMove, CmdObjectEncoding, CmdObjectFreq, CmdObjectHelp, CmdObjectIdletime, CmdObjectRefcount, CmdPTTL, CmdPersist, CmdPexpire, CmdPexpireat, CmdRandomkey, CmdRename, CmdRenameNx, CmdRestore, CmdScan, CmdSort, CmdTTL, CmdTouch, CmdType, CmdUnlink, CmdWait}, GroupGeo: {CmdGeoadd, CmdGeodist, CmdGeohash, CmdGeopos, CmdGeoradius, CmdGeoradiusbymember}, GroupHash: {CmdHdel, CmdHexists, CmdHget, CmdHgetall, CmdHincrby, CmdHincrbyfloat, CmdHkeys, CmdHlen, CmdHmget, CmdHscan, CmdHset, CmdHsetNx, CmdHstrlen, CmdHvals}, GroupHyperloglog: {CmdPfadd, CmdPfcount, CmdPfmerge}, GroupList: {CmdBlpop, CmdBrpop, CmdBrpoplpush, CmdLindex, CmdLinsert, CmdLlen, CmdLpop, CmdLpush, CmdLpushx, CmdLrange, CmdLrem, CmdLset, CmdLtrim, CmdRpop, CmdRpoplpush, CmdRpush, CmdRpushx}, GroupPubsub: {CmdPsubscribe, CmdPublish, CmdPubsubChannels, CmdPubsubNumpat, CmdPubsubNumsub, CmdPunsubscribe, CmdSubscribe, CmdUnsubscribe}, GroupScripting: {CmdEval, CmdEvalsha, CmdScriptDebug, CmdScriptExists, CmdScriptFlush, CmdScriptKill, CmdScriptLoad}, GroupServer: {CmdBgrewriteaof, CmdBgsave, CmdClientGetname, CmdClientId, CmdClientKill, CmdClientList, CmdClientPause, CmdClientReply, CmdClientSetname, CmdClientTracking, CmdClientUnblock, CmdCommand, CmdCommandCount, CmdCommandGetkeys, CmdCommandInfo, CmdConfigGet, CmdConfigResetstat, CmdConfigRewrite, CmdConfigSet, CmdDbsize, CmdDebugObject, CmdDebugSegfault, CmdFlushall, CmdFlushdb, CmdInfo, CmdLastsave, CmdLatencyDoctor, CmdLatencyGraph, CmdLatencyHelp, CmdLatencyHistory, CmdLatencyLatest, CmdLatencyReset, CmdLolwut, CmdMemoryDoctor, CmdMemoryHelp, CmdMemoryMallocStats, CmdMemoryPurge, CmdMemoryStats, CmdMemoryUsage, CmdModuleList, CmdModuleLoad, CmdModuleUnload, CmdMonitor, CmdPsync, CmdReplicaof, CmdRole, CmdSave, CmdShutdown, CmdSlowlogGet, CmdSlowlogLen, CmdSlowlogReset, CmdTime}, GroupSet: {CmdSadd, CmdScard, CmdSdiff, CmdSdiffstore, CmdSinter, CmdSinterstore, CmdSismember, CmdSmembers, CmdSmove, CmdSpop, CmdSrandmember, CmdSrem, CmdSscan, CmdSunion, CmdSunionstore}, GroupSortedSet: {CmdBzpopmax, CmdBzpopmin, CmdZadd, CmdZaddCh, CmdZaddNx, CmdZaddXx, CmdZaddXxCh, CmdZcard, CmdZcount, CmdZincrby, CmdZinterstore, CmdZlexcount, CmdZpopmax, CmdZpopmin, CmdZrange, CmdZrangebylex, CmdZrangebyscore, CmdZrank, CmdZrem, CmdZremrangebylex, CmdZremrangebyrank, CmdZremrangebyscore, CmdZrevrange, CmdZrevrangebylex, CmdZrevrangebyscore, CmdZrevrank, CmdZscan, CmdZscore, CmdZunionstore}, GroupStream: {CmdXack, CmdXadd, CmdXclaim, CmdXdel, CmdXgroupCreate, CmdXgroupDelconsumer, CmdXgroupDestroy, CmdXgroupHelp, CmdXgroupSetid, CmdXinfoConsumers, CmdXinfoGroups, CmdXinfoHelp, CmdXinfoStream, CmdXlen, CmdXpending, CmdXrange, CmdXread, CmdXreadgroup, CmdXrevrange, CmdXtrim}, GroupString: {CmdAppend, CmdBitcount, CmdBitfield, CmdBitopAnd, CmdBitopNot, CmdBitopOr, CmdBitopXor, CmdBitpos, CmdDecr, CmdDecrby, CmdGet, CmdGetbit, CmdGetrange, CmdGetset, CmdIncr, CmdIncrby, CmdIncrbyfloat, CmdMget, CmdMset, CmdMsetNx, CmdSet, CmdSetEx, CmdSetExNx, CmdSetExXx, CmdSetNx, CmdSetPx, CmdSetPxNx, CmdSetPxXx, CmdSetXx, CmdSetbit, CmdSetrange, CmdStrlen}, GroupTransactions: {CmdDiscard, CmdExec, CmdMulti, CmdUnwatch, CmdWatch}}

Functions

func Int64Ptr

func Int64Ptr(i int64) *int64

Int64Ptr returns a pointer to the int64 parameter.

func RandomKey

func RandomKey(key string) string

RandomKey returns key + base64 encoded random bytes. Used for tests to avoid key overwrites on Redis server.

func StringPtr

func StringPtr(s string) *string

StringPtr returns a pointer to the string parameter.

Types

type Aggregate

type Aggregate string
const (
	AggregateSum Aggregate = "SUM"
	AggregateMin Aggregate = "MIN"
	AggregateMax Aggregate = "MAX"
)

type Booler

type Booler interface {
	// ToBooler converts a redis value to a bool.
	// In case the conversion is not supported a ConversionError is returned.
	ToBool() (bool, error)
}

Booler is implemented by any redis value that has a ToBool method.

type Cache

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

Cache is a key cache supporting Redis client side caching.

func NewCache

func NewCache() *Cache

NewCache creates a new ClientCache instance.

func NewCacheSize

func NewCacheSize(size int) *Cache

NewCacheSize creates a new ClientCache instance with size slot entries.

func (*Cache) Get

func (c *Cache) Get(key string) (RedisValue, bool)

Get reads the value of a key from the cache.

func (*Cache) Put

func (c *Cache) Put(key string, value RedisValue)

Put inserts a key into the cache.

type Clienttype

type Clienttype string
const (
	ClienttypeNormal  Clienttype = "normal"
	ClienttypeMaster  Clienttype = "master"
	ClienttypeReplica Clienttype = "replica"
	ClienttypePubsub  Clienttype = "pubsub"
)

type ClusterCommands

type ClusterCommands interface {
	ClusterAddslots(slot []int64) Result
	ClusterBumpepoch() Result
	ClusterCountFailureReports(nodeId string) Result
	ClusterCountkeysinslot(slot int64) Result
	ClusterDelslots(slot []int64) Result
	ClusterFailover(force *bool) Result
	ClusterFlushslots() Result
	ClusterForget(nodeId string) Result
	ClusterGetkeysinslot(slot, count int64) Result
	ClusterInfo() Result
	ClusterKeyslot(key string) Result
	ClusterMeet(ip string, port int64) Result
	ClusterMyid() Result
	ClusterNodes() Result
	ClusterReplicas(nodeId string) Result
	ClusterReplicate(nodeId string) Result
	ClusterReset(hard *bool) Result
	ClusterSaveconfig() Result
	ClusterSetConfigEpoch(configEpoch int64) Result
	ClusterSetslotImporting(slot int64, sourceNodeId string) Result
	ClusterSetslotMigrating(slot int64, destNodeId string) Result
	ClusterSetslotNode(slot int64, nodeId string) Result
	ClusterSetslotStable(slot int64) Result
	ClusterSlaves(nodeId string) Result
	ClusterSlots() Result
	Readonly() Result
	Readwrite() Result
}

type Conn

type Conn interface {
	Commands
	Pipeline() Pipeline
	Close() error
}

Conn represents the redis network connection.

Example (Tracing)
package main

import (
	"fmt"
	"log"
	"strconv"

	"github.com/d024441/go-resp3/client"
)

func trace(dir bool, b []byte) {
	if dir { // Example: print sent commands only.
		fmt.Println(strconv.Quote(string(b)))
	}
}

func main() {
	// Create connetion providing trace callback.
	dialer := client.Dialer{TraceCallback: trace}
	conn, err := dialer.Dial("")
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close()

	if err := conn.Set("mykey", "Hello Redis").Err(); err != nil {
		log.Fatal(err)
	}
	if err := conn.Get("mykey").Err(); err != nil {
		log.Fatal(err)
	}
}
Output:

"*2\r\n$5\r\nHELLO\r\n$1\r\n3\r\n"
"*3\r\n$3\r\nSET\r\n$5\r\nmykey\r\n$11\r\nHello Redis\r\n"
"*2\r\n$3\r\nGET\r\n$5\r\nmykey\r\n"
"*1\r\n$4\r\nQUIT\r\n"

func Dial

func Dial(address string) (Conn, error)

Dial connects to the redis server address.

func DialContext

func DialContext(ctx context.Context, address string) (Conn, error)

DialContext connects to the redis server address using the provided context.

type ConnectionCommands

type ConnectionCommands interface {
	AclCat(category *string) Result
	AclDeluser(username []string) Result
	AclGenpass() Result
	AclGetuser(username string) Result
	AclHelp() Result
	AclList() Result
	AclLoad() Result
	AclSave() Result
	AclSetuser(username string, rules []string) Result
	AclUsers() Result
	AclWhoami() Result
	Auth(username *string, password string) Result
	Echo(message string) Result
	Hello(version string, userPassword *UserPassword, clientName *string) Result
	Ping(message *string) Result
	Quit() Result
	Select(index int64) Result
	Swapdb(index1, index2 int64) Result
}

type ConversionError

type ConversionError struct {
	To    string
	Value interface{}
}

A ConversionError is raised for an unsuccessful type conversion of a redis value. - To: Name of the conversion function. - Value: Value for which the conversion was not successful.

func (*ConversionError) Error

func (e *ConversionError) Error() string

type Converter

Converter is the interface that groups Redis value conversion interfaces.

type Decoder

type Decoder interface {
	Decode() (interface{}, error)
}

Decoder is the interface that wraps the Decode method.

func NewDecoder

func NewDecoder(r io.Reader) Decoder

NewDecoder returns a Decoder for Redis results.

type Dialer

type Dialer struct {
	net.Dialer
	// TLS
	TLSConfig *tls.Config
	// Connection logging.
	Logger *log.Logger
	// Channel size for asynchronous result reader and handler.
	ChannelSize int
	// Duration to wait for async results before timeout.
	AsyncTimeout time.Duration
	// Redis authentication.
	User, Password string
	// Redis client name.
	ClientName string
	// Client cache.
	Cache *Cache
	// Monitor callback.
	MonitorCallback MonitorCallback
	// Callback function tracing Redis commands and results on RESP3 protocol level.
	// Direction dir is true for sent bytes b (commands), false for received bytes b (results).
	TraceCallback TraceCallback
	// Command interceptor (debugging).
	SendInterceptor SendInterceptor
}

Dialer contains options for connecting to a redis server.

func (*Dialer) Dial

func (d *Dialer) Dial(address string) (Conn, error)

Dial connects to the redis server address.

func (*Dialer) DialContext

func (d *Dialer) DialContext(ctx context.Context, address string) (Conn, error)

DialContext connects to the redis server address using the provided context.

type Encoder

type Encoder interface {
	Encode([]interface{}) error
	Flush() error
}

Encoder is the interface that wraps the Encode method.

Encode is not a general redis encoder but encodes redis commands only. Redis commands are send as ARRAY of BULK STRINGS. Encode is encoding all elements of v to BULK STRINGS. In case an element is a not suported type, Encode will panic.

func NewEncoder

func NewEncoder(w io.Writer) Encoder

NewEncoder returns an Encoder for redis commands.

type FieldValue

type FieldValue struct {
	Field interface{}
	Value interface{}
}

type Float64er

type Float64er interface {
	// ToFloat64 converts a redis value to a float64.
	// In case the conversion is not supported a ConversionError is returned.
	ToFloat64() (float64, error)
}

Float64er is implemented by any redis value that has a ToFloat64 method.

type GenericCommands

type GenericCommands interface {
	Del(key []interface{}) Result
	Do(v ...interface{}) Result
	Dump(key interface{}) Result
	Exists(key []interface{}) Result
	Expire(key interface{}, seconds int64) Result
	Expireat(key interface{}, timestamp int64) Result
	Keys(pattern string) Result
	Migrate(host, port string, key interface{}, destinationDb, timeout int64, copy, replace bool, auth *string, keys []interface{}) Result
	Move(key interface{}, db int64) Result
	ObjectEncoding(key interface{}) Result
	ObjectFreq(key interface{}) Result
	ObjectHelp() Result
	ObjectIdletime(key interface{}) Result
	ObjectRefcount(key interface{}) Result
	PTTL(key interface{}) Result
	Persist(key interface{}) Result
	Pexpire(key interface{}, milliseconds int64) Result
	Pexpireat(key interface{}, millisecondsTimestamp int64) Result
	Randomkey() Result
	Rename(key, newkey interface{}) Result
	RenameNx(key, newkey interface{}) Result
	Restore(key interface{}, ttl int64, serializedValue string, replace, absttl bool, idletime, freq *int64) Result
	Scan(cursor int64, match *string, count *int64, typ *string) Result
	Sort(key interface{}, by *string, limit *OffsetCount, get []string, asc *bool, sorting bool, store *interface{}) Result
	TTL(key interface{}) Result
	Touch(key []interface{}) Result
	Type(key interface{}) Result
	Unlink(key []interface{}) Result
	Wait(numreplicas, timeout int64) Result
}

type GeoCommands

type GeoCommands interface {
	Geoadd(key interface{}, longitudeLatitudeMember []LongitudeLatitudeMember) Result
	Geodist(key, member1, member2 interface{}, unit *Unit) Result
	Geohash(key interface{}, member []interface{}) Result
	Geopos(key interface{}, member []interface{}) Result
	Georadius(key interface{}, longitude, latitude, radius float64, unit Unit, withcoord, withdist, withhash bool, count *int64, asc *bool, store, storedist *interface{}) Result
	Georadiusbymember(key, member interface{}, radius float64, unit Unit, withcoord, withdist, withhash bool, count *int64, asc *bool, store, storedist *interface{}) Result
}

type GroupConsumer

type GroupConsumer struct {
	Group    string
	Consumer string
}

type HashCommands

type HashCommands interface {
	Hdel(key interface{}, field []interface{}) Result
	Hexists(key, field interface{}) Result
	Hget(key, field interface{}) Result
	Hgetall(key interface{}) Result
	Hincrby(key, field interface{}, increment int64) Result
	Hincrbyfloat(key, field interface{}, increment float64) Result
	Hkeys(key interface{}) Result
	Hlen(key interface{}) Result
	Hmget(key interface{}, field []interface{}) Result
	Hscan(key interface{}, cursor int64, match *string, count *int64) Result
	Hset(key interface{}, fieldValue []FieldValue) Result
	HsetNx(key, field, value interface{}) Result
	Hstrlen(key, field interface{}) Result
	Hvals(key interface{}) Result
}

type HyperloglogCommands

type HyperloglogCommands interface {
	Pfadd(key interface{}, element []interface{}) Result
	Pfcount(key []interface{}) Result
	Pfmerge(destkey interface{}, sourcekey []interface{}) Result
}

type IDMap

type IDMap struct {
	ID  string
	Map map[string]string
}

IDMap represents the id and the field value mapping of streams.

type Int64Slicer

type Int64Slicer interface {
	// ToInt64Slice returns a slice with values of type int64. In case value conversion to string is not possible
	// a ConversitionError is returned.
	ToInt64Slice() ([]int64, error)
}

Int64Slicer is implemented by any redis value that has a ToInt64Slice method.

type Int64er

type Int64er interface {
	// ToInt64 converts a redis value to an int64.
	// In case the conversion is not supported a ConversionError is returned.
	ToInt64() (int64, error)
}

Int64er is implemented by any redis value that has a ToInt64 method.

type InvalidBigNumberError

type InvalidBigNumberError struct {
	Value string
}

An InvalidBigNumberError is raised by decoding a bignumber including unexpected characters.

func (*InvalidBigNumberError) Error

func (e *InvalidBigNumberError) Error() string

type InvalidDoubleError

type InvalidDoubleError struct {
	Value string
}

An InvalidDoubleError is raised by decoding a double including unexpected characters.

func (*InvalidDoubleError) Error

func (e *InvalidDoubleError) Error() string

type InvalidNumberError

type InvalidNumberError struct {
	Value string
}

An InvalidNumberError is raised by decoding a number including unexpected characters.

func (*InvalidNumberError) Error

func (e *InvalidNumberError) Error() string

type InvalidTypeError

type InvalidTypeError struct {
	Value interface{}
}

An InvalidTypeError is raised by encoding an unsupported value type.

func (*InvalidTypeError) Error

func (e *InvalidTypeError) Error() string

type InvalidValueError

type InvalidValueError struct {
	Name  string
	Value interface{}
}

A InvalidValueError is raised by a redis commend provided with an invalid parameter value. - Name: Parameter name. - Value: Invalid value.

func (*InvalidValueError) Error

func (e *InvalidValueError) Error() string

type Key

type Key string

Key provides methods to calculate Redis crc64 hash and client caching slot.

func (Key) CRC64

func (k Key) CRC64() uint64

CRC64 returns the Redis crc64 hash value of key.

func (Key) Slot

func (k Key) Slot() uint32

Slot returns the Redis client caching slot for key.

type KeyValue

type KeyValue struct {
	Key   interface{}
	Value interface{}
}

type ListCommands

type ListCommands interface {
	Blpop(key []interface{}, timeout int64) Result
	Brpop(key []interface{}, timeout int64) Result
	Brpoplpush(source, destination interface{}, timeout int64) Result
	Lindex(key interface{}, index int64) Result
	Linsert(key interface{}, before bool, pivot, element interface{}) Result
	Llen(key interface{}) Result
	Lpop(key interface{}) Result
	Lpush(key interface{}, element []interface{}) Result
	Lpushx(key interface{}, element []interface{}) Result
	Lrange(key interface{}, start, stop int64) Result
	Lrem(key interface{}, count int64, element interface{}) Result
	Lset(key interface{}, index int64, element interface{}) Result
	Ltrim(key interface{}, start, stop int64) Result
	Rpop(key interface{}) Result
	Rpoplpush(source, destination interface{}) Result
	Rpush(key interface{}, element []interface{}) Result
	Rpushx(key interface{}, element []interface{}) Result
}

type LongitudeLatitudeMember

type LongitudeLatitudeMember struct {
	Longitude float64
	Latitude  float64
	Member    interface{}
}

type Map

type Map []MapItem

A Map represents the redis map type.

func (Map) Attr

func (m Map) Attr() *Map

func (Map) Kind

func (m Map) Kind() RedisKind

Kind returns the type of a Map.

func (Map) ToBool

func (m Map) ToBool() (bool, error)

func (Map) ToFloat64

func (m Map) ToFloat64() (float64, error)

func (Map) ToInt64

func (m Map) ToInt64() (int64, error)

func (Map) ToInt64Slice

func (m Map) ToInt64Slice() ([]int64, error)

func (Map) ToSlice

func (m Map) ToSlice() ([]interface{}, error)

func (Map) ToSlice2

func (m Map) ToSlice2() ([][]interface{}, error)

func (Map) ToString

func (m Map) ToString() (string, error)

func (Map) ToStringInt64Map

func (m Map) ToStringInt64Map() (map[string]int64, error)

ToStringInt64Map returns a map with keys of type string and values of type int64. In case key or value conversion is not possible a ConvertionError is returned.

func (Map) ToStringMap

func (m Map) ToStringMap() (map[string]interface{}, error)

ToStringMap returns a map with keys of type string. In case key conversion to string is not possible a ConvertionError is returned.

func (Map) ToStringMapSlice

func (m Map) ToStringMapSlice() ([]map[string]interface{}, error)

func (Map) ToStringSet

func (m Map) ToStringSet() (map[string]bool, error)

func (Map) ToStringSlice

func (m Map) ToStringSlice() ([]string, error)

func (Map) ToStringStringMap

func (m Map) ToStringStringMap() (map[string]string, error)

ToStringStringMap returns a map with keys and values of type string. In case key or value conversion to string is not possible a ConvertionError is returned.

func (Map) ToTree

func (m Map) ToTree() ([]interface{}, error)

func (Map) ToXrange

func (m Map) ToXrange() ([]IDMap, error)

func (Map) ToXread

func (m Map) ToXread() (map[string][]IDMap, error)

ToXread returns a map[string] with values of type IdMap. In case the conversion is not possible a ConversitionError is returned.

type MapItem

type MapItem struct {
	Key   RedisValue
	Value RedisValue
}

A MapItem represents the redis map type key and value.

type Mode

type Mode string
const (
	ModeYes  Mode = "YES"
	ModeSync Mode = "SYNC"
	ModeNo   Mode = "NO"
)

type MonitorCallback

type MonitorCallback func(time time.Time, db int64, addr string, cmds []string)

MonitorCallback is the function type for the Redis monitor callback function.

type MsgCallback

type MsgCallback func(pattern, channel, msg string)

MsgCallback is the function type for Redis pubsub message callback functions.

type OffsetCount

type OffsetCount struct {
	Offset int64
	Count  int64
}

type Overflow

type Overflow string
const (
	OverflowWrap Overflow = "WRAP"
	OverflowSat  Overflow = "SAT"
	OverflowFail Overflow = "FAIL"
)

type Pipeline

type Pipeline interface {
	Commands
	Reset()
	Flush() error
}

Pipeline supports redis pipelining capabilities. Multiple goroutines must not invoke methods on a Pipeline simultaneously.

type PubsubCommands

type PubsubCommands interface {
	Psubscribe(pattern []string, cb MsgCallback) Result
	Publish(channel, message string) Result
	PubsubChannels(pattern *string) Result
	PubsubNumpat() Result
	PubsubNumsub(channel []string) Result
	Punsubscribe(pattern []string) Result
	Subscribe(channel []string, cb MsgCallback) Result
	Unsubscribe(channel []string) Result
}

type RedisError

type RedisError struct {
	Code string
	Msg  string
}

A RedisError represents the redis error message if a redis command was executed unsuccessfully.

func (*RedisError) Error

func (e *RedisError) Error() string

type RedisKind

type RedisKind byte

RedisKind represents the kind of type that a RedisValue represents.

const (
	RkInvalid RedisKind = iota
	RkError
	RkPush
	RkNull
	RkString
	RkVerbatimString
	RkNumber
	RkDouble
	RkBigNumber
	RkBoolean
	RkSlice
	RkMap
	RkSet
)

RedisKind constants.

type RedisValue

type RedisValue interface {
	Kind() RedisKind
	Attr() *Map
	Converter
}

RedisValue represents a Redis command reply value.

type ReplyMode

type ReplyMode string
const (
	ReplyModeOn   ReplyMode = "ON"
	ReplyModeOff  ReplyMode = "OFF"
	ReplyModeSkip ReplyMode = "SKIP"
)

type Result

type Result interface {
	// Attr returns the attribute of a Redis value if provided - <nil> otherwise.
	Attr() (*Map, error)
	// Err returns any of the following errors:
	// - <nil>: result received successfully.
	// - ErrNotFlushed: result not received yet (pipeline not flushed).
	// - ErrTimeout: timeout reached before result is available.
	// - RedisError: redis error message if a redis command was executed unsuccessfully.
	Err() error
	// IsNull returns <true> if the redis value is null.
	IsNull() (bool, error)
	// Kind returns the type of a Redis value.
	Kind() (RedisKind, error)
	// Value returns a Redis value.
	Value() (RedisValue, error)
	// VerbatimString returns a VerbatimString if the Redis type is a verbatim string.
	VerbatimString() (VerbatimString, error)
	// Map returns a Map if the Redis type is a map.
	Map() (Map, error)
	// Set returns a Set if the Redis type is a set.
	Set() (Set, error)
	// Slice returns a Slice if the Redis type is an array.
	Slice() (Slice, error)

	// Conversion methods.
	Converter
}

Result represents a redis command result.

type ScoreMember

type ScoreMember struct {
	Score  float64
	Member interface{}
}

type ScriptingCommands

type ScriptingCommands interface {
	Eval(script string, numkeys int64, key, arg []interface{}) Result
	Evalsha(sha1 string, numkeys int64, key, arg []interface{}) Result
	ScriptDebug(mode Mode) Result
	ScriptExists(sha1 []string) Result
	ScriptFlush() Result
	ScriptKill() Result
	ScriptLoad(script string) Result
}

type SendInterceptor

type SendInterceptor func(name string, values []interface{})

SendInterceptor is the function type for the send interceptor function.

type ServerCommands

type ServerCommands interface {
	Bgrewriteaof() Result
	Bgsave() Result
	ClientGetname() Result
	ClientId() Result
	ClientKill(id *int64, typ *Clienttype, addr *string, skipme bool) Result
	ClientList(typ *Clienttype) Result
	ClientPause(timeout int64) Result
	ClientReply(replyMode ReplyMode) Result
	ClientSetname(connectionName string) Result
	ClientTracking(on bool, redirect *int64) Result
	ClientUnblock(clientId int64, timeout *bool) Result
	Command() Result
	CommandCount() Result
	CommandGetkeys(arg []interface{}) Result
	CommandInfo(commandName []string) Result
	ConfigGet(parameter string) Result
	ConfigResetstat() Result
	ConfigRewrite() Result
	ConfigSet(parameter, value string) Result
	Dbsize() Result
	DebugObject(key interface{}) Result
	DebugSegfault() Result
	Flushall(async bool) Result
	Flushdb(async bool) Result
	Info(section *string) Result
	Lastsave() Result
	LatencyDoctor() Result
	LatencyGraph(event string) Result
	LatencyHelp() Result
	LatencyHistory(event string) Result
	LatencyLatest() Result
	LatencyReset(event *string) Result
	Lolwut(version *int64) Result
	MemoryDoctor() Result
	MemoryHelp() Result
	MemoryMallocStats() Result
	MemoryPurge() Result
	MemoryStats() Result
	MemoryUsage(key interface{}, samples *int64) Result
	ModuleList() Result
	ModuleLoad(path string, arg []string) Result
	ModuleUnload(name string) Result
	Monitor() Result
	Psync(replicationid, offset int64) Result
	Replicaof(host, port string) Result
	Role() Result
	Save() Result
	Shutdown(nosave *bool) Result
	SlowlogGet(count *int64) Result
	SlowlogLen() Result
	SlowlogReset() Result
	Time() Result
}

type Set

type Set []RedisValue

A Set represents the redis set type.

func (Set) Attr

func (s Set) Attr() *Map

func (Set) Kind

func (s Set) Kind() RedisKind

Kind returns the type of a Set.

func (Set) ToBool

func (s Set) ToBool() (bool, error)

func (Set) ToFloat64

func (s Set) ToFloat64() (float64, error)

func (Set) ToInt64

func (s Set) ToInt64() (int64, error)

func (Set) ToInt64Slice

func (s Set) ToInt64Slice() ([]int64, error)

func (Set) ToSlice

func (s Set) ToSlice() ([]interface{}, error)

func (Set) ToSlice2

func (s Set) ToSlice2() ([][]interface{}, error)

func (Set) ToString

func (s Set) ToString() (string, error)

func (Set) ToStringInt64Map

func (s Set) ToStringInt64Map() (map[string]int64, error)

func (Set) ToStringMap

func (s Set) ToStringMap() (map[string]interface{}, error)

func (Set) ToStringMapSlice

func (s Set) ToStringMapSlice() ([]map[string]interface{}, error)

func (Set) ToStringSet

func (s Set) ToStringSet() (map[string]bool, error)

ToStringSet returns a map with keys of type string and boolean true values. In case key conversion to string is not possible a ConvertionError is returned.

func (Set) ToStringSlice

func (s Set) ToStringSlice() ([]string, error)

func (Set) ToStringStringMap

func (s Set) ToStringStringMap() (map[string]string, error)

func (Set) ToTree

func (s Set) ToTree() ([]interface{}, error)

func (Set) ToXrange

func (s Set) ToXrange() ([]IDMap, error)

func (Set) ToXread

func (s Set) ToXread() (map[string][]IDMap, error)

type SetCommands

type SetCommands interface {
	Sadd(key interface{}, member []interface{}) Result
	Scard(key interface{}) Result
	Sdiff(key []interface{}) Result
	Sdiffstore(destination interface{}, key []interface{}) Result
	Sinter(key []interface{}) Result
	Sinterstore(destination interface{}, key []interface{}) Result
	Sismember(key, member interface{}) Result
	Smembers(key interface{}) Result
	Smove(source, destination, member interface{}) Result
	Spop(key interface{}, count *int64) Result
	Srandmember(key interface{}, count *int64) Result
	Srem(key interface{}, member []interface{}) Result
	Sscan(key interface{}, cursor int64, match *string, count *int64) Result
	Sunion(key []interface{}) Result
	Sunionstore(destination interface{}, key []interface{}) Result
}

type Slice

type Slice []RedisValue

A Slice represents the redis slice type.

func (Slice) Attr

func (s Slice) Attr() *Map

func (Slice) Kind

func (s Slice) Kind() RedisKind

Kind returns the type of a Slice.

func (Slice) ToBool

func (s Slice) ToBool() (bool, error)

func (Slice) ToFloat64

func (s Slice) ToFloat64() (float64, error)

func (Slice) ToInt64

func (s Slice) ToInt64() (int64, error)

func (Slice) ToInt64Slice

func (s Slice) ToInt64Slice() ([]int64, error)

ToInt64Slice returns a slice with values of type int64. In case value conversion to string is not possible a ConversitionError is returned.

func (Slice) ToSlice

func (s Slice) ToSlice() ([]interface{}, error)

ToSlice returns a slice with values of type interface{}.

func (Slice) ToSlice2

func (s Slice) ToSlice2() ([][]interface{}, error)

ToSlice2 returns a slice with values of type []interface{}. In case value conversion to []interface{} is not possible a ConversitionError is returned.

func (Slice) ToString

func (s Slice) ToString() (string, error)

func (Slice) ToStringInt64Map

func (s Slice) ToStringInt64Map() (map[string]int64, error)

func (Slice) ToStringMap

func (s Slice) ToStringMap() (map[string]interface{}, error)

func (Slice) ToStringMapSlice

func (s Slice) ToStringMapSlice() ([]map[string]interface{}, error)

ToStringMapSlice returns a slice with values of type map[string]interfcae{}. In case value conversion to map[string]interface{} is not possible a ConversitionError is returned.

func (Slice) ToStringSet

func (s Slice) ToStringSet() (map[string]bool, error)

func (Slice) ToStringSlice

func (s Slice) ToStringSlice() ([]string, error)

ToStringSlice returns a slice with values of type string. In case value conversion to string is not possible a ConversitionError is returned.

func (Slice) ToStringStringMap

func (s Slice) ToStringStringMap() (map[string]string, error)

func (Slice) ToTree

func (s Slice) ToTree() ([]interface{}, error)

ToTree returns a tree with nodes of type []interface{} and leaves of type interface{}. In case value conversion to []interface{} is not possible a ConversitionError is returned.

func (Slice) ToXrange

func (s Slice) ToXrange() ([]IDMap, error)

ToXrange returns a slice with values of type IdMap. In case the conversion is not possible a ConversitionError is returned.

func (Slice) ToXread

func (s Slice) ToXread() (map[string][]IDMap, error)

type Slice2er

type Slice2er interface {
	// ToSlice2 returns a slice with values of type []interface{}. In case value conversion to []interface{} is not possible
	// a ConversitionError is returned.
	ToSlice2() ([][]interface{}, error)
}

Slice2er is implemented by any redis value that has a ToSlice2 method.

type Slicer

type Slicer interface {
	// ToSlice returns a slice with values of type interface{}.
	ToSlice() ([]interface{}, error)
}

Slicer is implemented by any redis value that has a ToSlice method.

type SortedSetCommands

type SortedSetCommands interface {
	Bzpopmax(key []interface{}, timeout int64) Result
	Bzpopmin(key []interface{}, timeout int64) Result
	Zadd(key interface{}, scoreMember []ScoreMember) Result
	ZaddCh(key interface{}, scoreMember []ScoreMember) Result
	ZaddNx(key interface{}, scoreMember []ScoreMember) Result
	ZaddXx(key interface{}, scoreMember []ScoreMember) Result
	ZaddXxCh(key interface{}, scoreMember []ScoreMember) Result
	Zcard(key interface{}) Result
	Zcount(key interface{}, min, max Zfloat64) Result
	Zincrby(key interface{}, increment float64, member interface{}) Result
	Zinterstore(destination interface{}, numkeys int64, key []interface{}, weights []int64, aggregate *Aggregate) Result
	Zlexcount(key interface{}, min, max string) Result
	Zpopmax(key interface{}, count *int64) Result
	Zpopmin(key interface{}, count *int64) Result
	Zrange(key interface{}, start, stop int64, withscores bool) Result
	Zrangebylex(key interface{}, min, max string, limit *OffsetCount) Result
	Zrangebyscore(key interface{}, min, max Zfloat64, withscores bool, limit *OffsetCount) Result
	Zrank(key, member interface{}) Result
	Zrem(key interface{}, member []interface{}) Result
	Zremrangebylex(key interface{}, min, max string) Result
	Zremrangebyrank(key interface{}, start, stop int64) Result
	Zremrangebyscore(key interface{}, min, max Zfloat64) Result
	Zrevrange(key interface{}, start, stop int64, withscores bool) Result
	Zrevrangebylex(key interface{}, max, min string, limit *OffsetCount) Result
	Zrevrangebyscore(key interface{}, max, min Zfloat64, withscores bool, limit *OffsetCount) Result
	Zrevrank(key, member interface{}) Result
	Zscan(key interface{}, cursor int64, match *string, count *int64) Result
	Zscore(key, member interface{}) Result
	Zunionstore(destination interface{}, numkeys int64, key []interface{}, weights []int64, aggregate *Aggregate) Result
}

type StartEnd

type StartEnd struct {
	Start int64
	End   int64
}

type StartEndCount

type StartEndCount struct {
	Start string
	End   string
	Count int64
}

type StreamCommands

type StreamCommands interface {
	Xack(key interface{}, group string, id []string) Result
	Xadd(key interface{}, id string, fieldValue []FieldValue) Result
	Xclaim(key interface{}, group, consumer, minIdleTime string, id []string, idle, time, retrycount *int64, force, justid bool) Result
	Xdel(key interface{}, id []string) Result
	XgroupCreate(key interface{}, groupname, id string, mkstream bool) Result
	XgroupDelconsumer(key interface{}, groupname, consumername string) Result
	XgroupDestroy(key interface{}, groupname string) Result
	XgroupHelp() Result
	XgroupSetid(key interface{}, groupname, id string) Result
	XinfoConsumers(key interface{}, groupname string) Result
	XinfoGroups(key interface{}) Result
	XinfoHelp() Result
	XinfoStream(key interface{}) Result
	Xlen(key interface{}) Result
	Xpending(key interface{}, group string, startEndCount *StartEndCount, consumer *string) Result
	Xrange(key interface{}, start, end string, count *int64) Result
	Xread(count, block *int64, key []interface{}, id []string) Result
	Xreadgroup(group GroupConsumer, count, block *int64, noack bool, key []interface{}, id []string) Result
	Xrevrange(key interface{}, end, start string, count *int64) Result
	Xtrim(key interface{}, approx bool, count int64) Result
}

type StringCommands

type StringCommands interface {
	Append(key, value interface{}) Result
	Bitcount(key interface{}, startEnd *StartEnd) Result
	Bitfield(key interface{}, operation []interface{}) Result
	BitopAnd(destkey interface{}, srckey []interface{}) Result
	BitopNot(destkey, srckey interface{}) Result
	BitopOr(destkey interface{}, srckey []interface{}) Result
	BitopXor(destkey interface{}, srckey []interface{}) Result
	Bitpos(key interface{}, bit int64, start, end *int64) Result
	Decr(key interface{}) Result
	Decrby(key interface{}, decrement int64) Result
	Get(key interface{}) Result
	Getbit(key interface{}, offset int64) Result
	Getrange(key interface{}, start, end int64) Result
	Getset(key, value interface{}) Result
	Incr(key interface{}) Result
	Incrby(key interface{}, increment int64) Result
	Incrbyfloat(key interface{}, increment float64) Result
	Mget(key []interface{}) Result
	Mset(keyValue []KeyValue) Result
	MsetNx(keyValue []KeyValue) Result
	Set(key, value interface{}) Result
	SetEx(key, value interface{}, seconds int64) Result
	SetExNx(key, value interface{}, seconds int64) Result
	SetExXx(key, value interface{}, seconds int64) Result
	SetNx(key, value interface{}) Result
	SetPx(key, value interface{}, milliseconds int64) Result
	SetPxNx(key, value interface{}, milliseconds int64) Result
	SetPxXx(key, value interface{}, milliseconds int64) Result
	SetXx(key, value interface{}) Result
	Setbit(key interface{}, offset, value int64) Result
	Setrange(key interface{}, offset int64, value interface{}) Result
	Strlen(key interface{}) Result
}

type StringInt64Mapper

type StringInt64Mapper interface {
	// ToStringInt64Map returns a map with keys of type string and values of type int64. In case key or value conversion is not possible
	// a ConvertionError is returned.
	ToStringInt64Map() (map[string]int64, error)
}

StringInt64Mapper is implemented by any redis value that has a ToStringInt64Map method.

type StringMapSlicer

type StringMapSlicer interface {
	// ToStringMapSlice returns a slice with values of type map[string]interfcae{}. In case value conversion to map[string]interface{} is not possible
	// a ConversitionError is returned.
	ToStringMapSlice() ([]map[string]interface{}, error)
}

StringMapSlicer is implemented by any redis value that has a ToStringMapSlice method.

type StringMapper

type StringMapper interface {
	// ToStringMap returns a map with keys of type string. In case key conversion to string is not possible
	// a ConvertionError is returned.
	ToStringMap() (map[string]interface{}, error)
}

StringMapper is implemented by any redis value that has a ToStringMap method.

type StringSetter

type StringSetter interface {
	// ToStringSet returns a map with keys of type string and boolean true values. In case key conversion to string is not possible
	// a ConvertionError is returned.
	ToStringSet() (map[string]bool, error)
}

StringSetter is implemented by any redis value that has a ToStringSet method.

type StringSlicer

type StringSlicer interface {
	// ToStringSlice returns a slice with values of type string. In case value conversion to string is not possible
	// a ConversitionError is returned.
	ToStringSlice() ([]string, error)
}

StringSlicer is implemented by any redis value that has a ToStringSlice method.

type StringStringMapper

type StringStringMapper interface {
	// ToStringStringMap returns a map with keys and values of type string. In case key or value conversion to string is not possible
	// a ConvertionError is returned.
	ToStringStringMap() (map[string]string, error)
}

StringStringMapper is implemented by any redis value that has a ToStringStringMap method.

type Stringer

type Stringer interface {
	// ToString converts a redis value to a string.
	// In case the conversion is not supported a ConversionError is returned.
	ToString() (string, error)
}

Stringer is implemented by any redis value that has a ToString method.

type TraceCallback

type TraceCallback func(dir bool, b []byte)

TraceCallback is the function type for the tracing callback function.

type TransactionsCommands

type TransactionsCommands interface {
	Discard() Result
	Exec() Result
	Multi() Result
	Unwatch() Result
	Watch(key []interface{}) Result
}

type Treer

type Treer interface {
	// ToTree returns a tree with nodes of type []interface{} and leaves of type interface{}. In case value conversion to []interface{} is not possible
	// a ConversitionError is returned.
	ToTree() ([]interface{}, error)
}

Treer is implemented by any redis value that has a ToTree method.

type TypeOffset

type TypeOffset struct {
	Type   string
	Offset int64
}

type TypeOffsetIncrement

type TypeOffsetIncrement struct {
	Type      string
	Offset    int64
	Increment int64
}

type TypeOffsetValue

type TypeOffsetValue struct {
	Type   string
	Offset int64
	Value  int64
}

type UnexpectedCharacterError

type UnexpectedCharacterError struct {
	ActChar byte
	ExpChar byte
}

An UnexpectedCharacterError is raised by decoding an unexpected character.

func (*UnexpectedCharacterError) Error

func (e *UnexpectedCharacterError) Error() string

type Unit

type Unit string
const (
	UnitM  Unit = "m"
	UnitKm Unit = "km"
	UnitFt Unit = "ft"
	UnitMi Unit = "mi"
)

type UserPassword

type UserPassword struct {
	User     string
	Password string
}

type VerbatimString

type VerbatimString string

A VerbatimString represents the redis verbatim string type.

func (VerbatimString) Attr

func (s VerbatimString) Attr() *Map

func (VerbatimString) FileFormat

func (s VerbatimString) FileFormat() string

FileFormat is returning the file format of a verbatim string.

func (VerbatimString) Kind

func (s VerbatimString) Kind() RedisKind

Kind returns the type of a VerbatimString.

func (VerbatimString) String

func (s VerbatimString) String() string

String implements the Stringer interface.

func (VerbatimString) ToBool

func (s VerbatimString) ToBool() (bool, error)

ToBool implements the Converter ToBooler interface.

func (VerbatimString) ToFloat64

func (s VerbatimString) ToFloat64() (float64, error)

ToFloat64 implements the Converter ToFloat64er interface.

func (VerbatimString) ToInt64

func (s VerbatimString) ToInt64() (int64, error)

ToInt64 implements the Converter ToInt64er interface.

func (VerbatimString) ToInt64Slice

func (s VerbatimString) ToInt64Slice() ([]int64, error)

func (VerbatimString) ToSlice

func (s VerbatimString) ToSlice() ([]interface{}, error)

func (VerbatimString) ToSlice2

func (s VerbatimString) ToSlice2() ([][]interface{}, error)

func (VerbatimString) ToString

func (s VerbatimString) ToString() (string, error)

ToString implements the Converter Stringer interface.

func (VerbatimString) ToStringInt64Map

func (s VerbatimString) ToStringInt64Map() (map[string]int64, error)

func (VerbatimString) ToStringMap

func (s VerbatimString) ToStringMap() (map[string]interface{}, error)

func (VerbatimString) ToStringMapSlice

func (s VerbatimString) ToStringMapSlice() ([]map[string]interface{}, error)

func (VerbatimString) ToStringSet

func (s VerbatimString) ToStringSet() (map[string]bool, error)

func (VerbatimString) ToStringSlice

func (s VerbatimString) ToStringSlice() ([]string, error)

func (VerbatimString) ToStringStringMap

func (s VerbatimString) ToStringStringMap() (map[string]string, error)

func (VerbatimString) ToTree

func (s VerbatimString) ToTree() ([]interface{}, error)

func (VerbatimString) ToXrange

func (s VerbatimString) ToXrange() ([]IDMap, error)

func (VerbatimString) ToXread

func (s VerbatimString) ToXread() (map[string][]IDMap, error)

type Xranger

type Xranger interface {
	// ToXrange returns a slice with values of type IdMap. In case the conversion is not possible
	// a ConversitionError is returned.
	ToXrange() ([]IDMap, error)
}

Xranger is implemented by any redis value that has a ToXrange method.

type Xreader

type Xreader interface {
	// ToXread returns a map[string] with values of type IdMap. In case the conversion is not possible
	// a ConversitionError is returned.
	ToXread() (map[string][]IDMap, error)
}

Xreader is implemented by any redis value that has a ToXread method.

type Zclose

type Zclose float64

Zclose is the close interval Zfloat64 type.

func (Zclose) String

func (z Zclose) String() string

type Zfloat64

type Zfloat64 interface {
	String() string
	// contains filtered or unexported methods
}

Zfloat64 is the float64 used in some sorted sets commands for min and max values.

type Zopen

type Zopen float64

Zopen is the open interval Zfloat64 type.

func (Zopen) String

func (z Zopen) String() string

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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