0
votes

Just started playing with lua scripting in redis, I want to execute the following commands in a script:

set k1 foo
set k2 bar

Tried..

> EVAL "redis.call('set', KEYS[1],'foo'); redis.call('set',KEYS[2],'bar'); return 1;" 1 k1 2 k2


 > script load "redis.call('set', KEYS[1],'foo'); redis.call('set',KEYS[2],'bar'); return 1;"
 > "bb031c00b6ab2508bbf182dadd5c9bf1675cce56"
 > EVALSHA "bb031c00b6ab2508bbf182dadd5c9bf1675cce56" 1 k1 2 k2

Results

get k1
1) "foo"

get k2
(nil)

Why is k2 not set; is the script and/or syntax not correct?

1

1 Answers

3
votes

the way you call it now, it passes in one key name (k1) and two arguments (2, k2).

I think you want it to be

EVAL "redis.call('set', KEYS[1], 'foo'); redis.call('set', KEYS[2],'bar'); return 1;" 2 k1 k2