-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: improve clear useless cache (#7)
* refactor: improve clear useless cache * fix: delete only * feat: skip
- Loading branch information
Showing
3 changed files
with
62 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-expressions */ | ||
|
||
import { RedisBin, RedisCache } from '../src' | ||
|
||
const redisConfig = { | ||
// 服务器地址 | ||
host: '127.0.0.1', | ||
// 端口 | ||
port: 6379, | ||
// 密码,若无填空字符串 | ||
password: '', | ||
// 数据库,默认为0 | ||
db: 0, | ||
// 键前缀,可区分不同的项目 | ||
prefix: 'test___pre_', | ||
// 是否回显查询语句 | ||
trace: false, | ||
} | ||
|
||
// 一般一个数据库只需要使用一个实例,内部会管理连接池,无需创建多个 | ||
const redisBin = new RedisBin(redisConfig) | ||
|
||
// 创建一个缓存实例 | ||
const redisCache = new RedisCache(redisBin) | ||
|
||
const nsp1 = 'NSP_1' | ||
|
||
describe.skip('RedisCache class test', function () { | ||
it('init data', async () => { | ||
await redisCache.mSet(nsp1, { a: 1, b: 2, c: 3 }, 1) | ||
await redisCache.mSet(nsp1, { a1: 1, b1: 2, c1: 3 }, 10) | ||
await redisCache.delete(nsp1, ['b', 'c1']) | ||
await redisCache.set(nsp1, 'b', 'v-b') | ||
await redisCache.set(nsp1, 'c1', 'v-c1') | ||
}) | ||
|
||
it('clear useless cache', async () => { | ||
const res = await redisCache.clearUseless('*') | ||
console.log(res) | ||
}) | ||
}) |