?由于mac redis client无法进行快速批量删除,故想通过脚本来执行批量删除。
?一、安装依赖
npm install ioredis mocha
二、脚本
test.js
const Redis = require('ioredis');
const redis = new Redis({
port: 6379, // Redis port
host: 'xxxx.redis.rds.aliyuncs.com', // Redis host
family: 6, // 4 (IPv4) or 6 (IPv6)
password: 'xxxx',
db: 0
});
describe('', async () => {
it.skip('设置key', async () => {
try {
await redis.set('foo', 'bar'); // returns promise which resolves to string, "OK"
} catch (error) {
await console.error(error);
}
});
it.skip('查询指定key', async () => {
try {
var result = await redis.get('USER_REMAINING_-1103');
await console.log(`GET USER_REMAINING_-1103:${result}`); // Promise resolves to "bar"
} catch (error) {
await console.error(error);
}
});
it('删除 USER_REMAINING_', async () => {
try {
for (let index = 1209; index < 1309; index++) {
var result = await redis.del(`USER_REMAINING_-${index}`);
await console.log(`DEL USER_REMAINING_-${index}:${result}:${result}`); // Promise resolves to "bar"
}
} catch (error) {
await console.error(error);
}
});
it('删除 GIFT_TOTAL_NUM_', async () => {
try {
for (let index = 1; index < 6; index++) {
var result = await redis.del(`GIFT_TOTAL_NUM_${index}`);
await console.log(`DEL GIFT_TOTAL_NUM_${index}:${result}`); // Promise resolves to "bar"
}
} catch (error) {
await console.error(error);
}
});
it('删除 GIFT_SEND_DAY_NUM_', async () => {
try {
for (let index = 1; index < 6; index++) {
var result = await redis.del(`GIFT_SEND_DAY_NUM_${index}`);
await console.log(`DEL GIFT_SEND_DAY_NUM_${index}:${result}`); // Promise resolves to "bar"
}
} catch (error) {
await console.error(error);
}
});
});
?三、执行结果
|