V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
guyeuro
V2EX  ›  问与答

RedisTemplate 如何检查某个 key 是否存在?

  •  
  •   guyeuro · 2017-08-23 11:28:44 +08:00 · 19563 次点击
    这是一个创建于 2438 天前的主题,其中的信息可能已经有所发展或是发生改变。
    13 条回复    2017-08-24 15:31:03 +08:00
    zjp
        1
    zjp  
       2017-08-23 11:47:31 +08:00 via Android
    get() 然后判断是否为 null 不行吗
    guyeuro
        2
    guyeuro  
    OP
       2017-08-23 11:48:09 +08:00
    @zjp hash 和 set 的键呢
    guyeuro
        3
    guyeuro  
    OP
       2017-08-23 11:50:07 +08:00
    @guyeuro get 有 nullpointexception 啊
    irockytan
        4
    irockytan  
       2017-08-23 11:53:35 +08:00 via iPhone
    api 文档看看,有 exist 和 hexist 的
    guyeuro
        5
    guyeuro  
    OP
       2017-08-23 11:55:22 +08:00
    @irockytan 没有啊,哪里的文档说有?
    KillThunder
        6
    KillThunder  
       2017-08-23 12:05:50 +08:00
    EXISTS key
    检查给定 key 是否存在。
    guyeuro
        7
    guyeuro  
    OP
       2017-08-23 12:21:34 +08:00   ❤️ 1
    @KillThunder 这是 redis 的命令,不是 redistemplate 里的啊
    251804746
        8
    251804746  
       2017-08-23 12:34:15 +08:00
    valueOperations.getOperations().hasKey("");
    LaudOak
        9
    LaudOak  
       2017-08-23 12:36:56 +08:00
    LaudOak
        10
    LaudOak  
       2017-08-23 12:45:12 +08:00


    RedisTemplate#hasKey(K key)
    ooTwToo
        11
    ooTwToo  
       2017-08-23 13:20:16 +08:00 via Android
    进去看看有哪些方法再来问。。
    GoGoGoBoy
        12
    GoGoGoBoy  
       2017-08-23 17:34:20 +08:00 via iPhone
    @LaudOak 为什么设计成回掉模式???
    KillThunder
        13
    KillThunder  
       2017-08-24 15:31:03 +08:00
    @guyeuro redistemplate 和 jedis 有什么区别吗?哪个比较好用?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2615 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 01:51 · PVG 09:51 · LAX 18:51 · JFK 21:51
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.