【问题标题】:How to set expire time along with NX/XX/GT/LT using redis module for node js如何使用节点 js 的 redis 模块与 NX/XX/GT/LT 一起设置过期时间
【发布时间】:2022-02-01 07:28:59
【问题描述】:

我正在使用带有节点的 redis (v 3.1.2) 并尝试设置一个带有过期时间的哈希键,我一直坚持在哪里为过期命令提供这个附加属性 (NX/XX/GT/LT) 的部分.

  await client.hset(hashKey, key, JSON.stringify(value));
  await client.expire(hashKey,expire)

有人可以帮忙吗?

【问题讨论】:

    标签: node.js redis hashset


    【解决方案1】:

    只需将第三个参数传递给 expire 方法:

    client.expire(hashKey, expire, 'NX');
    

    【讨论】:

    • 已经试过这个,得到以下错误ReplyError: ERR wrong number of arguments for 'expire' command
    • 你使用的是哪个版本的redis(服务器)?因为 NX/XX/GT/LT 修饰符被添加到 Redis v7 中的 EXPIRE redis.io/commands/expire#history
    • 3.2 版,但我只能在从面向节点的问题中使用 CLI 时使用这些修饰符
    猜你喜欢
    • 1970-01-01
    • 2019-05-24
    • 1970-01-01
    • 2022-01-06
    • 2021-08-08
    • 2020-03-22
    • 2016-05-15
    • 1970-01-01
    • 2020-01-13
    相关资源
    最近更新 更多