If there’s a way to check if a key already exists in a Redis list?

Technology CommunityCategory: RedisIf there’s a way to check if a key already exists in a Redis list?
VietMX Staff asked 3 years ago

Your options are as follows:

  1. Using LREM and replacing it if it was found.
  2. Maintaining a separate SET in conjunction with your LIST
  3. Looping through the LIST until you find the item or reach the end.

Redis lists are implemented as a, hence the limitations. I think your best option is maintaining a duplicate SET. Regardless, make sure your actions are atomic with MULTIEXEC or Lua scripts.