diff --git a/core/stores/redis/redis.go b/core/stores/redis/redis.go index 244f0732..6c17be68 100644 --- a/core/stores/redis/redis.go +++ b/core/stores/redis/redis.go @@ -250,6 +250,21 @@ func (s *Redis) Eval(script string, keys []string, args ...interface{}) (val int return } +// Eval is the implementation of redis eval command. +func (s *Redis) EvalSha(script string, keys []string, args ...interface{}) (val interface{}, err error) { + err = s.brk.DoWithAcceptable(func() error { + conn, err := getRedis(s) + if err != nil { + return err + } + + val, err = conn.EvalSha(script, keys, args...).Result() + return err + }, acceptable) + + return +} + // Exists is the implementation of redis exists command. func (s *Redis) Exists(key string) (val bool, err error) { err = s.brk.DoWithAcceptable(func() error { @@ -1672,7 +1687,7 @@ func (s *Redis) String() string { return s.Addr } -func (s *Redis) scriptLoad(script string) (string, error) { +func (s *Redis) ScriptLoad(script string) (string, error) { conn, err := getRedis(s) if err != nil { return "", err diff --git a/core/stores/redis/redis_test.go b/core/stores/redis/redis_test.go index 790e68b5..6d8af051 100644 --- a/core/stores/redis/redis_test.go +++ b/core/stores/redis/redis_test.go @@ -947,13 +947,24 @@ func TestRedisString(t *testing.T) { func TestRedisScriptLoad(t *testing.T) { runOnRedis(t, func(client *Redis) { client.Ping() - _, err := NewRedis(client.Addr, "").scriptLoad("foo") + _, err := NewRedis(client.Addr, "").ScriptLoad("foo") assert.NotNil(t, err) - _, err = client.scriptLoad("foo") + _, err = client.ScriptLoad("foo") assert.NotNil(t, err) }) } +func TestRedisEvalSha(t *testing.T) { + runOnRedis(t, func(client *Redis) { + client.Ping() + scriptHash, err := client.ScriptLoad(`return redis.call("EXISTS", KEYS[1])`) + assert.Nil(t, err) + result, err := client.EvalSha(scriptHash, []string{"key1"}) + assert.Nil(t, err) + assert.Equal(t, int64(0), result) + }) +} + func TestRedisToPairs(t *testing.T) { pairs := toPairs([]red.Z{ {