redis-smq-common 1.0.0-rc.2 → 1.0.0-rc.5
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 +23 -0
- package/README.md +7 -5
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/src/lock-manager/lock-manager.js +7 -1
- package/dist/src/redis-client/clients/ioredis-client-multi.d.ts +22 -0
- package/dist/src/redis-client/clients/ioredis-client-multi.js +99 -0
- package/dist/src/redis-client/clients/ioredis-client.d.ts +54 -0
- package/dist/src/redis-client/clients/ioredis-client.js +186 -0
- package/dist/src/redis-client/clients/node-redis-v3-client-multi.d.ts +22 -0
- package/dist/src/redis-client/clients/node-redis-v3-client-multi.js +81 -0
- package/dist/src/redis-client/clients/node-redis-v3-client.d.ts +54 -0
- package/dist/src/redis-client/clients/node-redis-v3-client.js +218 -0
- package/dist/src/redis-client/clients/node-redis-v4-client-multi.d.ts +21 -0
- package/dist/src/redis-client/clients/node-redis-v4-client-multi.js +76 -0
- package/dist/src/redis-client/clients/node-redis-v4-client.d.ts +54 -0
- package/dist/src/redis-client/clients/node-redis-v4-client.js +284 -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/lua-scripts.js +1 -1
- package/dist/src/redis-client/redis-client.d.ts +53 -59
- 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 -6
- package/dist/src/worker/worker.js +1 -4
- package/dist/types/index.d.ts +31 -42
- 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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 1.0.0-rc.5 (2022-05-30)
|
|
4
|
+
|
|
5
|
+
Update IRedisClientMulti interface (be1c534)
|
|
6
|
+
|
|
7
|
+
## 1.0.0-rc.4 (2022-05-30)
|
|
8
|
+
|
|
9
|
+
* Update docs (5b88f1d)
|
|
10
|
+
* Clean up (dfccabf)
|
|
11
|
+
* Fix type coverage (a5def8d)
|
|
12
|
+
* Implement RedisClientMulti (fc5a832)
|
|
13
|
+
* Fix redis-client/test00001 (ba817ef)
|
|
14
|
+
* Drop support for node.js v12 (14773ab)
|
|
15
|
+
* Add node-redis v4 support (WIP) (a316490)
|
|
16
|
+
* Add NPM version badge (8fa0d52)
|
|
17
|
+
* Update package keywords (98b6e5e)
|
|
18
|
+
* Update logs.md (fe0e708)
|
|
19
|
+
* Add shared docs (19b9f0b)
|
|
20
|
+
|
|
21
|
+
## 1.0.0-rc.3 (2022-05-26)
|
|
22
|
+
|
|
23
|
+
* Update README.md
|
|
24
|
+
* Refactor and clean up Worker and WorkerRunner classes
|
|
25
|
+
|
|
3
26
|
## 1.0.0-rc.2 (2022-05-25)
|
|
4
27
|
|
|
5
28
|
* Allow children of Worker class to access worker params
|
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,7 +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 {
|
|
6
|
+
export { createClientInstance } from './src/redis-client/create-client-instance';
|
|
7
7
|
export { Ticker } from './src/ticker/ticker';
|
|
8
8
|
export { Worker } from './src/worker/worker';
|
|
9
9
|
export { WorkerRunner } from './src/worker/worker-runner/worker-runner';
|
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.
|
|
3
|
+
exports.events = exports.WorkerPool = exports.WorkerRunner = exports.Worker = exports.Ticker = 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,8 +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
|
|
15
|
-
Object.defineProperty(exports, "
|
|
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; } });
|
|
16
16
|
var ticker_1 = require("./src/ticker/ticker");
|
|
17
17
|
Object.defineProperty(exports, "Ticker", { enumerable: true, get: function () { return ticker_1.Ticker; } });
|
|
18
18
|
var worker_1 = require("./src/worker/worker");
|
|
@@ -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,22 @@
|
|
|
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): 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): this;
|
|
18
|
+
pexpire(key: string, millis: number): this;
|
|
19
|
+
rpoplpush(source: string, destination: string): this;
|
|
20
|
+
del(key: string | string[]): this;
|
|
21
|
+
exec(cb: ICallback<unknown[]>): void;
|
|
22
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
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
|
+
class IoredisClientMulti {
|
|
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
|
+
pexpire(key, millis) {
|
|
58
|
+
this.multi.pexpire(key, millis);
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
rpoplpush(source, destination) {
|
|
62
|
+
this.multi.rpoplpush(source, destination);
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
del(key) {
|
|
66
|
+
this.multi.del(...key);
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
exec(cb) {
|
|
70
|
+
this.multi.exec((err, reply) => {
|
|
71
|
+
if (err)
|
|
72
|
+
cb(err);
|
|
73
|
+
else if (!reply)
|
|
74
|
+
cb(new redis_client_error_1.RedisClientError(`Redis transaction has been abandoned. Try again.`));
|
|
75
|
+
else {
|
|
76
|
+
const lengths = [];
|
|
77
|
+
let err = null;
|
|
78
|
+
for (const i of reply) {
|
|
79
|
+
if (!Array.isArray(i)) {
|
|
80
|
+
err = new redis_client_error_1.RedisClientError('Expected an array reply from multi.exec()');
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
const [error, result] = i;
|
|
84
|
+
if (error instanceof Error) {
|
|
85
|
+
err = error;
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
lengths.push(result);
|
|
89
|
+
}
|
|
90
|
+
if (err)
|
|
91
|
+
cb(err);
|
|
92
|
+
else
|
|
93
|
+
cb(null, lengths);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.IoredisClientMulti = IoredisClientMulti;
|
|
99
|
+
//# sourceMappingURL=ioredis-client-multi.js.map
|
|
@@ -0,0 +1,54 @@
|
|
|
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>): 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
|
+
zrangebyscore(key: string, min: number | string, max: number | string, cb: ICallback<string[]>): void;
|
|
25
|
+
smembers(key: string, cb: ICallback<string[]>): void;
|
|
26
|
+
sadd(key: string, member: string, cb: ICallback<number>): void;
|
|
27
|
+
hgetall(key: string, cb: ICallback<Record<string, string>>): void;
|
|
28
|
+
hget(key: string, field: string, cb: ICallback<string>): void;
|
|
29
|
+
hset(key: string, field: string, value: string, cb: ICallback<number>): void;
|
|
30
|
+
hdel(key: string, fields: string | string[], cb: ICallback<number>): void;
|
|
31
|
+
lrange(key: string, start: number, stop: number, cb: ICallback<string[]>): void;
|
|
32
|
+
hkeys(key: string, cb: ICallback<string[]>): void;
|
|
33
|
+
hlen(key: string, cb: ICallback<number>): void;
|
|
34
|
+
brpoplpush(source: string, destination: string, timeout: number, cb: ICallback<string>): void;
|
|
35
|
+
rpoplpush(source: string, destination: string, cb: ICallback<string>): void;
|
|
36
|
+
zrangebyscorewithscores(source: string, min: number, max: number, cb: ICallback<Record<string, string>>): void;
|
|
37
|
+
rpop(key: string, cb: ICallback<string>): void;
|
|
38
|
+
lrem(key: string, count: number, element: string, cb: ICallback<number>): void;
|
|
39
|
+
publish(channel: string, message: string, cb: ICallback<number>): void;
|
|
40
|
+
flushall(cb: ICallback<string>): void;
|
|
41
|
+
loadScript(script: string, cb: ICallback<string>): void;
|
|
42
|
+
evalsha(hash: string, args: (string | number)[] | string | number, cb: (err?: Error | null, res?: unknown) => void): void;
|
|
43
|
+
get(key: string, cb: ICallback<string>): void;
|
|
44
|
+
del(key: string | string[], cb: ICallback<number>): void;
|
|
45
|
+
llen(key: string, cb: ICallback<number>): void;
|
|
46
|
+
lmove(source: string, destination: string, from: 'LEFT' | 'RIGHT', to: 'LEFT' | 'RIGHT', cb: ICallback<string>): void;
|
|
47
|
+
zremrangebyscore(source: string, min: number | string, max: number | string, cb: ICallback<number>): void;
|
|
48
|
+
hmget(source: string, keys: string[], cb: ICallback<(string | null)[]>): void;
|
|
49
|
+
halt(cb: ICallback<void>): void;
|
|
50
|
+
end(flush: boolean): void;
|
|
51
|
+
quit(cb?: ICallback<void>): void;
|
|
52
|
+
getInfo(cb: ICallback<string>): void;
|
|
53
|
+
on(event: string, listener: (...args: unknown[]) => any): this;
|
|
54
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
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
|
+
zrangebyscore(key, min, max, cb) {
|
|
63
|
+
this.client.zrangebyscore(key, min, max, cb);
|
|
64
|
+
}
|
|
65
|
+
smembers(key, cb) {
|
|
66
|
+
this.client.smembers(key, cb);
|
|
67
|
+
}
|
|
68
|
+
sadd(key, member, cb) {
|
|
69
|
+
this.client.sadd(key, member, cb);
|
|
70
|
+
}
|
|
71
|
+
hgetall(key, cb) {
|
|
72
|
+
this.client.hgetall(key, cb);
|
|
73
|
+
}
|
|
74
|
+
hget(key, field, cb) {
|
|
75
|
+
this.client.hget(key, field, cb);
|
|
76
|
+
}
|
|
77
|
+
hset(key, field, value, cb) {
|
|
78
|
+
this.client.hset(key, field, value, cb);
|
|
79
|
+
}
|
|
80
|
+
hdel(key, fields, cb) {
|
|
81
|
+
this.client.hdel(key, fields, cb);
|
|
82
|
+
}
|
|
83
|
+
lrange(key, start, stop, cb) {
|
|
84
|
+
this.client.lrange(key, start, stop, cb);
|
|
85
|
+
}
|
|
86
|
+
hkeys(key, cb) {
|
|
87
|
+
this.client.hkeys(key, cb);
|
|
88
|
+
}
|
|
89
|
+
hlen(key, cb) {
|
|
90
|
+
this.client.hlen(key, cb);
|
|
91
|
+
}
|
|
92
|
+
brpoplpush(source, destination, timeout, cb) {
|
|
93
|
+
this.client.brpoplpush(source, destination, timeout, cb);
|
|
94
|
+
}
|
|
95
|
+
rpoplpush(source, destination, cb) {
|
|
96
|
+
this.client.rpoplpush(source, destination, cb);
|
|
97
|
+
}
|
|
98
|
+
zrangebyscorewithscores(source, min, max, cb) {
|
|
99
|
+
this.client.zrangebyscore(source, min, max, 'WITHSCORES', (err, reply) => {
|
|
100
|
+
if (err)
|
|
101
|
+
cb(err);
|
|
102
|
+
else {
|
|
103
|
+
const replyRange = reply !== null && reply !== void 0 ? reply : [];
|
|
104
|
+
const range = {};
|
|
105
|
+
for (let slice = replyRange.splice(0, 2); slice.length > 0; slice = replyRange.splice(0, 2)) {
|
|
106
|
+
const [member, score] = slice;
|
|
107
|
+
range[score] = member;
|
|
108
|
+
}
|
|
109
|
+
cb(null, range);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
rpop(key, cb) {
|
|
114
|
+
this.client.rpop(key, cb);
|
|
115
|
+
}
|
|
116
|
+
lrem(key, count, element, cb) {
|
|
117
|
+
this.client.lrem(key, count, element, cb);
|
|
118
|
+
}
|
|
119
|
+
publish(channel, message, cb) {
|
|
120
|
+
this.client.publish(channel, message, cb);
|
|
121
|
+
}
|
|
122
|
+
flushall(cb) {
|
|
123
|
+
this.client.flushall(cb);
|
|
124
|
+
}
|
|
125
|
+
loadScript(script, cb) {
|
|
126
|
+
this.client.script('load', script, cb);
|
|
127
|
+
}
|
|
128
|
+
evalsha(hash, args, cb) {
|
|
129
|
+
const arrHash = [hash];
|
|
130
|
+
const arrArgs = Array.isArray(args) ? args : [args];
|
|
131
|
+
this.client.evalsha(arrHash.concat(arrArgs), cb);
|
|
132
|
+
}
|
|
133
|
+
get(key, cb) {
|
|
134
|
+
this.client.get(key, cb);
|
|
135
|
+
}
|
|
136
|
+
del(key, cb) {
|
|
137
|
+
this.client.del(key, cb);
|
|
138
|
+
}
|
|
139
|
+
llen(key, cb) {
|
|
140
|
+
this.client.llen(key, cb);
|
|
141
|
+
}
|
|
142
|
+
lmove(source, destination, from, to, cb) {
|
|
143
|
+
if (!this.validateRedisVersion(6, 2)) {
|
|
144
|
+
cb(new redis_client_error_1.RedisClientError('Command not supported by your Redis server. Minimal required Redis server version is 6.2.0.'));
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
this.client.lmove(source, destination, from, to, cb);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
zremrangebyscore(source, min, max, cb) {
|
|
151
|
+
this.client.zremrangebyscore(source, min, max, cb);
|
|
152
|
+
}
|
|
153
|
+
hmget(source, keys, cb) {
|
|
154
|
+
this.client.hmget(source, keys, cb);
|
|
155
|
+
}
|
|
156
|
+
halt(cb) {
|
|
157
|
+
if (!this.connectionClosed) {
|
|
158
|
+
this.client.once('end', cb);
|
|
159
|
+
this.end(true);
|
|
160
|
+
}
|
|
161
|
+
else
|
|
162
|
+
cb();
|
|
163
|
+
}
|
|
164
|
+
end(flush) {
|
|
165
|
+
if (!this.connectionClosed) {
|
|
166
|
+
this.client.disconnect(false);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
quit(cb = () => void 0) {
|
|
170
|
+
if (!this.connectionClosed) {
|
|
171
|
+
this.client.once('end', cb);
|
|
172
|
+
this.client.quit();
|
|
173
|
+
}
|
|
174
|
+
else
|
|
175
|
+
cb();
|
|
176
|
+
}
|
|
177
|
+
getInfo(cb) {
|
|
178
|
+
this.client.info(cb);
|
|
179
|
+
}
|
|
180
|
+
on(event, listener) {
|
|
181
|
+
this.client.on(event, listener);
|
|
182
|
+
return this;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
exports.IoredisClient = IoredisClient;
|
|
186
|
+
//# sourceMappingURL=ioredis-client.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
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): 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): this;
|
|
18
|
+
pexpire(key: string, millis: number): this;
|
|
19
|
+
rpoplpush(source: string, destination: string): this;
|
|
20
|
+
del(key: string | string[]): this;
|
|
21
|
+
exec(cb: ICallback<unknown[]>): void;
|
|
22
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NodeRedisV3ClientMulti = void 0;
|
|
4
|
+
const redis_client_error_1 = require("../errors/redis-client.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
|
+
pexpire(key, millis) {
|
|
58
|
+
this.multi.pexpire(key, millis);
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
rpoplpush(source, destination) {
|
|
62
|
+
this.multi.rpoplpush(source, destination);
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
del(key) {
|
|
66
|
+
this.multi.del(key);
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
exec(cb) {
|
|
70
|
+
this.multi.exec((err, reply) => {
|
|
71
|
+
if (err)
|
|
72
|
+
cb(err);
|
|
73
|
+
else if (!reply)
|
|
74
|
+
cb(new redis_client_error_1.RedisClientError(`Redis transaction has been abandoned. Try again.`));
|
|
75
|
+
else
|
|
76
|
+
cb(null, reply);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.NodeRedisV3ClientMulti = NodeRedisV3ClientMulti;
|
|
81
|
+
//# sourceMappingURL=node-redis-v3-client-multi.js.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { RedisClient } from '../redis-client';
|
|
2
|
+
import { ICallback } from '../../../types';
|
|
3
|
+
import { ClientOpts, RedisClient as NodeRedis } from 'redis';
|
|
4
|
+
import { NodeRedisV3ClientMulti } from './node-redis-v3-client-multi';
|
|
5
|
+
export declare class NodeRedisV3Client extends RedisClient {
|
|
6
|
+
protected client: NodeRedis;
|
|
7
|
+
constructor(config?: ClientOpts);
|
|
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>): void;
|
|
15
|
+
zadd(key: string, score: number, member: string, cb: ICallback<number | string>): void;
|
|
16
|
+
multi(): NodeRedisV3ClientMulti;
|
|
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
|
+
zrangebyscore(key: string, min: number | string, max: number | string, cb: ICallback<string[]>): void;
|
|
25
|
+
smembers(key: string, cb: ICallback<string[]>): void;
|
|
26
|
+
sadd(key: string, member: string, cb: ICallback<number>): void;
|
|
27
|
+
hgetall(key: string, cb: ICallback<Record<string, string>>): void;
|
|
28
|
+
hget(key: string, field: string, cb: ICallback<string>): void;
|
|
29
|
+
hset(key: string, field: string, value: string, cb: ICallback<number>): void;
|
|
30
|
+
hdel(key: string, fields: string | string[], cb: ICallback<number>): void;
|
|
31
|
+
lrange(key: string, start: number, stop: number, cb: ICallback<string[]>): void;
|
|
32
|
+
hkeys(key: string, cb: ICallback<string[]>): void;
|
|
33
|
+
hlen(key: string, cb: ICallback<number>): void;
|
|
34
|
+
brpoplpush(source: string, destination: string, timeout: number, cb: ICallback<string>): void;
|
|
35
|
+
rpoplpush(source: string, destination: string, cb: ICallback<string>): void;
|
|
36
|
+
zrangebyscorewithscores(source: string, min: number, max: number, cb: ICallback<Record<string, string>>): void;
|
|
37
|
+
rpop(key: string, cb: ICallback<string>): void;
|
|
38
|
+
lrem(key: string, count: number, element: string, cb: ICallback<number>): void;
|
|
39
|
+
publish(channel: string, message: string, cb: ICallback<number>): void;
|
|
40
|
+
flushall(cb: ICallback<string>): void;
|
|
41
|
+
loadScript(script: string, cb: ICallback<string>): void;
|
|
42
|
+
evalsha(hash: string, args: (string | number)[] | string | number, cb: (err?: Error | null, res?: unknown) => void): void;
|
|
43
|
+
get(key: string, cb: ICallback<string>): void;
|
|
44
|
+
del(key: string | string[], cb: ICallback<number>): void;
|
|
45
|
+
llen(key: string, cb: ICallback<number>): void;
|
|
46
|
+
lmove(source: string, destination: string, from: 'LEFT' | 'RIGHT', to: 'LEFT' | 'RIGHT', cb: ICallback<string>): void;
|
|
47
|
+
zremrangebyscore(source: string, min: number | string, max: number | string, cb: ICallback<number>): void;
|
|
48
|
+
hmget(source: string, keys: string[], cb: ICallback<(string | null)[]>): void;
|
|
49
|
+
halt(cb: ICallback<void>): void;
|
|
50
|
+
end(flush: boolean): void;
|
|
51
|
+
quit(cb?: ICallback<void>): void;
|
|
52
|
+
getInfo(cb: ICallback<string>): void;
|
|
53
|
+
on(event: string, listener: (...args: unknown[]) => any): this;
|
|
54
|
+
}
|