@mulingai-npm/redis 3.7.0 → 3.7.1
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/dist/redis-client.d.ts +0 -8
- package/dist/redis-client.js +0 -33
- package/package.json +1 -1
package/dist/redis-client.d.ts
CHANGED
|
@@ -5,18 +5,10 @@ export interface RedisConfig {
|
|
|
5
5
|
password?: string;
|
|
6
6
|
db: number;
|
|
7
7
|
}
|
|
8
|
-
/**
|
|
9
|
-
* Thin wrapper around ioredis that exposes exactly the helpers used by the two
|
|
10
|
-
* managers. All helpers are 1-to-1 pass-through so there is no behavioural
|
|
11
|
-
* change – this merely centralises typing and keeps the rest of the codebase
|
|
12
|
-
* clean.
|
|
13
|
-
*/
|
|
14
8
|
export declare class RedisClient {
|
|
15
9
|
private client;
|
|
16
10
|
constructor(config: RedisConfig);
|
|
17
11
|
set(key: string, value: string): Promise<void>;
|
|
18
|
-
/** Atomic SET with NX + EX.
|
|
19
|
-
* @returns true if the key was set, false when it already existed */
|
|
20
12
|
setNxEx(key: string, value: string, expireSeconds: number): Promise<boolean>;
|
|
21
13
|
get(key: string): Promise<string | null>;
|
|
22
14
|
del(key: string): Promise<number>;
|
package/dist/redis-client.js
CHANGED
|
@@ -5,12 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.RedisClient = void 0;
|
|
7
7
|
const ioredis_1 = __importDefault(require("ioredis"));
|
|
8
|
-
/**
|
|
9
|
-
* Thin wrapper around ioredis that exposes exactly the helpers used by the two
|
|
10
|
-
* managers. All helpers are 1-to-1 pass-through so there is no behavioural
|
|
11
|
-
* change – this merely centralises typing and keeps the rest of the codebase
|
|
12
|
-
* clean.
|
|
13
|
-
*/
|
|
14
8
|
class RedisClient {
|
|
15
9
|
constructor(config) {
|
|
16
10
|
this.client = new ioredis_1.default({
|
|
@@ -23,14 +17,9 @@ class RedisClient {
|
|
|
23
17
|
console.error('Redis error:', err);
|
|
24
18
|
});
|
|
25
19
|
}
|
|
26
|
-
/* ----------------------------------------------------------------------- */
|
|
27
|
-
/* Primitive string helpers */
|
|
28
|
-
/* ----------------------------------------------------------------------- */
|
|
29
20
|
async set(key, value) {
|
|
30
21
|
await this.client.set(key, value);
|
|
31
22
|
}
|
|
32
|
-
/** Atomic SET with NX + EX.
|
|
33
|
-
* @returns true if the key was set, false when it already existed */
|
|
34
23
|
async setNxEx(key, value, expireSeconds) {
|
|
35
24
|
// correct order: 'EX', ttl, 'NX'
|
|
36
25
|
const res = (await this.client.set(key, value, 'EX', expireSeconds, 'NX'));
|
|
@@ -48,9 +37,6 @@ class RedisClient {
|
|
|
48
37
|
async expire(key, seconds) {
|
|
49
38
|
return this.client.expire(key, seconds);
|
|
50
39
|
}
|
|
51
|
-
/* ----------------------------------------------------------------------- */
|
|
52
|
-
/* Set helpers */
|
|
53
|
-
/* ----------------------------------------------------------------------- */
|
|
54
40
|
async sadd(key, ...values) {
|
|
55
41
|
return this.client.sadd(key, values);
|
|
56
42
|
}
|
|
@@ -60,18 +46,12 @@ class RedisClient {
|
|
|
60
46
|
async smembers(key) {
|
|
61
47
|
return this.client.smembers(key);
|
|
62
48
|
}
|
|
63
|
-
/* ----------------------------------------------------------------------- */
|
|
64
|
-
/* Hash helpers */
|
|
65
|
-
/* ----------------------------------------------------------------------- */
|
|
66
49
|
async hset(key, data) {
|
|
67
50
|
return this.client.hset(key, data);
|
|
68
51
|
}
|
|
69
52
|
async hgetall(key) {
|
|
70
53
|
return this.client.hgetall(key);
|
|
71
54
|
}
|
|
72
|
-
/* ----------------------------------------------------------------------- */
|
|
73
|
-
/* Sorted-set helpers */
|
|
74
|
-
/* ----------------------------------------------------------------------- */
|
|
75
55
|
async zadd(key, score, member) {
|
|
76
56
|
return this.client.zadd(key, score, member);
|
|
77
57
|
}
|
|
@@ -87,24 +67,15 @@ class RedisClient {
|
|
|
87
67
|
async zrem(key, ...members) {
|
|
88
68
|
return this.client.zrem(key, members);
|
|
89
69
|
}
|
|
90
|
-
/* ----------------------------------------------------------------------- */
|
|
91
|
-
/* Scan (pattern search) */
|
|
92
|
-
/* ----------------------------------------------------------------------- */
|
|
93
70
|
async scan(cursor, pattern, count = 1000) {
|
|
94
71
|
return this.client.scan(cursor, 'MATCH', pattern, 'COUNT', count);
|
|
95
72
|
}
|
|
96
73
|
async keys(pattern) {
|
|
97
74
|
return this.client.keys(pattern);
|
|
98
75
|
}
|
|
99
|
-
/* ----------------------------------------------------------------------- */
|
|
100
|
-
/* Pipeline */
|
|
101
|
-
/* ----------------------------------------------------------------------- */
|
|
102
76
|
pipeline() {
|
|
103
77
|
return this.client.pipeline();
|
|
104
78
|
}
|
|
105
|
-
/* ----------------------------------------------------------------------- */
|
|
106
|
-
/* Misc */
|
|
107
|
-
/* ----------------------------------------------------------------------- */
|
|
108
79
|
async unlink(...keys) {
|
|
109
80
|
// unlink exists on Redis ≥4 and is supported by ioredis but not typed in
|
|
110
81
|
// older versions – we cast to any.
|
|
@@ -112,7 +83,6 @@ class RedisClient {
|
|
|
112
83
|
// @ts-ignore – runtime command exists even if typings lag behind.
|
|
113
84
|
return this.client.unlink(...keys);
|
|
114
85
|
}
|
|
115
|
-
/* JSON commands (RedisJSON module) -------------------------------------- */
|
|
116
86
|
async jsonSet(key, path, value) {
|
|
117
87
|
const result = await this.client.call('JSON.SET', key, path, JSON.stringify(value));
|
|
118
88
|
return result;
|
|
@@ -135,9 +105,6 @@ class RedisClient {
|
|
|
135
105
|
async jsonArrPop(key, path, index) {
|
|
136
106
|
return index !== undefined ? this.client.call('JSON.ARRPOP', key, path, index) : this.client.call('JSON.ARRPOP', key, path);
|
|
137
107
|
}
|
|
138
|
-
/* ----------------------------------------------------------------------- */
|
|
139
|
-
/* Dangerous! – flush helpers */
|
|
140
|
-
/* ----------------------------------------------------------------------- */
|
|
141
108
|
async flushAll() {
|
|
142
109
|
console.warn('Flushing all Redis data!');
|
|
143
110
|
return this.client.flushall();
|