Get the index of an item by value in a redis list

前端 未结 6 1964
臣服心动
臣服心动 2020-12-31 08:32

I have a redis list I have created, I am using it as a queue at the moment that reverses once in a while. My problem is that I would like to be able to get the index of an i

6条回答
  •  鱼传尺愫
    2020-12-31 09:18

    Using sorted sets (ZADD, etc) you can use ZRANK.

    Edit: My old answer below doesn't work, because your list changes, although it does, with a list that only grows using RPUSH.

    You could store the index with the value (or its hash) as a key:

    set listvalue listindex
    

    In order to keep your redis organised, you could prefix those keys with the listname:

    set listname:listvalue listindex
    

提交回复
热议问题