@tomsd/redis-client 1.3.2 → 1.4.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/README.md +0 -1
- package/dist/index.cjs +64 -78
- package/dist/index.d.cts +18 -17
- package/dist/index.d.mts +23 -0
- package/dist/index.mjs +50 -0
- package/package.json +12 -12
- package/dist/index.d.ts +0 -22
- package/dist/index.js +0 -53
package/README.md
CHANGED
|
@@ -9,7 +9,6 @@ See [redis-client.netlify.app](https://redis-client.netlify.app/) also.
|
|
|
9
9
|

|
|
10
10
|

|
|
11
11
|

|
|
12
|
-

|
|
13
12
|

|
|
14
13
|

|
|
15
14
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,88 +1,74 @@
|
|
|
1
|
-
"
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
9
|
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
19
18
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
Redis: () => Redis
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(index_exports);
|
|
36
|
-
var import_ioredis = __toESM(require("ioredis"), 1);
|
|
37
|
-
var import_uuid = require("uuid");
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
//#endregion
|
|
24
|
+
let ioredis = require("ioredis");
|
|
25
|
+
ioredis = __toESM(ioredis, 1);
|
|
26
|
+
let uuid = require("uuid");
|
|
27
|
+
//#region src/index.ts
|
|
38
28
|
var Redis = class {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
this.redis = void 0;
|
|
83
|
-
}
|
|
29
|
+
config;
|
|
30
|
+
redis;
|
|
31
|
+
constructor(config) {
|
|
32
|
+
this.config = config;
|
|
33
|
+
this.redis = void 0;
|
|
34
|
+
}
|
|
35
|
+
get keyProp() {
|
|
36
|
+
return this.config.keyProp ?? "_id";
|
|
37
|
+
}
|
|
38
|
+
get expireSeconds() {
|
|
39
|
+
return this.config.expireSeconds;
|
|
40
|
+
}
|
|
41
|
+
getRedis() {
|
|
42
|
+
this.redis = this.redis ?? new ioredis.default(this.config.options);
|
|
43
|
+
return this.redis;
|
|
44
|
+
}
|
|
45
|
+
async getKeys() {
|
|
46
|
+
const keyFilter = `${this.config?.options?.keyPrefix ?? ""}*`;
|
|
47
|
+
const sliceKey = (s) => s.slice(this.config?.options?.keyPrefix?.length ?? 0);
|
|
48
|
+
return await this.getRedis().keys(keyFilter).then((keys) => keys.map(sliceKey));
|
|
49
|
+
}
|
|
50
|
+
async get(key) {
|
|
51
|
+
return await this.getRedis().get(key).then((value) => {
|
|
52
|
+
if (value == null) return;
|
|
53
|
+
return JSON.parse(value);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
async set(value) {
|
|
57
|
+
const redis = this.getRedis();
|
|
58
|
+
const savingObj = {
|
|
59
|
+
[this.keyProp]: (0, uuid.v4)(),
|
|
60
|
+
...value
|
|
61
|
+
};
|
|
62
|
+
const key = savingObj[this.keyProp];
|
|
63
|
+
return this.expireSeconds !== void 0 ? await redis.set(key, JSON.stringify(savingObj), "EX", this.expireSeconds).then(() => savingObj) : await redis.set(key, JSON.stringify(savingObj)).then(() => savingObj);
|
|
64
|
+
}
|
|
65
|
+
async del(key) {
|
|
66
|
+
return await this.getRedis().del(key);
|
|
67
|
+
}
|
|
68
|
+
disconnect() {
|
|
69
|
+
this.getRedis().disconnect();
|
|
70
|
+
this.redis = void 0;
|
|
71
|
+
}
|
|
84
72
|
};
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
Redis
|
|
88
|
-
});
|
|
73
|
+
//#endregion
|
|
74
|
+
exports.Redis = Redis;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
import IORedis, { RedisOptions } from
|
|
1
|
+
import IORedis, { RedisOptions } from "ioredis";
|
|
2
2
|
|
|
3
|
+
//#region src/index.d.ts
|
|
3
4
|
interface EasyRedisConfig {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
keyProp?: string;
|
|
6
|
+
expireSeconds?: number;
|
|
7
|
+
options: RedisOptions;
|
|
7
8
|
}
|
|
8
9
|
declare class Redis<T = any> {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
config: EasyRedisConfig;
|
|
11
|
+
protected redis: IORedis | undefined;
|
|
12
|
+
constructor(config: EasyRedisConfig);
|
|
13
|
+
get keyProp(): string;
|
|
14
|
+
get expireSeconds(): number | undefined;
|
|
15
|
+
getRedis(): IORedis;
|
|
16
|
+
getKeys(): Promise<string[]>;
|
|
17
|
+
get(key: string): Promise<T>;
|
|
18
|
+
set(value: T | Partial<T>): Promise<T>;
|
|
19
|
+
del(key: string): Promise<number>;
|
|
20
|
+
disconnect(): void;
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
-
export { Redis };
|
|
22
|
+
//#endregion
|
|
23
|
+
export { Redis };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import IORedis, { RedisOptions } from "ioredis";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
interface EasyRedisConfig {
|
|
5
|
+
keyProp?: string;
|
|
6
|
+
expireSeconds?: number;
|
|
7
|
+
options: RedisOptions;
|
|
8
|
+
}
|
|
9
|
+
declare class Redis<T = any> {
|
|
10
|
+
config: EasyRedisConfig;
|
|
11
|
+
protected redis: IORedis | undefined;
|
|
12
|
+
constructor(config: EasyRedisConfig);
|
|
13
|
+
get keyProp(): string;
|
|
14
|
+
get expireSeconds(): number | undefined;
|
|
15
|
+
getRedis(): IORedis;
|
|
16
|
+
getKeys(): Promise<string[]>;
|
|
17
|
+
get(key: string): Promise<T>;
|
|
18
|
+
set(value: T | Partial<T>): Promise<T>;
|
|
19
|
+
del(key: string): Promise<number>;
|
|
20
|
+
disconnect(): void;
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { Redis };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import IORedis from "ioredis";
|
|
2
|
+
import { v4 } from "uuid";
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
var Redis = class {
|
|
5
|
+
config;
|
|
6
|
+
redis;
|
|
7
|
+
constructor(config) {
|
|
8
|
+
this.config = config;
|
|
9
|
+
this.redis = void 0;
|
|
10
|
+
}
|
|
11
|
+
get keyProp() {
|
|
12
|
+
return this.config.keyProp ?? "_id";
|
|
13
|
+
}
|
|
14
|
+
get expireSeconds() {
|
|
15
|
+
return this.config.expireSeconds;
|
|
16
|
+
}
|
|
17
|
+
getRedis() {
|
|
18
|
+
this.redis = this.redis ?? new IORedis(this.config.options);
|
|
19
|
+
return this.redis;
|
|
20
|
+
}
|
|
21
|
+
async getKeys() {
|
|
22
|
+
const keyFilter = `${this.config?.options?.keyPrefix ?? ""}*`;
|
|
23
|
+
const sliceKey = (s) => s.slice(this.config?.options?.keyPrefix?.length ?? 0);
|
|
24
|
+
return await this.getRedis().keys(keyFilter).then((keys) => keys.map(sliceKey));
|
|
25
|
+
}
|
|
26
|
+
async get(key) {
|
|
27
|
+
return await this.getRedis().get(key).then((value) => {
|
|
28
|
+
if (value == null) return;
|
|
29
|
+
return JSON.parse(value);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
async set(value) {
|
|
33
|
+
const redis = this.getRedis();
|
|
34
|
+
const savingObj = {
|
|
35
|
+
[this.keyProp]: v4(),
|
|
36
|
+
...value
|
|
37
|
+
};
|
|
38
|
+
const key = savingObj[this.keyProp];
|
|
39
|
+
return this.expireSeconds !== void 0 ? await redis.set(key, JSON.stringify(savingObj), "EX", this.expireSeconds).then(() => savingObj) : await redis.set(key, JSON.stringify(savingObj)).then(() => savingObj);
|
|
40
|
+
}
|
|
41
|
+
async del(key) {
|
|
42
|
+
return await this.getRedis().del(key);
|
|
43
|
+
}
|
|
44
|
+
disconnect() {
|
|
45
|
+
this.getRedis().disconnect();
|
|
46
|
+
this.redis = void 0;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
//#endregion
|
|
50
|
+
export { Redis };
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tomsd/redis-client",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "It's a wrapper of ioredis.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
|
-
"types": "./dist/index.d.
|
|
9
|
-
"import": "./dist/index.
|
|
8
|
+
"types": "./dist/index.d.mts",
|
|
9
|
+
"import": "./dist/index.mjs",
|
|
10
10
|
"require": "./dist/index.cjs"
|
|
11
11
|
}
|
|
12
12
|
},
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"dist"
|
|
15
15
|
],
|
|
16
16
|
"scripts": {
|
|
17
|
-
"build": "
|
|
17
|
+
"build": "tsdown",
|
|
18
18
|
"lint": "biome check",
|
|
19
19
|
"prepare": "husky",
|
|
20
20
|
"start-redis": "docker compose up -d",
|
|
@@ -45,19 +45,19 @@
|
|
|
45
45
|
},
|
|
46
46
|
"homepage": "https://github.com/tomsdoo/redis-client#readme",
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@biomejs/biome": "2.4.
|
|
48
|
+
"@biomejs/biome": "2.4.12",
|
|
49
49
|
"@tomsd/md-book": "2.0.7",
|
|
50
|
-
"@types/node": "25.
|
|
50
|
+
"@types/node": "25.6.0",
|
|
51
51
|
"@types/uuid": "11.0.0",
|
|
52
52
|
"husky": "9.1.7",
|
|
53
|
-
"lint-staged": "16.
|
|
53
|
+
"lint-staged": "16.4.0",
|
|
54
54
|
"ts-node": "10.9.2",
|
|
55
|
-
"
|
|
56
|
-
"typescript": "
|
|
57
|
-
"vitest": "4.
|
|
55
|
+
"tsdown": "0.21.10",
|
|
56
|
+
"typescript": "6.0.3",
|
|
57
|
+
"vitest": "4.1.4"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"ioredis": "5.10.
|
|
61
|
-
"uuid": "
|
|
60
|
+
"ioredis": "5.10.1",
|
|
61
|
+
"uuid": "14.0.0"
|
|
62
62
|
}
|
|
63
63
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import IORedis, { RedisOptions } from 'ioredis';
|
|
2
|
-
|
|
3
|
-
interface EasyRedisConfig {
|
|
4
|
-
keyProp?: string;
|
|
5
|
-
expireSeconds?: number;
|
|
6
|
-
options: RedisOptions;
|
|
7
|
-
}
|
|
8
|
-
declare class Redis<T = any> {
|
|
9
|
-
config: EasyRedisConfig;
|
|
10
|
-
protected redis: IORedis | undefined;
|
|
11
|
-
constructor(config: EasyRedisConfig);
|
|
12
|
-
get keyProp(): string;
|
|
13
|
-
get expireSeconds(): number | undefined;
|
|
14
|
-
getRedis(): IORedis;
|
|
15
|
-
getKeys(): Promise<string[]>;
|
|
16
|
-
get(key: string): Promise<T>;
|
|
17
|
-
set(value: T | Partial<T>): Promise<T>;
|
|
18
|
-
del(key: string): Promise<number>;
|
|
19
|
-
disconnect(): void;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export { Redis };
|
package/dist/index.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
import IORedis from "ioredis";
|
|
3
|
-
import { v4 as uuid } from "uuid";
|
|
4
|
-
var Redis = class {
|
|
5
|
-
config;
|
|
6
|
-
redis;
|
|
7
|
-
constructor(config) {
|
|
8
|
-
this.config = config;
|
|
9
|
-
this.redis = void 0;
|
|
10
|
-
}
|
|
11
|
-
get keyProp() {
|
|
12
|
-
return this.config.keyProp ?? "_id";
|
|
13
|
-
}
|
|
14
|
-
get expireSeconds() {
|
|
15
|
-
return this.config.expireSeconds;
|
|
16
|
-
}
|
|
17
|
-
getRedis() {
|
|
18
|
-
this.redis = this.redis ?? new IORedis(this.config.options);
|
|
19
|
-
return this.redis;
|
|
20
|
-
}
|
|
21
|
-
async getKeys() {
|
|
22
|
-
const keyFilter = `${this.config?.options?.keyPrefix ?? ""}*`;
|
|
23
|
-
const sliceKey = (s) => s.slice(this.config?.options?.keyPrefix?.length ?? 0);
|
|
24
|
-
return await this.getRedis().keys(keyFilter).then((keys) => keys.map(sliceKey));
|
|
25
|
-
}
|
|
26
|
-
async get(key) {
|
|
27
|
-
return await this.getRedis().get(key).then((value) => {
|
|
28
|
-
if (value == null) {
|
|
29
|
-
return void 0;
|
|
30
|
-
}
|
|
31
|
-
return JSON.parse(value);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
async set(value) {
|
|
35
|
-
const redis = this.getRedis();
|
|
36
|
-
const savingObj = {
|
|
37
|
-
[this.keyProp]: uuid(),
|
|
38
|
-
...value
|
|
39
|
-
};
|
|
40
|
-
const key = savingObj[this.keyProp];
|
|
41
|
-
return this.expireSeconds !== void 0 ? await redis.set(key, JSON.stringify(savingObj), "EX", this.expireSeconds).then(() => savingObj) : await redis.set(key, JSON.stringify(savingObj)).then(() => savingObj);
|
|
42
|
-
}
|
|
43
|
-
async del(key) {
|
|
44
|
-
return await this.getRedis().del(key);
|
|
45
|
-
}
|
|
46
|
-
disconnect() {
|
|
47
|
-
this.getRedis().disconnect();
|
|
48
|
-
this.redis = void 0;
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
export {
|
|
52
|
-
Redis
|
|
53
|
-
};
|