Skip to content

Commit

Permalink
Add keys to evalscript (#109)
Browse files Browse the repository at this point in the history
* Add keys to evalsha

Shouldn't `evalscript` take a `keys` argument, at least according to https://redis.io/docs/latest/commands/eval/ ?

* Fix tests

* use new evalscript method signature always

---------

Co-authored-by: tan <[email protected]>
  • Loading branch information
aviks and tanmaykm authored Jul 12, 2024
1 parent 645c8f6 commit 085dca5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/commands.jl
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ end

# Scripting commands
# TODO: PipelineConnection and TransactionConnection
function evalscript(conn::RedisConnection, script, numkeys::Integer, args)
response = execute_command(conn, flatten_command("eval", script, numkeys, args))
function evalscript(conn::RedisConnection, script, numkeys::Integer, keys, args)
response = execute_command(conn, flatten_command("eval", script, numkeys, keys, args))
return response
end

Expand Down
13 changes: 7 additions & 6 deletions test/redis_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -333,23 +333,24 @@ function redis_tests(conn = RedisConnection())

@testset "Scripting" begin
script = "return {KEYS[1], KEYS[2], ARGV[1], ARGV[2]}"
args = ["key1", "key2", "first", "second"]
resp = evalscript(conn, script, 2, args)
@test resp == args
keys = ["key1", "key2"]
args = ["first", "second"]
resp = evalscript(conn, script, 2, keys, args)
@test resp == vcat(keys, args)
del(conn, "key1")

script = "return redis.call('set', KEYS[1], 'bar')"
ky = "foo"
resp = evalscript(conn, script, 1, [ky])
resp = evalscript(conn, script, 1, [ky], [])
@test resp == "OK"
del(conn, ky)

script = "return {10,20}"
resp = evalscript(conn, script, 0, [])
resp = evalscript(conn, script, 0, [], [])
@test resp == [10, 20]

script = "return"
resp = evalscript(conn, script, 0, [])
resp = evalscript(conn, script, 0, [], [])
@test resp === nothing

#@test evalscript(conn, "return {'1','2',{'3','Hello World!'}}", 0, []) == ["1"; "2"; ["3","Hello World!"]]
Expand Down

0 comments on commit 085dca5

Please sign in to comment.