I have Redis system that utilizes key nesting and key composition with different prefixes:
SET prefix-1:concrete-key-1 value-1
SET prefix-1:concrete-key-2 value-2
SET prefix-2:concrete-key-1 value-3
SET prefix-2:concrete-key-2 value-4
SET id-123 concrete-key-1
SET id-456 concrete-key-2
SET id-789 concrete-key-1
So by using id-xxx
and <prefix>
I can get to specific value in 2 commands
id-123 -> concrete-key-1
prefix-1 + concrete-key-1 -> value-1
To reduce redis call and traffic amount I've created small LUA script to do getter on Redis side:
key = redis.call('GET', KEYS[1]);
return redis.call('GET', <prefix>..key);
Question is how to properly pass prefix in this case?
According to Redis I should explicitly specify keys as KEYS parameter: https://redis.io/topics/lua-api
Should I pass it as a key?
key = redis.call('GET', KEYS[1]);
return redis.call('GET', KEYS[2]..key);
However there are no standalone <prefix>
keys, they are all composed of <prefix>:<key>
. So should I pass prefixes as an argument?
key = redis.call('GET', KEYS[1]);
return redis.call('GET', ARGV[1]..key);
Or does it even makes sense to pass it like that? Is there other way how to properly get value using scripts?