我想知道是否有办法检查 redis 列表中是否已存在某个键?
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.
推荐答案您的选项如下:
Redis 列表作为 en.wikipedia/wiki/Linked_list 实现,因此存在局限性.
Redis lists are implemented as a en.wikipedia/wiki/Linked_list, hence the limitations.
我认为您最好的选择是维护一个重复的 SET.这是我倾向于做的.把它想象成一个额外的索引.无论如何,请确保您的操作是使用 MULTI-EXEC 或 Lua 脚本的原子操作.
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.
更多推荐
检查列表中是否存在一个值已经 Redis
发布评论