javascript - Redis 客户端不删除任何东西

标签 javascript node.js caching redis

我正在使用 node.js redis client .在我运行单元测试之前,我想清除所有的 redis 键。由于一些奇怪的原因,我的代码什么也没做。

const redis = require('redis');

const client = redis.createClient({
  host: conf.host,
  port: conf.port,
  prefix: conf.prefix
});

client.on('connect', err => {
  // everything is OK here. I can set and get.
});

module.exports = redis;

在开始测试之前,我想清除我的缓存:

const redis = require('file-above');

before(done => {
  redis.keys('*', function (err, rows) {
    rows.forEach(row => {
      console.log(row); // perfectly matched
      redis.del(row);
      // nothing changed. I can still get any of the rows above here
    });
  });
  done();
});

此后不会删除任何内容。我尝试添加 setTimeout,尝试直接使用 redis.del('*', done) 而无需键匹配。

我在 redis 包自述文件中找不到任何与 .del 相关的内容来弄清楚我做错了什么。

最佳答案

如果合适,您应该使用flushall。在此处查看更多文档 http://redis.io/commands/FLUSHALL .不过,关于您的实现,我认为您需要将回调传递给 del

关于javascript - Redis 客户端不删除任何东西,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36070352/

相关文章:

javascript - React 路由器无法识别新的 :flag with history. Push()

node.js - Express.js sendFile 返回 ECONNABORTED

node.js - nodeJS回调错误参数

sql - 当对DBI进行子类化时,Perl DBI将设置SQLite DB cache_size视为写操作

c# - 如何清除 WPF 应用程序中的 WebBrowser 缓存?

html - 为什么我的 style.css 更新仅在执行硬刷新时反射(reflect)出来,而在之后刷新时恢复到以前的版本?

javascript - html canvas 1600x1200屏幕撕裂

javascript - 使用 __proto__ 扩展 Protractor 中的基本页面对象

javascript - 如何在javascript中检查浏览器是否有pdf查看器

javascript - 将字符串拆分为对象 javascript