检查列表中是否存在一个值已经 Redis

编程入门 行业动态 更新时间:2024-10-13 06:16:35
本文介绍了检查列表中是否存在一个值已经 Redis的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想知道是否有办法检查 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.

推荐答案

您的选项如下:

  • 使用 LREM 并在找到后替换它.
  • 维护一个单独的 SET 与您的 LIST
  • 循环遍历 LIST,直到找到项目或到达结尾.
  • Using LREM and replacing it if it was found.
  • Maintaining a separate SET in conjunction with your LIST
  • Looping through the LIST until you find the item or reach the end.
  • 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

    本文发布于:2023-11-28 18:27:38,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1643477.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:是否存在   列表中   Redis

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!