Esempio n. 1
0
File: pool.go Progetto: pl/radix.v2
// Cmd automatically gets one client from the pool, executes the given command
// (returning its result), and puts the client back in the pool
func (p *Pool) Cmd(cmd string, args ...interface{}) *redis.Resp {
	c, err := p.Get()
	if err != nil {
		return redis.NewResp(err)
	}
	defer p.Put(c)

	return c.Cmd(cmd, args...)
}
Esempio n. 2
0
File: lua.go Progetto: pl/radix.v2
// 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 LuaEval(c Cmder, script string, keys int, args ...interface{}) *redis.Resp {
	mainKey, _ := redis.KeyFromArgs(args...)

	sumRaw := sha1.Sum([]byte(script))
	sum := hex.EncodeToString(sumRaw[:])

	var r *redis.Resp
	if err := withClientForKey(c, mainKey, func(cc Cmder) {
		r = c.Cmd("EVALSHA", sum, keys, args)
		if r.Err != nil && strings.HasPrefix(r.Err.Error(), "NOSCRIPT") {
			r = c.Cmd("EVAL", script, keys, args)
		}
	}); err != nil {
		return redis.NewResp(err)
	}

	return r
}
Esempio n. 3
0
func errorResp(err error) *redis.Resp {
	return redis.NewResp(err)
}