我正在使用 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/