redis-smq-common 1.0.0-rc.0 → 1.0.0-rc.11
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/.codecov.yml +5 -0
- package/CHANGELOG.md +54 -1
- package/README.md +7 -5
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/src/lock-manager/lock-manager.js +7 -1
- package/dist/src/redis-client/clients/ioredis-client-multi.d.ts +24 -0
- package/dist/src/redis-client/clients/ioredis-client-multi.js +108 -0
- package/dist/src/redis-client/clients/ioredis-client.d.ts +56 -0
- package/dist/src/redis-client/clients/ioredis-client.js +192 -0
- package/dist/src/redis-client/clients/node-redis-v3-client-multi.d.ts +24 -0
- package/dist/src/redis-client/clients/node-redis-v3-client-multi.js +89 -0
- package/dist/src/redis-client/clients/node-redis-v3-client.d.ts +56 -0
- package/dist/src/redis-client/clients/node-redis-v3-client.js +224 -0
- package/dist/src/redis-client/clients/node-redis-v4-client-multi.d.ts +23 -0
- package/dist/src/redis-client/clients/node-redis-v4-client-multi.js +91 -0
- package/dist/src/redis-client/clients/node-redis-v4-client.d.ts +56 -0
- package/dist/src/redis-client/clients/node-redis-v4-client.js +292 -0
- package/dist/src/redis-client/create-client-instance.d.ts +3 -0
- package/dist/src/redis-client/create-client-instance.js +33 -0
- package/dist/src/redis-client/{redis-client.error.d.ts → errors/redis-client.error.d.ts} +1 -1
- package/dist/src/redis-client/{redis-client.error.js → errors/redis-client.error.js} +1 -1
- package/dist/src/redis-client/errors/watched-keys-changed.error.d.ts +4 -0
- package/dist/src/redis-client/errors/watched-keys-changed.error.js +11 -0
- package/dist/src/redis-client/lua-scripts.js +1 -1
- package/dist/src/redis-client/redis-client.d.ts +56 -60
- package/dist/src/redis-client/redis-client.js +20 -335
- package/dist/src/worker/worker-runner/worker-runner.d.ts +5 -8
- package/dist/src/worker/worker-runner/worker-runner.js +6 -56
- package/dist/src/worker/worker.d.ts +3 -5
- package/dist/src/worker/worker.js +1 -3
- package/dist/types/index.d.ts +35 -44
- package/dist/types/index.js +1 -0
- package/package.json +19 -3
- package/dist/src/redis-client/lua/zpoprpush.lua +0 -12
- package/dist/src/redis-client/lua/zpushhset.lua +0 -8
package/.codecov.yml
ADDED
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,59 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
-
## 1.0.0-rc.
|
|
3
|
+
## 1.0.0-rc.11 (2022-05-31)
|
|
4
|
+
|
|
5
|
+
* Update RedisClient and IRedisClientMulti interfaces (8732c97)
|
|
6
|
+
|
|
7
|
+
## 1.0.0-rc.10 (2022-05-31)
|
|
8
|
+
|
|
9
|
+
* Fix broken promisify(All) because of ICallback typing (4250e32)
|
|
10
|
+
|
|
11
|
+
## 1.0.0-rc.9 (2022-05-31)
|
|
12
|
+
|
|
13
|
+
* Improve RedisClient typings (27219a6)
|
|
14
|
+
* Set up codecov (98293bd)
|
|
15
|
+
* Fix type coverage (2f4a722)
|
|
16
|
+
|
|
17
|
+
## 1.0.0-rc.8 (2022-05-30)
|
|
18
|
+
|
|
19
|
+
* Add WatchedKeysChangedError class (1e42e80)
|
|
20
|
+
|
|
21
|
+
## 1.0.0-rc.7 (2022-05-30)
|
|
22
|
+
|
|
23
|
+
* Fix various redis errors (9349261)
|
|
24
|
+
|
|
25
|
+
## 1.0.0-rc.6 (2022-05-30)
|
|
26
|
+
|
|
27
|
+
* Fix missing RedisClient from package exports (88f90f0)
|
|
28
|
+
|
|
29
|
+
## 1.0.0-rc.5 (2022-05-30)
|
|
30
|
+
|
|
31
|
+
* Update IRedisClientMulti interface (be1c534)
|
|
32
|
+
|
|
33
|
+
## 1.0.0-rc.4 (2022-05-30)
|
|
34
|
+
|
|
35
|
+
* Update docs (5b88f1d)
|
|
36
|
+
* Clean up (dfccabf)
|
|
37
|
+
* Fix type coverage (a5def8d)
|
|
38
|
+
* Implement RedisClientMulti (fc5a832)
|
|
39
|
+
* Fix redis-client/test00001 (ba817ef)
|
|
40
|
+
* Drop support for node.js v12 (14773ab)
|
|
41
|
+
* Add node-redis v4 support (WIP) (a316490)
|
|
42
|
+
* Add NPM version badge (8fa0d52)
|
|
43
|
+
* Update package keywords (98b6e5e)
|
|
44
|
+
* Update logs.md (fe0e708)
|
|
45
|
+
* Add shared docs (19b9f0b)
|
|
46
|
+
|
|
47
|
+
## 1.0.0-rc.3 (2022-05-26)
|
|
48
|
+
|
|
49
|
+
* Update README.md
|
|
50
|
+
* Refactor and clean up Worker and WorkerRunner classes
|
|
51
|
+
|
|
52
|
+
## 1.0.0-rc.2 (2022-05-25)
|
|
53
|
+
|
|
54
|
+
* Allow children of Worker class to access worker params
|
|
55
|
+
|
|
56
|
+
## 1.0.0-rc.1 (2022-05-24)
|
|
4
57
|
|
|
5
58
|
* Update package keywords and description
|
|
6
59
|
* Use codecov instead of coveralls
|
package/README.md
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
<div align="center" style="text-align: center">
|
|
2
2
|
<p><a href="https://github.com/weyoss/redis-smq-common"><img alt="RedisSMQ" src="./logo.png" /></a></p>
|
|
3
3
|
<p>A simple high-performance Redis message queue for Node.js.</p>
|
|
4
|
-
<p>
|
|
5
|
-
<a href="https://github.com/weyoss/redis-smq-common/actions/workflows/tests.yml"><img src="https://github.com/weyoss/redis-smq-common/actions/workflows/tests.yml/badge.svg" alt="Tests" style="max-width:100%;" /></a>
|
|
6
|
-
<a href="https://codecov.io/github/weyoss/redis-smq-common?branch=master" rel="nofollow"><img src="https://img.shields.io/codecov/c/github/weyoss/redis-smq-common" alt="Coverage Status" /></a>
|
|
7
|
-
<a href="https://lgtm.com/projects/g/weyoss/redis-smq-common/context:javascript" rel="nofollow"><img src="https://img.shields.io/lgtm/grade/javascript/github/weyoss/redis-smq-common.svg?logo=lgtm&logoWidth=18" alt="Code quality" /></a>
|
|
8
|
-
</p>
|
|
9
4
|
</div>
|
|
10
5
|
|
|
11
6
|
## RedisSMQ Common Library
|
|
12
7
|
|
|
8
|
+
<p>
|
|
9
|
+
<a href="https://github.com/weyoss/redis-smq-common/actions/workflows/tests.yml"><img src="https://github.com/weyoss/redis-smq-common/actions/workflows/tests.yml/badge.svg" alt="Tests" style="max-width:100%;" /></a>
|
|
10
|
+
<a href="https://npmjs.org/package/redis-smq-common" rel="nofollow"><img src="https://img.shields.io/npm/v/redis-smq-common.svg" alt="NPM version" /></a>
|
|
11
|
+
<a href="https://codecov.io/github/weyoss/redis-smq-common?branch=master" rel="nofollow"><img src="https://img.shields.io/codecov/c/github/weyoss/redis-smq-common" alt="Coverage Status" /></a>
|
|
12
|
+
<a href="https://lgtm.com/projects/g/weyoss/redis-smq-common/context:javascript" rel="nofollow"><img src="https://img.shields.io/lgtm/grade/javascript/github/weyoss/redis-smq-common.svg?logo=lgtm&logoWidth=18" alt="Code quality" /></a>
|
|
13
|
+
</p>
|
|
14
|
+
|
|
13
15
|
[RedisSMQ](https://github.com/weyoss/redis-smq) shared components that may be used by integrated applications and extensions.
|
|
14
16
|
|
|
15
17
|
## License
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { errors } from './src/errors';
|
|
|
3
3
|
export { LockManager } from './src/lock-manager/lock-manager';
|
|
4
4
|
export { logger } from './src/logger/logger';
|
|
5
5
|
export { PowerManager } from './src/power-manager/power-manager';
|
|
6
|
+
export { createClientInstance } from './src/redis-client/create-client-instance';
|
|
6
7
|
export { RedisClient } from './src/redis-client/redis-client';
|
|
7
8
|
export { Ticker } from './src/ticker/ticker';
|
|
8
9
|
export { Worker } from './src/worker/worker';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.events = exports.WorkerPool = exports.WorkerRunner = exports.Worker = exports.Ticker = exports.RedisClient = exports.PowerManager = exports.logger = exports.LockManager = exports.errors = exports.async = void 0;
|
|
3
|
+
exports.events = exports.WorkerPool = exports.WorkerRunner = exports.Worker = exports.Ticker = exports.RedisClient = exports.createClientInstance = exports.PowerManager = exports.logger = exports.LockManager = exports.errors = exports.async = void 0;
|
|
4
4
|
var async_1 = require("./src/async/async");
|
|
5
5
|
Object.defineProperty(exports, "async", { enumerable: true, get: function () { return async_1.async; } });
|
|
6
6
|
var errors_1 = require("./src/errors");
|
|
@@ -11,6 +11,8 @@ var logger_1 = require("./src/logger/logger");
|
|
|
11
11
|
Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return logger_1.logger; } });
|
|
12
12
|
var power_manager_1 = require("./src/power-manager/power-manager");
|
|
13
13
|
Object.defineProperty(exports, "PowerManager", { enumerable: true, get: function () { return power_manager_1.PowerManager; } });
|
|
14
|
+
var create_client_instance_1 = require("./src/redis-client/create-client-instance");
|
|
15
|
+
Object.defineProperty(exports, "createClientInstance", { enumerable: true, get: function () { return create_client_instance_1.createClientInstance; } });
|
|
14
16
|
var redis_client_1 = require("./src/redis-client/redis-client");
|
|
15
17
|
Object.defineProperty(exports, "RedisClient", { enumerable: true, get: function () { return redis_client_1.RedisClient; } });
|
|
16
18
|
var ticker_1 = require("./src/ticker/ticker");
|
|
@@ -95,7 +95,13 @@ class LockManager {
|
|
|
95
95
|
this.status = ELockStatus.locking;
|
|
96
96
|
const lock = () => {
|
|
97
97
|
if (this.status === ELockStatus.locking) {
|
|
98
|
-
this.redisClient.set(this.lockKey, this.lockId,
|
|
98
|
+
this.redisClient.set(this.lockKey, this.lockId, {
|
|
99
|
+
expire: {
|
|
100
|
+
mode: 'PX',
|
|
101
|
+
value: this.ttl,
|
|
102
|
+
},
|
|
103
|
+
exists: 'NX',
|
|
104
|
+
}, (err, reply) => {
|
|
99
105
|
if (err)
|
|
100
106
|
cb(err);
|
|
101
107
|
else if (this.status === ELockStatus.locking) {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ICallback, IRedisClientMulti } from '../../../types';
|
|
2
|
+
import { Pipeline, Redis } from 'ioredis';
|
|
3
|
+
export declare class IoredisClientMulti implements IRedisClientMulti {
|
|
4
|
+
protected multi: Pipeline;
|
|
5
|
+
constructor(client: Redis);
|
|
6
|
+
lrem(key: string, count: number, element: string): this;
|
|
7
|
+
lpop(key: string): this;
|
|
8
|
+
lpush(key: string, element: string): this;
|
|
9
|
+
ltrim(key: string, start: number, stop: number): this;
|
|
10
|
+
rpop(key: string): this;
|
|
11
|
+
rpush(key: string, element: string): this;
|
|
12
|
+
zadd(key: string, score: number, element: string): this;
|
|
13
|
+
zrem(key: string, element: string | string[]): this;
|
|
14
|
+
sadd(key: string, element: string): this;
|
|
15
|
+
srem(key: string, element: string | string[]): this;
|
|
16
|
+
hset(key: string, field: string, value: string): this;
|
|
17
|
+
hdel(key: string, field: string | string[]): this;
|
|
18
|
+
hincrby(key: string, field: string, by: number): this;
|
|
19
|
+
pexpire(key: string, millis: number): this;
|
|
20
|
+
expire(key: string, secs: number): this;
|
|
21
|
+
rpoplpush(source: string, destination: string): this;
|
|
22
|
+
del(key: string | string[]): this;
|
|
23
|
+
exec(cb: ICallback<unknown[]>): void;
|
|
24
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IoredisClientMulti = void 0;
|
|
4
|
+
const redis_client_error_1 = require("../errors/redis-client.error");
|
|
5
|
+
const watched_keys_changed_error_1 = require("../errors/watched-keys-changed.error");
|
|
6
|
+
class IoredisClientMulti {
|
|
7
|
+
constructor(client) {
|
|
8
|
+
this.multi = client.multi();
|
|
9
|
+
}
|
|
10
|
+
lrem(key, count, element) {
|
|
11
|
+
this.multi.lrem(key, count, element);
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
lpop(key) {
|
|
15
|
+
this.multi.lpop(key);
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
lpush(key, element) {
|
|
19
|
+
this.multi.lpush(key, element);
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
ltrim(key, start, stop) {
|
|
23
|
+
this.multi.ltrim(key, start, stop);
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
rpop(key) {
|
|
27
|
+
this.multi.rpop(key);
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
rpush(key, element) {
|
|
31
|
+
this.multi.rpush(key, element);
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
zadd(key, score, element) {
|
|
35
|
+
this.multi.zadd(key, score, element);
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
zrem(key, element) {
|
|
39
|
+
this.multi.zrem(key, ...(typeof element === 'string' ? [element] : element));
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
sadd(key, element) {
|
|
43
|
+
this.multi.sadd(key, element);
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
srem(key, element) {
|
|
47
|
+
this.multi.srem(key, ...(typeof element === 'string' ? [element] : element));
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
hset(key, field, value) {
|
|
51
|
+
this.multi.hset(key, field, value);
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
hdel(key, field) {
|
|
55
|
+
this.multi.hdel(key, ...(typeof field === 'string' ? [field] : field));
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
hincrby(key, field, by) {
|
|
59
|
+
this.multi.hincrby(key, field, by);
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
pexpire(key, millis) {
|
|
63
|
+
this.multi.pexpire(key, millis);
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
expire(key, secs) {
|
|
67
|
+
this.multi.expire(key, secs);
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
rpoplpush(source, destination) {
|
|
71
|
+
this.multi.rpoplpush(source, destination);
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
del(key) {
|
|
75
|
+
this.multi.del(...(typeof key === 'string' ? [key] : key));
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
exec(cb) {
|
|
79
|
+
this.multi.exec((err, reply) => {
|
|
80
|
+
if (err)
|
|
81
|
+
cb(err);
|
|
82
|
+
else if (!reply)
|
|
83
|
+
cb(new watched_keys_changed_error_1.WatchedKeysChangedError());
|
|
84
|
+
else {
|
|
85
|
+
const lengths = [];
|
|
86
|
+
let err = null;
|
|
87
|
+
for (const i of reply) {
|
|
88
|
+
if (!Array.isArray(i)) {
|
|
89
|
+
err = new redis_client_error_1.RedisClientError('Expected an array reply from multi.exec()');
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
const [error, result] = i;
|
|
93
|
+
if (error instanceof Error) {
|
|
94
|
+
err = error;
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
lengths.push(result);
|
|
98
|
+
}
|
|
99
|
+
if (err)
|
|
100
|
+
cb(err);
|
|
101
|
+
else
|
|
102
|
+
cb(null, lengths);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.IoredisClientMulti = IoredisClientMulti;
|
|
108
|
+
//# sourceMappingURL=ioredis-client-multi.js.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { RedisClient } from '../redis-client';
|
|
2
|
+
import { Redis, RedisOptions } from 'ioredis';
|
|
3
|
+
import { ICallback } from '../../../types';
|
|
4
|
+
import { IoredisClientMulti } from './ioredis-client-multi';
|
|
5
|
+
export declare class IoredisClient extends RedisClient {
|
|
6
|
+
protected client: Redis;
|
|
7
|
+
constructor(config?: RedisOptions);
|
|
8
|
+
set(key: string, value: string, options: {
|
|
9
|
+
expire?: {
|
|
10
|
+
mode: 'EX' | 'PX';
|
|
11
|
+
value: number;
|
|
12
|
+
};
|
|
13
|
+
exists?: 'NX' | 'XX';
|
|
14
|
+
}, cb: ICallback<string | null>): void;
|
|
15
|
+
zadd(key: string, score: number, member: string, cb: ICallback<number | string>): void;
|
|
16
|
+
multi(): IoredisClientMulti;
|
|
17
|
+
watch(args: string[], cb: ICallback<string>): void;
|
|
18
|
+
unwatch(cb: ICallback<string>): void;
|
|
19
|
+
sismember(key: string, member: string, cb: ICallback<number>): void;
|
|
20
|
+
zcard(key: string, cb: ICallback<number>): void;
|
|
21
|
+
zrange(key: string, min: number, max: number, cb: ICallback<string[]>): void;
|
|
22
|
+
psubscribe(pattern: string): void;
|
|
23
|
+
punsubscribe(channel: string): void;
|
|
24
|
+
subscribe(channel: string): void;
|
|
25
|
+
unsubscribe(channel: string): void;
|
|
26
|
+
zrangebyscore(key: string, min: number | string, max: number | string, cb: ICallback<string[]>): void;
|
|
27
|
+
smembers(key: string, cb: ICallback<string[]>): void;
|
|
28
|
+
sadd(key: string, member: string, cb: ICallback<number>): void;
|
|
29
|
+
hgetall(key: string, cb: ICallback<Record<string, string>>): void;
|
|
30
|
+
hget(key: string, field: string, cb: ICallback<string | null>): void;
|
|
31
|
+
hset(key: string, field: string, value: string, cb: ICallback<number>): void;
|
|
32
|
+
hdel(key: string, fields: string | string[], cb: ICallback<number>): void;
|
|
33
|
+
lrange(key: string, start: number, stop: number, cb: ICallback<string[]>): void;
|
|
34
|
+
hkeys(key: string, cb: ICallback<string[]>): void;
|
|
35
|
+
hlen(key: string, cb: ICallback<number>): void;
|
|
36
|
+
brpoplpush(source: string, destination: string, timeout: number, cb: ICallback<string | null>): void;
|
|
37
|
+
rpoplpush(source: string, destination: string, cb: ICallback<string | null>): void;
|
|
38
|
+
zrangebyscorewithscores(source: string, min: number, max: number, cb: ICallback<Record<string, string>>): void;
|
|
39
|
+
rpop(key: string, cb: ICallback<string | null>): void;
|
|
40
|
+
lrem(key: string, count: number, element: string, cb: ICallback<number>): void;
|
|
41
|
+
publish(channel: string, message: string, cb: ICallback<number>): void;
|
|
42
|
+
flushall(cb: ICallback<string>): void;
|
|
43
|
+
loadScript(script: string, cb: ICallback<string>): void;
|
|
44
|
+
evalsha(hash: string, args: (string | number)[] | string | number, cb: (err?: Error | null, res?: unknown) => void): void;
|
|
45
|
+
get(key: string, cb: ICallback<string | null>): void;
|
|
46
|
+
del(key: string | string[], cb: ICallback<number>): void;
|
|
47
|
+
llen(key: string, cb: ICallback<number>): void;
|
|
48
|
+
lmove(source: string, destination: string, from: 'LEFT' | 'RIGHT', to: 'LEFT' | 'RIGHT', cb: ICallback<string | null>): void;
|
|
49
|
+
zremrangebyscore(source: string, min: number | string, max: number | string, cb: ICallback<number>): void;
|
|
50
|
+
hmget(source: string, keys: string[], cb: ICallback<(string | null)[]>): void;
|
|
51
|
+
halt(cb: ICallback<void>): void;
|
|
52
|
+
end(flush: boolean): void;
|
|
53
|
+
quit(cb?: ICallback<void>): void;
|
|
54
|
+
getInfo(cb: ICallback<string>): void;
|
|
55
|
+
on(event: string, listener: (...args: unknown[]) => any): this;
|
|
56
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IoredisClient = void 0;
|
|
4
|
+
const redis_client_1 = require("../redis-client");
|
|
5
|
+
const redis_client_error_1 = require("../errors/redis-client.error");
|
|
6
|
+
const IORedis = require("ioredis");
|
|
7
|
+
const ioredis_client_multi_1 = require("./ioredis-client-multi");
|
|
8
|
+
class IoredisClient extends redis_client_1.RedisClient {
|
|
9
|
+
constructor(config = {}) {
|
|
10
|
+
super();
|
|
11
|
+
this.client = new IORedis(config);
|
|
12
|
+
this.client.once('ready', () => {
|
|
13
|
+
this.connectionClosed = false;
|
|
14
|
+
this.emit('ready');
|
|
15
|
+
});
|
|
16
|
+
this.client.once('end', () => {
|
|
17
|
+
this.connectionClosed = true;
|
|
18
|
+
this.emit('end');
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
set(key, value, options, cb) {
|
|
22
|
+
if (options.exists && options.expire) {
|
|
23
|
+
this.client.set(key, value, options.expire.mode, options.expire.value, options.exists, cb);
|
|
24
|
+
}
|
|
25
|
+
else if (options.expire) {
|
|
26
|
+
this.client.set(key, value, options.expire.mode, options.expire.value, cb);
|
|
27
|
+
}
|
|
28
|
+
else if (options.exists) {
|
|
29
|
+
this.client.set(key, value, options.exists, cb);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
this.client.set(key, value, cb);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
zadd(key, score, member, cb) {
|
|
36
|
+
this.client.zadd(key, score, member, cb);
|
|
37
|
+
}
|
|
38
|
+
multi() {
|
|
39
|
+
return new ioredis_client_multi_1.IoredisClientMulti(this.client);
|
|
40
|
+
}
|
|
41
|
+
watch(args, cb) {
|
|
42
|
+
this.client.watch(args, cb);
|
|
43
|
+
}
|
|
44
|
+
unwatch(cb) {
|
|
45
|
+
this.client.unwatch(cb);
|
|
46
|
+
}
|
|
47
|
+
sismember(key, member, cb) {
|
|
48
|
+
this.client.sismember(key, member, cb);
|
|
49
|
+
}
|
|
50
|
+
zcard(key, cb) {
|
|
51
|
+
this.client.zcard(key, cb);
|
|
52
|
+
}
|
|
53
|
+
zrange(key, min, max, cb) {
|
|
54
|
+
this.client.zrange(key, min, max, cb);
|
|
55
|
+
}
|
|
56
|
+
psubscribe(pattern) {
|
|
57
|
+
this.client.psubscribe(pattern);
|
|
58
|
+
}
|
|
59
|
+
punsubscribe(channel) {
|
|
60
|
+
this.client.punsubscribe(channel);
|
|
61
|
+
}
|
|
62
|
+
subscribe(channel) {
|
|
63
|
+
this.client.subscribe(channel);
|
|
64
|
+
}
|
|
65
|
+
unsubscribe(channel) {
|
|
66
|
+
this.client.unsubscribe(channel);
|
|
67
|
+
}
|
|
68
|
+
zrangebyscore(key, min, max, cb) {
|
|
69
|
+
this.client.zrangebyscore(key, min, max, cb);
|
|
70
|
+
}
|
|
71
|
+
smembers(key, cb) {
|
|
72
|
+
this.client.smembers(key, cb);
|
|
73
|
+
}
|
|
74
|
+
sadd(key, member, cb) {
|
|
75
|
+
this.client.sadd(key, member, cb);
|
|
76
|
+
}
|
|
77
|
+
hgetall(key, cb) {
|
|
78
|
+
this.client.hgetall(key, cb);
|
|
79
|
+
}
|
|
80
|
+
hget(key, field, cb) {
|
|
81
|
+
this.client.hget(key, field, cb);
|
|
82
|
+
}
|
|
83
|
+
hset(key, field, value, cb) {
|
|
84
|
+
this.client.hset(key, field, value, cb);
|
|
85
|
+
}
|
|
86
|
+
hdel(key, fields, cb) {
|
|
87
|
+
this.client.hdel(key, fields, cb);
|
|
88
|
+
}
|
|
89
|
+
lrange(key, start, stop, cb) {
|
|
90
|
+
this.client.lrange(key, start, stop, cb);
|
|
91
|
+
}
|
|
92
|
+
hkeys(key, cb) {
|
|
93
|
+
this.client.hkeys(key, cb);
|
|
94
|
+
}
|
|
95
|
+
hlen(key, cb) {
|
|
96
|
+
this.client.hlen(key, cb);
|
|
97
|
+
}
|
|
98
|
+
brpoplpush(source, destination, timeout, cb) {
|
|
99
|
+
this.client.brpoplpush(source, destination, timeout, cb);
|
|
100
|
+
}
|
|
101
|
+
rpoplpush(source, destination, cb) {
|
|
102
|
+
this.client.rpoplpush(source, destination, cb);
|
|
103
|
+
}
|
|
104
|
+
zrangebyscorewithscores(source, min, max, cb) {
|
|
105
|
+
this.client.zrangebyscore(source, min, max, 'WITHSCORES', (err, reply) => {
|
|
106
|
+
if (err)
|
|
107
|
+
cb(err);
|
|
108
|
+
else {
|
|
109
|
+
const replyRange = reply !== null && reply !== void 0 ? reply : [];
|
|
110
|
+
const range = {};
|
|
111
|
+
for (let slice = replyRange.splice(0, 2); slice.length > 0; slice = replyRange.splice(0, 2)) {
|
|
112
|
+
const [member, score] = slice;
|
|
113
|
+
range[score] = member;
|
|
114
|
+
}
|
|
115
|
+
cb(null, range);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
rpop(key, cb) {
|
|
120
|
+
this.client.rpop(key, cb);
|
|
121
|
+
}
|
|
122
|
+
lrem(key, count, element, cb) {
|
|
123
|
+
this.client.lrem(key, count, element, cb);
|
|
124
|
+
}
|
|
125
|
+
publish(channel, message, cb) {
|
|
126
|
+
this.client.publish(channel, message, cb);
|
|
127
|
+
}
|
|
128
|
+
flushall(cb) {
|
|
129
|
+
this.client.flushall(cb);
|
|
130
|
+
}
|
|
131
|
+
loadScript(script, cb) {
|
|
132
|
+
this.client.script('load', script, cb);
|
|
133
|
+
}
|
|
134
|
+
evalsha(hash, args, cb) {
|
|
135
|
+
const arrHash = [hash];
|
|
136
|
+
const arrArgs = Array.isArray(args) ? args : [args];
|
|
137
|
+
this.client.evalsha(arrHash.concat(arrArgs), cb);
|
|
138
|
+
}
|
|
139
|
+
get(key, cb) {
|
|
140
|
+
this.client.get(key, cb);
|
|
141
|
+
}
|
|
142
|
+
del(key, cb) {
|
|
143
|
+
this.client.del(key, cb);
|
|
144
|
+
}
|
|
145
|
+
llen(key, cb) {
|
|
146
|
+
this.client.llen(key, cb);
|
|
147
|
+
}
|
|
148
|
+
lmove(source, destination, from, to, cb) {
|
|
149
|
+
if (!this.validateRedisVersion(6, 2)) {
|
|
150
|
+
cb(new redis_client_error_1.RedisClientError('Command not supported by your Redis server. Minimal required Redis server version is 6.2.0.'));
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
this.client.lmove(source, destination, from, to, cb);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
zremrangebyscore(source, min, max, cb) {
|
|
157
|
+
this.client.zremrangebyscore(source, min, max, cb);
|
|
158
|
+
}
|
|
159
|
+
hmget(source, keys, cb) {
|
|
160
|
+
this.client.hmget(source, keys, cb);
|
|
161
|
+
}
|
|
162
|
+
halt(cb) {
|
|
163
|
+
if (!this.connectionClosed) {
|
|
164
|
+
this.client.once('end', cb);
|
|
165
|
+
this.end(true);
|
|
166
|
+
}
|
|
167
|
+
else
|
|
168
|
+
cb();
|
|
169
|
+
}
|
|
170
|
+
end(flush) {
|
|
171
|
+
if (!this.connectionClosed) {
|
|
172
|
+
this.client.disconnect(false);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
quit(cb = () => void 0) {
|
|
176
|
+
if (!this.connectionClosed) {
|
|
177
|
+
this.client.once('end', cb);
|
|
178
|
+
this.client.quit();
|
|
179
|
+
}
|
|
180
|
+
else
|
|
181
|
+
cb();
|
|
182
|
+
}
|
|
183
|
+
getInfo(cb) {
|
|
184
|
+
this.client.info(cb);
|
|
185
|
+
}
|
|
186
|
+
on(event, listener) {
|
|
187
|
+
this.client.on(event, listener);
|
|
188
|
+
return this;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
exports.IoredisClient = IoredisClient;
|
|
192
|
+
//# sourceMappingURL=ioredis-client.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ICallback, IRedisClientMulti } from '../../../types';
|
|
2
|
+
import { Multi, RedisClient } from 'redis';
|
|
3
|
+
export declare class NodeRedisV3ClientMulti implements IRedisClientMulti {
|
|
4
|
+
protected multi: Multi;
|
|
5
|
+
constructor(client: RedisClient);
|
|
6
|
+
lrem(key: string, count: number, element: string): this;
|
|
7
|
+
lpop(key: string): this;
|
|
8
|
+
lpush(key: string, element: string): this;
|
|
9
|
+
ltrim(key: string, start: number, stop: number): this;
|
|
10
|
+
rpop(key: string): this;
|
|
11
|
+
rpush(key: string, element: string): this;
|
|
12
|
+
zadd(key: string, score: number, element: string): this;
|
|
13
|
+
zrem(key: string, element: string | string[]): this;
|
|
14
|
+
sadd(key: string, element: string): this;
|
|
15
|
+
srem(key: string, element: string | string[]): this;
|
|
16
|
+
hset(key: string, field: string, value: string): this;
|
|
17
|
+
hdel(key: string, field: string | string[]): this;
|
|
18
|
+
hincrby(key: string, field: string, by: number): this;
|
|
19
|
+
pexpire(key: string, millis: number): this;
|
|
20
|
+
expire(key: string, secs: number): this;
|
|
21
|
+
rpoplpush(source: string, destination: string): this;
|
|
22
|
+
del(key: string | string[]): this;
|
|
23
|
+
exec(cb: ICallback<unknown[]>): void;
|
|
24
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NodeRedisV3ClientMulti = void 0;
|
|
4
|
+
const watched_keys_changed_error_1 = require("../errors/watched-keys-changed.error");
|
|
5
|
+
class NodeRedisV3ClientMulti {
|
|
6
|
+
constructor(client) {
|
|
7
|
+
this.multi = client.multi();
|
|
8
|
+
}
|
|
9
|
+
lrem(key, count, element) {
|
|
10
|
+
this.multi.lrem(key, count, element);
|
|
11
|
+
return this;
|
|
12
|
+
}
|
|
13
|
+
lpop(key) {
|
|
14
|
+
this.multi.lpop(key);
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
lpush(key, element) {
|
|
18
|
+
this.multi.lpush(key, element);
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
ltrim(key, start, stop) {
|
|
22
|
+
this.multi.ltrim(key, start, stop);
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
rpop(key) {
|
|
26
|
+
this.multi.rpop(key);
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
rpush(key, element) {
|
|
30
|
+
this.multi.rpush(key, element);
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
zadd(key, score, element) {
|
|
34
|
+
this.multi.zadd(key, score, element);
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
zrem(key, element) {
|
|
38
|
+
this.multi.zrem(key, element);
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
sadd(key, element) {
|
|
42
|
+
this.multi.sadd(key, element);
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
srem(key, element) {
|
|
46
|
+
this.multi.srem(key, element);
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
hset(key, field, value) {
|
|
50
|
+
this.multi.hset(key, field, value);
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
hdel(key, field) {
|
|
54
|
+
this.multi.hdel(key, field);
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
hincrby(key, field, by) {
|
|
58
|
+
this.multi.hincrby(key, field, by);
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
pexpire(key, millis) {
|
|
62
|
+
this.multi.pexpire(key, millis);
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
expire(key, secs) {
|
|
66
|
+
this.multi.expire(key, secs);
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
rpoplpush(source, destination) {
|
|
70
|
+
this.multi.rpoplpush(source, destination);
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
del(key) {
|
|
74
|
+
this.multi.del(key);
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
exec(cb) {
|
|
78
|
+
this.multi.exec((err, reply) => {
|
|
79
|
+
if (err)
|
|
80
|
+
cb(err);
|
|
81
|
+
else if (!reply)
|
|
82
|
+
cb(new watched_keys_changed_error_1.WatchedKeysChangedError());
|
|
83
|
+
else
|
|
84
|
+
cb(null, reply);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.NodeRedisV3ClientMulti = NodeRedisV3ClientMulti;
|
|
89
|
+
//# sourceMappingURL=node-redis-v3-client-multi.js.map
|