0
我正在使用node.js redis client。在我運行單元測試之前,我想清除所有的redis鍵。由於一些奇怪的原因,我的代碼什麼都不做。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
相關的任何事情,以弄清楚我做錯了什麼。
該死的del回調解決了我的問題。在網絡的某個地方發現信息.del是同步功能。好的,謝謝你的幫助 –
不幸的是我錯了。沒有什麼改變。我無法使用flushall,因爲它會刪除比我想要的更多的數據。無論如何感謝您的幫助 –
如果您在循環中調用''del'',您應該使用''async.js''或承諾 – gabesoft