Is it possible to set size restriction for value in redis. For example, I want to store only values in which its size should be less than 2 MB to the redis key. value having size greater than 2 MB should be skipped.
keyName – sampleRedisKey_1
value for sampleRedisKey_1 – some value in which its size < 2 MB
keyName – sampleRedisKey_2
value for sampleRedisKey_2 – some value in which its size > 2 MB
In these two keys, sampleRedisKey_1 should be stored and sampleRedisKey_2 should not be stored.
Thanks in advance.
2
Answers
If your redis version >=
4.0.0
then you may usememory usage
, it returns the the value in bytes. In your application layer you may make comparison before setting the value, skip to another key if size exceeds.There is nothing like limits on size of individual Redis object or type, you have to handle that at application side. Otherwise use some Lua script to do that. However I prefer client side as it completely avoids sending data to Redis instance.