I'm wondering if there's a way to check if a key already exists in a redis list?
I can't use a set because I don't want to enforce uniqueness, but I do want to be able to check if the string is actually there.
Your options are as follows:
LREM
and replacing it if it was found.SET
in conjunction with your LIST
LIST
until you find the item or reach the end.Redis lists are implemented as a http://en.wikipedia.org/wiki/Linked_list, hence the limitations.
I think your best option is maintaining a duplicate SET
. This is what I tend to do. Just think of it as an extra index. Regardless, make sure your actions are atomic with MULTI
-EXEC
or Lua scripts.
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