I want to store some record in the Redis list, but I only want to keep the most recent 1000 records. My current approach is to use LTRIM key 0 999 to delete the expired record every time I LPUSH a record. but this means I need to execute two commands. Is there a better solution to this problem?
Comment From: madolson
As of today, no, there is no way to limit the size of records within Redis. Would you prefer some ability to do LPUSH with an optional argument that trimmed the size as well, or as some sort of built in constraint within Redis?
Comment From: ffbh123456
@madolson Hi, I prefer the second method you said, and I think this function can be made into a configuration item and configured by the user for example redis.list.max_len = 1000, This means that the length of a list is at most 1000. When this length is exceeded, Redis will auto delete the remaining elements according to some rules(maybe according to FIFO, the first inserted element is deleted first, or something else)
Comment From: ShooterIT
Hi @ZhouJiaZhi @madolson I always wish we can offer some configurations that limit the member number of list, hash, set, zset. Don't allow to insert more members if reached limit. Sometimes users don't know the member number of those types, they execute O(n) complexity commands that freeze server, actually, they doesn't want to this, and operation engineers also suffer from this. Moreover, big keys also blocks server when migrate slots keys.
Users will partition their list, hash, set, zset type if we have strong constraints. Does that make sense?