@naturalcycles/redis-lib 3.3.2 → 4.0.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/index.d.ts +3 -3
- package/dist/index.js +3 -6
- package/dist/redisClient.d.ts +4 -4
- package/dist/redisClient.js +7 -9
- package/dist/redisHashKeyValueDB.d.ts +3 -3
- package/dist/redisHashKeyValueDB.js +6 -9
- package/dist/redisKeyValueDB.d.ts +3 -3
- package/dist/redisKeyValueDB.js +9 -12
- package/package.json +12 -9
- package/src/index.ts +3 -3
- package/src/redisClient.ts +5 -5
- package/src/redisHashKeyValueDB.ts +4 -4
- package/src/redisKeyValueDB.ts +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './redisClient';
|
|
2
|
-
export * from './redisHashKeyValueDB';
|
|
3
|
-
export * from './redisKeyValueDB';
|
|
1
|
+
export * from './redisClient.js';
|
|
2
|
+
export * from './redisHashKeyValueDB.js';
|
|
3
|
+
export * from './redisKeyValueDB.js';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
tslib_1.__exportStar(require("./redisClient"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./redisHashKeyValueDB"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./redisKeyValueDB"), exports);
|
|
1
|
+
export * from './redisClient.js';
|
|
2
|
+
export * from './redisHashKeyValueDB.js';
|
|
3
|
+
export * from './redisKeyValueDB.js';
|
package/dist/redisClient.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { AnyObject, CommonLogger, NullableBuffer, NullableString, Promisable, UnixTimestamp } from '@naturalcycles/js-lib';
|
|
2
|
-
import { ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
1
|
+
import type { AnyObject, CommonLogger, NullableBuffer, NullableString, Promisable, UnixTimestamp } from '@naturalcycles/js-lib';
|
|
2
|
+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
3
3
|
import type { Redis, RedisOptions } from 'ioredis';
|
|
4
|
-
import type { ScanStreamOptions } from 'ioredis/built/types';
|
|
5
|
-
import type { ChainableCommander } from 'ioredis/built/utils/RedisCommander';
|
|
4
|
+
import type { ScanStreamOptions } from 'ioredis/built/types.js';
|
|
5
|
+
import type { ChainableCommander } from 'ioredis/built/utils/RedisCommander.js';
|
|
6
6
|
export interface CommonClient extends AsyncDisposable {
|
|
7
7
|
connected: boolean;
|
|
8
8
|
connect: () => Promise<void>;
|
package/dist/redisClient.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RedisClient = void 0;
|
|
4
|
-
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
1
|
+
import { _stringMapEntries } from '@naturalcycles/js-lib';
|
|
5
2
|
/**
|
|
6
3
|
Wraps the redis sdk with unified interface.
|
|
7
4
|
Features:
|
|
@@ -10,9 +7,8 @@ const js_lib_1 = require("@naturalcycles/js-lib");
|
|
|
10
7
|
- Reasonable defaults
|
|
11
8
|
|
|
12
9
|
*/
|
|
13
|
-
class RedisClient {
|
|
10
|
+
export class RedisClient {
|
|
14
11
|
constructor(cfg = {}) {
|
|
15
|
-
this.connected = false;
|
|
16
12
|
this.cfg = {
|
|
17
13
|
logger: console,
|
|
18
14
|
...cfg,
|
|
@@ -23,6 +19,9 @@ class RedisClient {
|
|
|
23
19
|
},
|
|
24
20
|
};
|
|
25
21
|
}
|
|
22
|
+
cfg;
|
|
23
|
+
connected = false;
|
|
24
|
+
_redis;
|
|
26
25
|
redis() {
|
|
27
26
|
if (this._redis)
|
|
28
27
|
return this._redis;
|
|
@@ -108,7 +107,7 @@ class RedisClient {
|
|
|
108
107
|
});
|
|
109
108
|
}
|
|
110
109
|
});
|
|
111
|
-
const validResults =
|
|
110
|
+
const validResults = _stringMapEntries(results).filter(([_, v]) => v !== undefined);
|
|
112
111
|
return validResults;
|
|
113
112
|
}
|
|
114
113
|
async setWithTTL(key, value, expireAt) {
|
|
@@ -142,7 +141,7 @@ class RedisClient {
|
|
|
142
141
|
});
|
|
143
142
|
}
|
|
144
143
|
});
|
|
145
|
-
const validResults =
|
|
144
|
+
const validResults = _stringMapEntries(results).filter(([_, v]) => v !== undefined);
|
|
146
145
|
return validResults;
|
|
147
146
|
}
|
|
148
147
|
async ttl(key) {
|
|
@@ -215,4 +214,3 @@ class RedisClient {
|
|
|
215
214
|
this.cfg.logger.log(...args);
|
|
216
215
|
}
|
|
217
216
|
}
|
|
218
|
-
exports.RedisClient = RedisClient;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CommonDBCreateOptions, CommonKeyValueDB, CommonKeyValueDBSaveBatchOptions, IncrementTuple, KeyValueDBTuple } from '@naturalcycles/db-lib';
|
|
2
|
-
import { ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
3
|
-
import { RedisKeyValueDBCfg } from './redisKeyValueDB';
|
|
1
|
+
import type { CommonDBCreateOptions, CommonKeyValueDB, CommonKeyValueDBSaveBatchOptions, IncrementTuple, KeyValueDBTuple } from '@naturalcycles/db-lib';
|
|
2
|
+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
3
|
+
import type { RedisKeyValueDBCfg } from './redisKeyValueDB.js';
|
|
4
4
|
/**
|
|
5
5
|
* RedisHashKeyValueDB is a KeyValueDB implementation that uses hash fields to simulate tables.
|
|
6
6
|
* The value in the `table` arguments points to a hash field in Redis.
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RedisHashKeyValueDB = void 0;
|
|
4
|
-
const db_lib_1 = require("@naturalcycles/db-lib");
|
|
1
|
+
import { commonKeyValueDBFullSupport } from '@naturalcycles/db-lib';
|
|
5
2
|
/**
|
|
6
3
|
* RedisHashKeyValueDB is a KeyValueDB implementation that uses hash fields to simulate tables.
|
|
7
4
|
* The value in the `table` arguments points to a hash field in Redis.
|
|
@@ -14,13 +11,14 @@ const db_lib_1 = require("@naturalcycles/db-lib");
|
|
|
14
11
|
* Once the available Redis version reaches 7.4.0+,
|
|
15
12
|
* this implementation can take over for RedisKeyValueDB.
|
|
16
13
|
*/
|
|
17
|
-
class RedisHashKeyValueDB {
|
|
14
|
+
export class RedisHashKeyValueDB {
|
|
15
|
+
cfg;
|
|
18
16
|
constructor(cfg) {
|
|
19
17
|
this.cfg = cfg;
|
|
20
|
-
this.support = {
|
|
21
|
-
...db_lib_1.commonKeyValueDBFullSupport,
|
|
22
|
-
};
|
|
23
18
|
}
|
|
19
|
+
support = {
|
|
20
|
+
...commonKeyValueDBFullSupport,
|
|
21
|
+
};
|
|
24
22
|
async ping() {
|
|
25
23
|
await this.cfg.client.ping();
|
|
26
24
|
}
|
|
@@ -102,4 +100,3 @@ class RedisHashKeyValueDB {
|
|
|
102
100
|
await this.cfg.client.del([table]);
|
|
103
101
|
}
|
|
104
102
|
}
|
|
105
|
-
exports.RedisHashKeyValueDB = RedisHashKeyValueDB;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CommonDBCreateOptions, CommonKeyValueDB, CommonKeyValueDBSaveBatchOptions, IncrementTuple, KeyValueDBTuple } from '@naturalcycles/db-lib';
|
|
2
|
-
import { ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
3
|
-
import { RedisClient } from './redisClient';
|
|
1
|
+
import type { CommonDBCreateOptions, CommonKeyValueDB, CommonKeyValueDBSaveBatchOptions, IncrementTuple, KeyValueDBTuple } from '@naturalcycles/db-lib';
|
|
2
|
+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib';
|
|
3
|
+
import type { RedisClient } from './redisClient.js';
|
|
4
4
|
export interface RedisKeyValueDBCfg {
|
|
5
5
|
client: RedisClient;
|
|
6
6
|
}
|
package/dist/redisKeyValueDB.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
6
|
-
class RedisKeyValueDB {
|
|
1
|
+
import { commonKeyValueDBFullSupport } from '@naturalcycles/db-lib';
|
|
2
|
+
import { _isTruthy, _zip } from '@naturalcycles/js-lib';
|
|
3
|
+
export class RedisKeyValueDB {
|
|
4
|
+
cfg;
|
|
7
5
|
constructor(cfg) {
|
|
8
6
|
this.cfg = cfg;
|
|
9
|
-
this.support = {
|
|
10
|
-
...db_lib_1.commonKeyValueDBFullSupport,
|
|
11
|
-
};
|
|
12
7
|
}
|
|
8
|
+
support = {
|
|
9
|
+
...commonKeyValueDBFullSupport,
|
|
10
|
+
};
|
|
13
11
|
async ping() {
|
|
14
12
|
await this.cfg.client.ping();
|
|
15
13
|
}
|
|
@@ -63,7 +61,7 @@ class RedisKeyValueDB {
|
|
|
63
61
|
match: `${table}:*`,
|
|
64
62
|
})
|
|
65
63
|
.flatMap(async (keys) => {
|
|
66
|
-
return (await this.cfg.client.mgetBuffer(keys)).filter(
|
|
64
|
+
return (await this.cfg.client.mgetBuffer(keys)).filter(_isTruthy);
|
|
67
65
|
}, {
|
|
68
66
|
concurrency: 16,
|
|
69
67
|
})
|
|
@@ -77,7 +75,7 @@ class RedisKeyValueDB {
|
|
|
77
75
|
.flatMap(async (keys) => {
|
|
78
76
|
// casting as Buffer[], because values are expected to exist for given keys
|
|
79
77
|
const bufs = (await this.cfg.client.mgetBuffer(keys));
|
|
80
|
-
return
|
|
78
|
+
return _zip(this.keysToIds(table, keys), bufs);
|
|
81
79
|
}, {
|
|
82
80
|
concurrency: 16,
|
|
83
81
|
})
|
|
@@ -113,4 +111,3 @@ class RedisKeyValueDB {
|
|
|
113
111
|
return key.slice(table.length + 1);
|
|
114
112
|
}
|
|
115
113
|
}
|
|
116
|
-
exports.RedisKeyValueDB = RedisKeyValueDB;
|
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/redis-lib",
|
|
3
|
+
"type": "module",
|
|
3
4
|
"scripts": {
|
|
4
5
|
"prepare": "husky",
|
|
5
6
|
"build": "dev-lib build",
|
|
@@ -9,15 +10,17 @@
|
|
|
9
10
|
"lbt": "dev-lib lbt"
|
|
10
11
|
},
|
|
11
12
|
"dependencies": {
|
|
12
|
-
"@naturalcycles/db-lib": "^
|
|
13
|
-
"@naturalcycles/js-lib": "^14
|
|
14
|
-
"@naturalcycles/nodejs-lib": "^13
|
|
15
|
-
"ioredis": "^5
|
|
13
|
+
"@naturalcycles/db-lib": "^10",
|
|
14
|
+
"@naturalcycles/js-lib": "^14",
|
|
15
|
+
"@naturalcycles/nodejs-lib": "^13",
|
|
16
|
+
"ioredis": "^5"
|
|
16
17
|
},
|
|
17
18
|
"devDependencies": {
|
|
18
|
-
"@naturalcycles/dev-lib": "^
|
|
19
|
-
"@types/node": "^22
|
|
20
|
-
"
|
|
19
|
+
"@naturalcycles/dev-lib": "^17",
|
|
20
|
+
"@types/node": "^22",
|
|
21
|
+
"@vitest/coverage-v8": "^3",
|
|
22
|
+
"tsx": "^4",
|
|
23
|
+
"vitest": "^3"
|
|
21
24
|
},
|
|
22
25
|
"files": [
|
|
23
26
|
"dist",
|
|
@@ -38,9 +41,9 @@
|
|
|
38
41
|
"url": "https://github.com/NaturalCycles/redis-lib"
|
|
39
42
|
},
|
|
40
43
|
"engines": {
|
|
41
|
-
"node": ">=
|
|
44
|
+
"node": ">=22.10"
|
|
42
45
|
},
|
|
43
|
-
"version": "
|
|
46
|
+
"version": "4.0.1",
|
|
44
47
|
"description": "Redis implementation of CommonKeyValueDB interface",
|
|
45
48
|
"author": "Natural Cycles Team",
|
|
46
49
|
"license": "MIT"
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './redisClient'
|
|
2
|
-
export * from './redisHashKeyValueDB'
|
|
3
|
-
export * from './redisKeyValueDB'
|
|
1
|
+
export * from './redisClient.js'
|
|
2
|
+
export * from './redisHashKeyValueDB.js'
|
|
3
|
+
export * from './redisKeyValueDB.js'
|
package/src/redisClient.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
_stringMapEntries,
|
|
1
|
+
import type {
|
|
3
2
|
AnyObject,
|
|
4
3
|
CommonLogger,
|
|
5
4
|
NullableBuffer,
|
|
@@ -8,11 +7,12 @@ import {
|
|
|
8
7
|
StringMap,
|
|
9
8
|
UnixTimestamp,
|
|
10
9
|
} from '@naturalcycles/js-lib'
|
|
11
|
-
import {
|
|
10
|
+
import { _stringMapEntries } from '@naturalcycles/js-lib'
|
|
11
|
+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
12
12
|
import type { Redis, RedisOptions } from 'ioredis'
|
|
13
13
|
import type * as RedisLib from 'ioredis'
|
|
14
|
-
import type { ScanStreamOptions } from 'ioredis/built/types'
|
|
15
|
-
import type { ChainableCommander } from 'ioredis/built/utils/RedisCommander'
|
|
14
|
+
import type { ScanStreamOptions } from 'ioredis/built/types.js'
|
|
15
|
+
import type { ChainableCommander } from 'ioredis/built/utils/RedisCommander.js'
|
|
16
16
|
|
|
17
17
|
export interface CommonClient extends AsyncDisposable {
|
|
18
18
|
connected: boolean
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
CommonDBCreateOptions,
|
|
3
3
|
CommonKeyValueDB,
|
|
4
|
-
commonKeyValueDBFullSupport,
|
|
5
4
|
CommonKeyValueDBSaveBatchOptions,
|
|
6
5
|
IncrementTuple,
|
|
7
6
|
KeyValueDBTuple,
|
|
8
7
|
} from '@naturalcycles/db-lib'
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
8
|
+
import { commonKeyValueDBFullSupport } from '@naturalcycles/db-lib'
|
|
9
|
+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
10
|
+
import type { RedisKeyValueDBCfg } from './redisKeyValueDB.js'
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* RedisHashKeyValueDB is a KeyValueDB implementation that uses hash fields to simulate tables.
|
package/src/redisKeyValueDB.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
CommonDBCreateOptions,
|
|
3
3
|
CommonKeyValueDB,
|
|
4
|
-
commonKeyValueDBFullSupport,
|
|
5
4
|
CommonKeyValueDBSaveBatchOptions,
|
|
6
5
|
IncrementTuple,
|
|
7
6
|
KeyValueDBTuple,
|
|
8
7
|
} from '@naturalcycles/db-lib'
|
|
8
|
+
import { commonKeyValueDBFullSupport } from '@naturalcycles/db-lib'
|
|
9
9
|
import { _isTruthy, _zip } from '@naturalcycles/js-lib'
|
|
10
|
-
import { ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
11
|
-
import { RedisClient } from './redisClient'
|
|
10
|
+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib'
|
|
11
|
+
import type { RedisClient } from './redisClient.js'
|
|
12
12
|
|
|
13
13
|
export interface RedisKeyValueDBCfg {
|
|
14
14
|
client: RedisClient
|