In redis, is it possible to set a maximum number of elements to a set so when one use the sadd
, the redis server prevents the set from having more elements that a maximum amount? e.g. something like :
127.0.0.1:6379> SETSIZE KEY 100
Thanks in advance.
No, it`s not possible with usual commands but possible with LUA scripting:
local size = redis.call('SCARD', KEYS[1]);
if size < tonumber(ARGV[1], 10) then
return redis.call('SADD', KEYS[1], ARGV[2]);
end
return -1;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With