Reputation: 21
How to load a lib redis (lua) using 'docker exec' command? I'm trying to load a lib in redis using 'docker exec' but I get the following error:
ERR Missing library metadata
Command used:
docker exec redis-db_1 redis-cli -a [password] FUNCTION LOAD "$(cat [path]\ZRANDSCORE.lua)"
Code [ZRANDSCORE.lua]
#!lua name=ZRANDSCORE
local function zrandscore(KEYS, ARGV)
local set = redis.call('ZRANGEBYSCORE', KEYS[1], ARGV[1], ARGV[2])
local langth = table.getn(set)
local member = set[math.random(1, langth)]
redis.call('ZINCRBY', KEYS[1], ARGV[3], member)
return {member, langth-1}
end
redis.register_function('ZRANDSCORE', zrandscore)
On the first line, notice that the metadata is reported as instructed in the documentation:
#!<engine name> name=<library name>
so much so that when I run this same code directly in redis I get success execution output
Upvotes: 1
Views: 598
Reputation: 41
This worked for me (Redis 7.0.5):
call docker exec with "-i" option to bind terminal's stdin to docker exec and redis-cli with "-x" option to read its last argument from stdin:
cat <script> | docker exec -i <container> redis-cli -x FUNCTION LOAD REPLACE
note: the script must begin with #!lua name=<libname>
In all other cases redis-cli gives: "ERR Missing library metadata"
Upvotes: 2
Reputation: 1
have you tried:
docker exec redis-db_1 redis-cli -a [password] FUNCTION LOAD < [path]\ZRANDSCORE.lua
Upvotes: 0