Reputation: 523
I need to iterate ring any times in redis, I have this Lua script:
local result = redis.call('lrange','test',0,5)
redis.call('ltrim','test',5,-1)
redis.call('rpush','test',result)
return result
Here I lpop
5 elements, then I need to rpush
them back.
redis.call('rpush','test',result)
throws error Lua redis() command arguments must be strings or integers
, so I need JavaScript like ...result
in Lua.
Upvotes: 1
Views: 1004
Reputation: 9596
I think you may use unpack for this.
local result = redis.call('lrange','test',0,5)
redis.call('ltrim','test',5,-1)
redis.call('rpush','test',unpack(result))
return result
While calling lrange
you (may) need to use 4
instead of 5
if you want to keep the list size same. Here is the sample demonstration when executing it with 4
.
127.0.0.1:6379> rpush test a b c d e f
(integer) 6
127.0.0.1:6379> "EVAL" "local result = redis.call('lrange','test',0,4) redis.call('ltrim','test',5,-1) redis.call('rpush','test',unpack(result)) return result" "0"
1) "a"
2) "b"
3) "c"
4) "d"
5) "e"
127.0.0.1:6379> lrange test 0 -1
1) "f"
2) "a"
3) "b"
4) "c"
5) "d"
6) "e"
Upvotes: 1