@aomex/cache-redis-adapter 3.30.6 → 3.30.8-alpha.131cf1c.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [3.30.7](https://github.com/aomex/aomex/compare/v3.30.6...v3.30.7) (2026-11-01)
7
+
8
+ **Note:** Version bump only for package @aomex/cache-redis-adapter
9
+
10
+
11
+
12
+
13
+
6
14
  ## [3.30.6](https://github.com/aomex/aomex/compare/v3.30.5...v3.30.6) (2026-10-19)
7
15
 
8
16
  **Note:** Version bump only for package @aomex/cache-redis-adapter
package/dist/index.d.ts CHANGED
@@ -1,23 +1,20 @@
1
- import { CacheAdapter } from '@aomex/cache';
2
- import { Redis, RedisOptions } from 'ioredis';
3
-
4
- declare class CacheRedisAdapter extends CacheAdapter {
5
- readonly redis: Redis;
6
- protected version?: string;
7
- constructor(config: RedisOptions);
8
- getValue(key: string): Promise<string | null>;
9
- setValue(key: string, value: string, duration?: number | undefined): Promise<boolean>;
10
- setNotExistValue(key: string, value: string, duration?: number | undefined): Promise<boolean>;
11
- existsKey(key: string): Promise<boolean>;
12
- deleteValue(key: string): Promise<boolean>;
13
- deleteAllValues(): Promise<boolean>;
14
- increaseValue(key: string): Promise<number>;
15
- decreaseValue(key: string): Promise<number>;
16
- expireKey(key: string, duration: number): Promise<boolean>;
17
- ttlKey(key: string): Promise<number>;
18
- leftPushValue(key: string, ...values: string[]): Promise<boolean>;
19
- rightPopValue(key: string): Promise<string | null>;
20
- }
21
- declare const redisAdapter: (config: RedisOptions) => CacheRedisAdapter;
22
-
23
- export { CacheRedisAdapter, redisAdapter };
1
+ import { CacheAdapter } from "@aomex/cache";
2
+ import { Redis, RedisOptions } from "ioredis";
3
+ export declare class CacheRedisAdapter extends CacheAdapter {
4
+ readonly redis: Redis;
5
+ protected version?: string;
6
+ constructor(config: RedisOptions);
7
+ getValue(key: string): Promise<string | null>;
8
+ setValue(key: string, value: string, duration?: number | undefined): Promise<boolean>;
9
+ setNotExistValue(key: string, value: string, duration?: number | undefined): Promise<boolean>;
10
+ existsKey(key: string): Promise<boolean>;
11
+ deleteValue(key: string): Promise<boolean>;
12
+ deleteAllValues(): Promise<boolean>;
13
+ increaseValue(key: string): Promise<number>;
14
+ decreaseValue(key: string): Promise<number>;
15
+ expireKey(key: string, duration: number): Promise<boolean>;
16
+ ttlKey(key: string): Promise<number>;
17
+ leftPushValue(key: string, ...values: string[]): Promise<boolean>;
18
+ rightPopValue(key: string): Promise<string | null>;
19
+ disconnect(): Promise<void>;
20
+ }
package/dist/index.js CHANGED
@@ -1,86 +1,73 @@
1
- // src/index.ts
2
1
  import { CacheAdapter } from "@aomex/cache";
3
2
  import { Redis } from "ioredis";
3
+ // src/index.ts
4
4
  var CacheRedisAdapter = class extends CacheAdapter {
5
- redis;
6
- version;
7
- constructor(config) {
8
- super();
9
- this.redis = new Redis({ ...config, lazyConnect: true });
10
- }
11
- getValue(key) {
12
- return this.redis.get(key);
13
- }
14
- async setValue(key, value, duration) {
15
- let result;
16
- if (duration !== void 0) {
17
- result = await this.redis.set(key, value, "PX", duration);
18
- } else {
19
- result = await this.redis.set(key, value);
20
- }
21
- return result === "OK";
22
- }
23
- async setNotExistValue(key, value, duration) {
24
- let result;
25
- if (duration !== void 0) {
26
- result = await this.redis.set(key, value, "PX", duration, "NX");
27
- } else {
28
- result = await this.redis.set(key, value, "NX");
29
- }
30
- return result === "OK";
31
- }
32
- async existsKey(key) {
33
- const count = await this.redis.exists(key);
34
- return count === 1;
35
- }
36
- async deleteValue(key) {
37
- await this.redis.del(key);
38
- return true;
39
- }
40
- async deleteAllValues() {
41
- const { redis } = this;
42
- const redisPrefix = redis.options.keyPrefix ?? "";
43
- if (redisPrefix) {
44
- await redis.eval(
45
- `
5
+ redis;
6
+ version;
7
+ constructor(config) {
8
+ super();
9
+ this.redis = new Redis({
10
+ ...config,
11
+ lazyConnect: true
12
+ });
13
+ }
14
+ getValue(key) {
15
+ return this.redis.get(key);
16
+ }
17
+ async setValue(key, value, duration) {
18
+ let result;
19
+ if (duration !== void 0) result = await this.redis.set(key, value, "PX", duration);
20
+ else result = await this.redis.set(key, value);
21
+ return result === "OK";
22
+ }
23
+ async setNotExistValue(key, value, duration) {
24
+ let result;
25
+ if (duration !== void 0) result = await this.redis.set(key, value, "PX", duration, "NX");
26
+ else result = await this.redis.set(key, value, "NX");
27
+ return result === "OK";
28
+ }
29
+ async existsKey(key) {
30
+ return await this.redis.exists(key) === 1;
31
+ }
32
+ async deleteValue(key) {
33
+ await this.redis.del(key);
34
+ return true;
35
+ }
36
+ async deleteAllValues() {
37
+ const { redis } = this;
38
+ const redisPrefix = redis.options.keyPrefix ?? "";
39
+ if (redisPrefix) await redis.eval(`
46
40
  for _,k in ipairs(redis.call('keys', ARGV[1])) do
47
41
  redis.call('del', k)
48
42
  end
49
- `,
50
- 0,
51
- `${redisPrefix}*`
52
- );
53
- } else {
54
- await redis.flushdb();
55
- }
56
- return true;
57
- }
58
- increaseValue(key) {
59
- return this.redis.incr(key);
60
- }
61
- decreaseValue(key) {
62
- return this.redis.decr(key);
63
- }
64
- async expireKey(key, duration) {
65
- const changeRow = await this.redis.pexpire(key, duration);
66
- return changeRow === 1;
67
- }
68
- async ttlKey(key) {
69
- const result = await this.redis.pttl(key);
70
- return result;
71
- }
72
- async leftPushValue(key, ...values) {
73
- const changeRow = await this.redis.lpush(key, ...values.reverse());
74
- return changeRow >= 1;
75
- }
76
- async rightPopValue(key) {
77
- const result = await this.redis.rpop(key);
78
- return result;
79
- }
80
- };
81
- var redisAdapter = (config) => new CacheRedisAdapter(config);
82
- export {
83
- CacheRedisAdapter,
84
- redisAdapter
43
+ `, 0, `${redisPrefix}*`);
44
+ else await redis.flushdb();
45
+ return true;
46
+ }
47
+ increaseValue(key) {
48
+ return this.redis.incr(key);
49
+ }
50
+ decreaseValue(key) {
51
+ return this.redis.decr(key);
52
+ }
53
+ async expireKey(key, duration) {
54
+ return await this.redis.pexpire(key, duration) === 1;
55
+ }
56
+ async ttlKey(key) {
57
+ return await this.redis.pttl(key);
58
+ }
59
+ async leftPushValue(key, ...values) {
60
+ return await this.redis.lpush(key, ...values.reverse()) >= 1;
61
+ }
62
+ async rightPopValue(key) {
63
+ return await this.redis.rpop(key);
64
+ }
65
+ async disconnect() {
66
+ const { status } = this.redis;
67
+ if (status === "end" || status === "close") return;
68
+ this.redis.disconnect();
69
+ }
85
70
  };
71
+ export { CacheRedisAdapter };
72
+
86
73
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { CacheAdapter } from '@aomex/cache';\nimport { Redis, type RedisOptions } from 'ioredis';\n\nexport class CacheRedisAdapter extends CacheAdapter {\n public readonly redis: Redis;\n protected version?: string;\n\n constructor(config: RedisOptions) {\n super();\n this.redis = new Redis({ ...config, lazyConnect: true });\n }\n\n getValue(key: string): Promise<string | null> {\n return this.redis.get(key);\n }\n\n async setValue(\n key: string,\n value: string,\n duration?: number | undefined,\n ): Promise<boolean> {\n let result: 'OK';\n if (duration !== undefined) {\n result = await this.redis.set(key, value, 'PX', duration);\n } else {\n result = await this.redis.set(key, value);\n }\n return result === 'OK';\n }\n\n override async setNotExistValue(\n key: string,\n value: string,\n duration?: number | undefined,\n ): Promise<boolean> {\n let result: 'OK' | null;\n if (duration !== undefined) {\n result = await this.redis.set(key, value, 'PX', duration, 'NX');\n } else {\n result = await this.redis.set(key, value, 'NX');\n }\n return result === 'OK';\n }\n\n async existsKey(key: string): Promise<boolean> {\n const count = await this.redis.exists(key);\n return count === 1;\n }\n\n async deleteValue(key: string): Promise<boolean> {\n await this.redis.del(key);\n return true;\n }\n\n async deleteAllValues(): Promise<boolean> {\n const { redis } = this;\n const redisPrefix = redis.options.keyPrefix ?? '';\n\n if (redisPrefix) {\n await redis.eval(\n `\nfor _,k in ipairs(redis.call('keys', ARGV[1])) do \n redis.call('del', k) \nend\n`,\n 0,\n `${redisPrefix}*`,\n );\n } else {\n await redis.flushdb();\n }\n return true;\n }\n\n override increaseValue(key: string): Promise<number> {\n return this.redis.incr(key);\n }\n\n override decreaseValue(key: string): Promise<number> {\n return this.redis.decr(key);\n }\n\n override async expireKey(key: string, duration: number): Promise<boolean> {\n const changeRow = await this.redis.pexpire(key, duration);\n return changeRow === 1;\n }\n\n override async ttlKey(key: string): Promise<number> {\n const result = await this.redis.pttl(key);\n return result;\n }\n\n override async leftPushValue(key: string, ...values: string[]): Promise<boolean> {\n const changeRow = await this.redis.lpush(key, ...values.reverse());\n return changeRow >= 1;\n }\n\n override async rightPopValue(key: string): Promise<string | null> {\n const result = await this.redis.rpop(key);\n return result;\n }\n}\n\nexport const redisAdapter = (config: RedisOptions) => new CacheRedisAdapter(config);\n"],"mappings":";AAAA,SAAS,oBAAoB;AAC7B,SAAS,aAAgC;AAElC,IAAM,oBAAN,cAAgC,aAAa;AAAA,EAClC;AAAA,EACN;AAAA,EAEV,YAAY,QAAsB;AAChC,UAAM;AACN,SAAK,QAAQ,IAAI,MAAM,EAAE,GAAG,QAAQ,aAAa,KAAK,CAAC;AAAA,EACzD;AAAA,EAEA,SAAS,KAAqC;AAC5C,WAAO,KAAK,MAAM,IAAI,GAAG;AAAA,EAC3B;AAAA,EAEA,MAAM,SACJ,KACA,OACA,UACkB;AAClB,QAAI;AACJ,QAAI,aAAa,QAAW;AAC1B,eAAS,MAAM,KAAK,MAAM,IAAI,KAAK,OAAO,MAAM,QAAQ;AAAA,IAC1D,OAAO;AACL,eAAS,MAAM,KAAK,MAAM,IAAI,KAAK,KAAK;AAAA,IAC1C;AACA,WAAO,WAAW;AAAA,EACpB;AAAA,EAEA,MAAe,iBACb,KACA,OACA,UACkB;AAClB,QAAI;AACJ,QAAI,aAAa,QAAW;AAC1B,eAAS,MAAM,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,KAAK,GAAG;AACxC,WAAO;AAAA,EACT;AACF;AAEO,IAAM,eAAe,CAAC,WAAyB,IAAI,kBAAkB,MAAM;","names":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { CacheAdapter } from '@aomex/cache';\nimport { Redis, type RedisOptions } from 'ioredis';\n\nexport class CacheRedisAdapter extends CacheAdapter {\n public readonly redis: Redis;\n protected version?: string;\n\n constructor(config: RedisOptions) {\n super();\n this.redis = new Redis({ ...config, lazyConnect: true });\n }\n\n getValue(key: string): Promise<string | null> {\n return this.redis.get(key);\n }\n\n async setValue(\n key: string,\n value: string,\n duration?: number | undefined,\n ): Promise<boolean> {\n let result: 'OK';\n if (duration !== undefined) {\n result = await this.redis.set(key, value, 'PX', duration);\n } else {\n result = await this.redis.set(key, value);\n }\n return result === 'OK';\n }\n\n override async setNotExistValue(\n key: string,\n value: string,\n duration?: number | undefined,\n ): Promise<boolean> {\n let result: 'OK' | null;\n if (duration !== undefined) {\n result = await this.redis.set(key, value, 'PX', duration, 'NX');\n } else {\n result = await this.redis.set(key, value, 'NX');\n }\n return result === 'OK';\n }\n\n async existsKey(key: string): Promise<boolean> {\n const count = await this.redis.exists(key);\n return count === 1;\n }\n\n async deleteValue(key: string): Promise<boolean> {\n await this.redis.del(key);\n return true;\n }\n\n async deleteAllValues(): Promise<boolean> {\n const { redis } = this;\n const redisPrefix = redis.options.keyPrefix ?? '';\n\n if (redisPrefix) {\n await redis.eval(\n `\nfor _,k in ipairs(redis.call('keys', ARGV[1])) do \n redis.call('del', k) \nend\n`,\n 0,\n `${redisPrefix}*`,\n );\n } else {\n await redis.flushdb();\n }\n return true;\n }\n\n override increaseValue(key: string): Promise<number> {\n return this.redis.incr(key);\n }\n\n override decreaseValue(key: string): Promise<number> {\n return this.redis.decr(key);\n }\n\n override async expireKey(key: string, duration: number): Promise<boolean> {\n const changeRow = await this.redis.pexpire(key, duration);\n return changeRow === 1;\n }\n\n override async ttlKey(key: string): Promise<number> {\n const result = await this.redis.pttl(key);\n return result;\n }\n\n override async leftPushValue(key: string, ...values: string[]): Promise<boolean> {\n const changeRow = await this.redis.lpush(key, ...values.reverse());\n return changeRow >= 1;\n }\n\n override async rightPopValue(key: string): Promise<string | null> {\n const result = await this.redis.rpop(key);\n return result;\n }\n\n override async disconnect(): Promise<void> {\n const { status } = this.redis;\n if (status === 'end' || status === 'close') return;\n this.redis.disconnect();\n }\n}\n"],"mappings":";;;AAGA,IAAa,oBAAb,cAAuC,aAAa;CAClD;CACA;CAEA,YAAY,QAAsB;EAChC,MAAM;EACN,KAAK,QAAQ,IAAI,MAAM;GAAE,GAAG;GAAQ,aAAa;EAAK,CAAC;CACzD;CAEA,SAAS,KAAqC;EAC5C,OAAO,KAAK,MAAM,IAAI,GAAG;CAC3B;CAEA,MAAM,SACJ,KACA,OACA,UACkB;EAClB,IAAI;EACJ,IAAI,aAAa,KAAA,GACf,SAAS,MAAM,KAAK,MAAM,IAAI,KAAK,OAAO,MAAM,QAAQ;OAExD,SAAS,MAAM,KAAK,MAAM,IAAI,KAAK,KAAK;EAE1C,OAAO,WAAW;CACpB;CAEA,MAAe,iBACb,KACA,OACA,UACkB;EAClB,IAAI;EACJ,IAAI,aAAa,KAAA,GACf,SAAS,MAAM,KAAK,MAAM,IAAI,KAAK,OAAO,MAAM,UAAU,IAAI;OAE9D,SAAS,MAAM,KAAK,MAAM,IAAI,KAAK,OAAO,IAAI;EAEhD,OAAO,WAAW;CACpB;CAEA,MAAM,UAAU,KAA+B;EAE7C,OAAO,MADa,KAAK,MAAM,OAAO,GAAG,MACxB;CACnB;CAEA,MAAM,YAAY,KAA+B;EAC/C,MAAM,KAAK,MAAM,IAAI,GAAG;EACxB,OAAO;CACT;CAEA,MAAM,kBAAoC;EACxC,MAAM,EAAE,UAAU;EAClB,MAAM,cAAc,MAAM,QAAQ,aAAa;EAE/C,IAAI,aACF,MAAM,MAAM,KACV;;;;GAKA,GACA,GAAG,YAAY,EACjB;OAEA,MAAM,MAAM,QAAQ;EAEtB,OAAO;CACT;CAEA,cAAuB,KAA8B;EACnD,OAAO,KAAK,MAAM,KAAK,GAAG;CAC5B;CAEA,cAAuB,KAA8B;EACnD,OAAO,KAAK,MAAM,KAAK,GAAG;CAC5B;CAEA,MAAe,UAAU,KAAa,UAAoC;EAExE,OAAO,MADiB,KAAK,MAAM,QAAQ,KAAK,QAAQ,MACnC;CACvB;CAEA,MAAe,OAAO,KAA8B;EAElD,OAAO,MADc,KAAK,MAAM,KAAK,GAAG;CAE1C;CAEA,MAAe,cAAc,KAAa,GAAG,QAAoC;EAE/E,OAAO,MADiB,KAAK,MAAM,MAAM,KAAK,GAAG,OAAO,QAAQ,CAAC,KAC7C;CACtB;CAEA,MAAe,cAAc,KAAqC;EAEhE,OAAO,MADc,KAAK,MAAM,KAAK,GAAG;CAE1C;CAEA,MAAe,aAA4B;EACzC,MAAM,EAAE,WAAW,KAAK;EACxB,IAAI,WAAW,SAAS,WAAW,SAAS;EAC5C,KAAK,MAAM,WAAW;CACxB;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aomex/cache-redis-adapter",
3
- "version": "3.30.6",
3
+ "version": "3.30.8-alpha.131cf1c.0",
4
4
  "description": "aomex缓存库redis适配器",
5
5
  "type": "module",
6
6
  "types": "dist/index.d.ts",
@@ -29,12 +29,12 @@
29
29
  "homepage": "https://aomex.js.org",
30
30
  "license": "MIT",
31
31
  "peerDependencies": {
32
- "@aomex/cache": "^3.0.0",
32
+ "@aomex/cache": "^4.0.0",
33
33
  "ioredis": ">=5"
34
34
  },
35
35
  "devDependencies": {
36
- "@aomex/cache": "3.30.6",
37
- "ioredis": "^5.4.1"
36
+ "@aomex/cache": "3.30.8-alpha.131cf1c.0",
37
+ "ioredis": "^6.0.0"
38
38
  },
39
39
  "scripts": {}
40
40
  }