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