【问题标题】:How to delete the redis keys?如何删除redis键?
【发布时间】:2018-01-05 00:12:06
【问题描述】:

我可以使用 FLUSHALL 命令删除所有 redis 键。但是如何使用 nodejs 中的脚本来实现相同的结果。 非常感谢这方面的任何帮助。

【问题讨论】:

  • 与redis建立连接你做到了吗?你到底在哪里坚持这个?

标签: javascript node.js redis


【解决方案1】:

首先,安装node-redis客户端

npm install redis --save

然后你需要创建一个连接:

import * as redis from 'redis'
const client = redis.createClient(REDIS_PORT, REDIS_HOST);

之后,您可以使用以下命令删除特定键:

client.del('myKey');

如果要删除所有键值对,请使用.flushall()

client.flushall((err, success) => {
  if (err) {
    throw new Error(err);
  }
  console.log(success); // will be true if successfull
});

【讨论】:

    猜你喜欢
    • 2022-01-12
    • 2022-01-21
    • 2018-03-10
    • 1970-01-01
    • 2014-01-30
    • 1970-01-01
    • 2020-05-29
    • 2021-11-11
    • 2020-10-13
    相关资源
    最近更新 更多