This is my (reckless) decision to keep the Redis List unique. (implementation in Ruby)
def push_item_to_the_list(LIST_KEY, item) insert_status = Redis.linsert(LIST_KEY, 'before', item, item) if insert_status == -1 Redis.lpush(LIST_KEY, item) else Redis.lrem(LIST_KEY, 1, item) end end
Each time you want to click or paste an item into your list, check to see if the LINSERT command LINSERT put that item immediately after the same item (this is the only way to find out if that item is already in the redis list or not).
If LINSERT returns the status -1, it means that he could not find the item in your list - everything is in order (you can click it or paste it now).
If LINSERT returns a different value (the size of the list in another case), it means that he was able to find the element already, and he was able to insert another element immediately after the previous one. This means that you have ( at least ) duplication of your element. Now you can delete one of them.
source share