node.js redis special delete del
https://github.com/luin/ioredis```
const Redis = require(‘ioredis’);
const redis = new Redis();
const delScript = local all_keys = {}; local keys = {}; local done = false; local cursor = "0" repeat local result = redis.call("SCAN", cursor, "match", KEYS[1], "count", KEYS[2]) cursor = result[1]; keys = result[2]; for i, key in ipairs(keys) do all_keys[#all_keys+1] = key; end if cursor == "0" then done = true; end until done for i, key in ipairs(all_keys) do redis.call("DEL", key); end return true;
;
redis.defineCommand(‘del’, {
numberOfKeys: 2,
lua: delScript
});
redis.del(‘login:202007*’, 10000, function(error, result) {
console.log(‘error: ‘, error);
console.log(‘result: ‘, result);
});