Ganesh Kumar
Ganesh Kumar

Reputation: 1361

LIST alternative in redis

Redis.io

The main features of Redis Lists from the point of view of time complexity is the support for constant time insertion and deletion of elements near the head and tail, even with many millions of inserted items. Accessing elements is very fast near the extremes of the list but is slow if you try accessing the middle of a very big list, as it is an O(N) operation.

what is the LIST alternative when the data is too high and writes are lesser than Reads

Upvotes: 0

Views: 678

Answers (1)

Ted Naleid
Ted Naleid

Reputation: 26821

This is something I'd definitely benchmark before doing, but if you're really hitting a performance issue accessing items in the middle of the list, there are a couple of alternatives that really depend on your use case.

  1. Don't make a list so big, age out/trim pieces that don't matter any more.
  2. Memoize hot sections of the list. If a particular paginated range is being requested much more often than others, make that it's own list. Check if it exists already, and if it doesn't create a subset of your list in the paginated range.
  3. Bucket your list from the beginning into "manageable sizes" (for whatever your definition of managable is). If a list is purely additive (no removal from the list), you could use the modulus index of an item as part of the key so that your list is stored in smaller buckets. Ex: key = "your_key_name_" + index % 100000

Upvotes: 1

Related Questions