Checking if a value exists in a list already Redis

后端 未结 5 1762
深忆病人
深忆病人 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:52

    I am surprised that no one mentioned the set, which perfectly solved the question.
    Using the sismember key value in set, it checks if the value is a member of the key.
    Here is the example:

    redis 127.0.0.1:6379> SADD myset1 "hello"
    (integer) 1
    redis 127.0.0.1:6379> SISMEMBER myset1 "hello"
    (integer) 1
    redis 127.0.0.1:6379> SISMEMBER myset1 "world"
    (integer) 0
    

提交回复
热议问题