util

package
v0.0.0-...-6d2ea26 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2015 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package util is a collection of helper functions for interacting with various parts of the radix.v2 package

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LuaEval

func LuaEval(c Cmder, script string, keys int, args ...interface{}) *redis.Resp

LuaEval calls EVAL on the given Cmder for the given script, passing the key count and argument list in as well. See http://redis.io/commands/eval for more on how EVAL works and for the meaning of the keys argument.

LuaEval will automatically try to call EVALSHA first in order to preserve bandwidth, and only falls back on EVAL if the script has never been used before.

This method works with any of the Cmder's implemented in radix.v2, including Client, Pool, and Cluster.

r := util.LuaEval(c, `return redis.call('GET', KEYS[1])`, 1, "foo")

func Scan

func Scan(r Cmder, ch chan string, cmd, key, pattern string) error

Scan is a helper function for performing any of the redis *SCAN functions. It takes in a channel which keys returned by redis will be written to, and returns an error should any occur. The input channel will always be closed when Scan returns, and *must* be read until it is closed.

The key argument is only needed if cmd isn't SCAN

Example SCAN command

ch := make(chan string)
var err error
go func() {
	err = util.Scan(r, ch, "SCAN", "", "*")
}()
for key := range ch {
	// do something with key
}
if err != nil {
	// handle error
}

Example HSCAN command

ch := make(chan string)
var err error
go func() {
	err = util.Scan(r, ch, "HSCAN", "somekey", "*")
}()
for key := range ch {
	// do something with key
}
if err != nil {
	// handle error
}

Types

type Cmder

type Cmder interface {
	Cmd(cmd string, args ...interface{}) *redis.Resp
}

Cmder is an interface which can be used to interchangeably work with either redis.Client (the basic, single connection redis client), pool.Pool, or cluster.Cluster. All three implement a Cmd method (although, as is the case with Cluster, sometimes with different limitations), and therefore all three are Cmders

Jump to

Keyboard shortcuts

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