Checking if a value exists in a list already Redis

后端 未结 5 1791
深忆病人
深忆病人 2021-02-01 13:14

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 ab

5条回答
  •  别跟我提以往
    2021-02-01 13:48

    You can also use LPOS.

    When the item exists it returns a number indicating the position:

    LPOS mylist myitem
    3
    

    When not it returns nill:

    LPOS mylist myitem_which_do_not_exits
    (nil)
    

    • Notes:

      • Available since 6.0.6.
      • Time complexity: O(N)
      • https://redis.io/commands/lpos

提交回复
热议问题