diff --git a/spec/redis_spec.cr b/spec/redis_spec.cr index b040377..be01c3b 100644 --- a/spec/redis_spec.cr +++ b/spec/redis_spec.cr @@ -1187,6 +1187,13 @@ describe Redis do result = redis.eval("return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", keys, args) result.should eq(["key1", "key2", "first", "second"]) end + + it "handles different return types" do + keys = ["key1", "key2"] of Redis::RedisValue + args = ["first", "second"] of Redis::RedisValue + result = redis.eval("return KEYS[1]", keys, args) + result.should eq("key1") + end end describe "#script_load / #eval_sha" do @@ -1197,6 +1204,14 @@ describe Redis do result = redis.evalsha(sha1, keys, args) result.should eq(["key1", "first"]) end + + it "handles different return types" do + sha1 = redis.script_load("return KEYS[1]") + keys = ["key1", "key2"] of Redis::RedisValue + args = ["first", "second"] of Redis::RedisValue + result = redis.evalsha(sha1, keys, args) + result.should eq("key1") + end end describe "#script_kill" do diff --git a/src/redis/command_execution/future_oriented.cr b/src/redis/command_execution/future_oriented.cr index b03baa3..d029e0a 100644 --- a/src/redis/command_execution/future_oriented.cr +++ b/src/redis/command_execution/future_oriented.cr @@ -47,6 +47,12 @@ class Redis command(request) end + # Executes a Redis command and casts the response to the correct type. + # This is an internal method. + def string_array_or_string_or_integer_command(request : Request) : Redis::Future + command(request) + end + # Executes a Redis command and returns a Future. def string_array_or_string_or_nil_command(request : Request) : Redis::Future command(request) diff --git a/src/redis/command_execution/value_oriented.cr b/src/redis/command_execution/value_oriented.cr index f01867c..34f97a1 100644 --- a/src/redis/command_execution/value_oriented.cr +++ b/src/redis/command_execution/value_oriented.cr @@ -51,6 +51,12 @@ class Redis command(request).as(Array(RedisValue) | Int64) end + # Executes a Redis command and casts the response to the correct type. + # This is an internal method. + def string_array_or_string_or_integer_command(request : Request) : Array(RedisValue) | String | Int64 + command(request).as(Array(RedisValue) | String | Int64) + end + # Executes a Redis command and casts the response to the correct type. # This is an internal method. def string_array_or_string_command(request : Request) : Array(RedisValue) | String diff --git a/src/redis/commands.cr b/src/redis/commands.cr index 8ec540f..2f0df55 100644 --- a/src/redis/commands.cr +++ b/src/redis/commands.cr @@ -1470,7 +1470,7 @@ class Redis # EVAL and EVALSHA are used to evaluate scripts using the Lua interpreter # built into Redis starting from version 2.6.0. # - # **Return value**: Array(String), depends on the executed script + # **Return value**: Depends on the executed script # # Example: # @@ -1478,15 +1478,15 @@ class Redis # redis.eval("return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", ["key1", "key2"], ["first art", "second arg"]) # ``` def eval(script : String, keys = [] of RedisValue, args = [] of RedisValue) - string_array_or_integer_command(concat(["EVAL", script, keys.size.to_s], keys, args)) + string_array_or_string_or_integer_command(concat(["EVAL", script, keys.size.to_s], keys, args)) end # EVAL and EVALSHA are used to evaluate scripts using the Lua interpreter # built into Redis starting from version 2.6.0. # - # **Return value**: Array(String), depends on the executed script + # **Return value**: Depends on the executed script def evalsha(sha1, keys = [] of RedisValue, args = [] of RedisValue) - string_array_or_integer_command(concat(["EVALSHA", sha1.to_s, keys.size.to_s], keys, args)) + string_array_or_string_or_integer_command(concat(["EVALSHA", sha1.to_s, keys.size.to_s], keys, args)) end # Load a script into the scripts cache, without executing it.