@bejibun/redis 0.1.32 → 0.1.34
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 +28 -0
- package/builders/RedisBuilder.d.ts +1 -0
- package/builders/RedisBuilder.js +20 -7
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,34 @@ All notable changes to this project will be documented in this file.
|
|
|
3
3
|
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
+
## [v0.1.34](https://github.com/crenata/bejibun-redis/compare/v0.1.33...v0.1.34) - 2025-11-23
|
|
7
|
+
|
|
8
|
+
### 🩹 Fixes
|
|
9
|
+
- Fix redis ttl
|
|
10
|
+
|
|
11
|
+
### 📖 Changes
|
|
12
|
+
|
|
13
|
+
### ❤️Contributors
|
|
14
|
+
- Havea Crenata ([@crenata](https://github.com/crenata))
|
|
15
|
+
|
|
16
|
+
**Full Changelog**: https://github.com/crenata/bejibun-redis/blob/master/CHANGELOG.md
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## [v0.1.33](https://github.com/crenata/bejibun-redis/compare/v0.1.30...v0.1.33) - 2025-11-09
|
|
21
|
+
|
|
22
|
+
### 🩹 Fixes
|
|
23
|
+
- Fix redis configuration
|
|
24
|
+
|
|
25
|
+
### 📖 Changes
|
|
26
|
+
|
|
27
|
+
### ❤️Contributors
|
|
28
|
+
- Havea Crenata ([@crenata](https://github.com/crenata))
|
|
29
|
+
|
|
30
|
+
**Full Changelog**: https://github.com/crenata/bejibun-redis/blob/master/CHANGELOG.md
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
6
34
|
## [v0.1.30](https://github.com/crenata/bejibun-redis/compare/v0.1.29...v0.1.30) - 2025-10-22
|
|
7
35
|
|
|
8
36
|
### 🩹 Fixes
|
|
@@ -13,6 +13,7 @@ export default class RedisBuilder {
|
|
|
13
13
|
static pipeline(fn: (pipe: RedisPipeline) => void, connection?: string): Promise<any[]>;
|
|
14
14
|
static on(event: "connect" | "disconnect" | "error", listener: (...args: Array<any>) => void): void;
|
|
15
15
|
static off(event: "connect" | "disconnect" | "error", listener: (...args: Array<any>) => void): void;
|
|
16
|
+
private static get config();
|
|
16
17
|
private static buildUrl;
|
|
17
18
|
private static createClient;
|
|
18
19
|
private static getOptions;
|
package/builders/RedisBuilder.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import App from "@bejibun/app";
|
|
1
2
|
import Logger from "@bejibun/logger";
|
|
2
3
|
import { defineValue, isEmpty, isNotEmpty } from "@bejibun/utils";
|
|
3
4
|
import { EventEmitter } from "events";
|
|
4
|
-
import
|
|
5
|
+
import fs from "fs";
|
|
6
|
+
import RedisConf from "../config/redis";
|
|
5
7
|
import RedisException from "../exceptions/RedisException";
|
|
6
8
|
export default class RedisBuilder {
|
|
7
9
|
static clients = {};
|
|
@@ -47,9 +49,10 @@ export default class RedisBuilder {
|
|
|
47
49
|
static async set(key, value, ttl, connection) {
|
|
48
50
|
const client = this.getClient(connection);
|
|
49
51
|
const serialized = this.serialize(value);
|
|
52
|
+
const data = await client.set(key, serialized);
|
|
50
53
|
if (isNotEmpty(ttl))
|
|
51
54
|
return await client.expire(key, ttl);
|
|
52
|
-
return
|
|
55
|
+
return data;
|
|
53
56
|
}
|
|
54
57
|
static async del(key, connection) {
|
|
55
58
|
return await this.getClient(connection).del(key);
|
|
@@ -60,7 +63,7 @@ export default class RedisBuilder {
|
|
|
60
63
|
}
|
|
61
64
|
static async subscribe(channel, listener, connection) {
|
|
62
65
|
const cfg = this.getConfig(connection);
|
|
63
|
-
const client = this.createClient(config.default, cfg);
|
|
66
|
+
const client = this.createClient(this.config.default, cfg);
|
|
64
67
|
this.clients[channel] = client;
|
|
65
68
|
await client.subscribe(channel, (message, channel) => listener(this.deserialize(message), channel));
|
|
66
69
|
Logger.setContext("Redis").info(`Subscribed to "${channel}" channel.`);
|
|
@@ -87,9 +90,10 @@ export default class RedisBuilder {
|
|
|
87
90
|
},
|
|
88
91
|
set: (key, value, ttl) => {
|
|
89
92
|
const serialized = this.serialize(value);
|
|
93
|
+
const data = client.set(key, serialized);
|
|
90
94
|
if (isNotEmpty(ttl))
|
|
91
95
|
ops.push(client.expire(key, ttl));
|
|
92
|
-
ops.push(
|
|
96
|
+
ops.push(data);
|
|
93
97
|
}
|
|
94
98
|
};
|
|
95
99
|
fn(pipe);
|
|
@@ -102,6 +106,15 @@ export default class RedisBuilder {
|
|
|
102
106
|
static off(event, listener) {
|
|
103
107
|
this.emitter.off(event, listener);
|
|
104
108
|
}
|
|
109
|
+
static get config() {
|
|
110
|
+
let config;
|
|
111
|
+
const configPath = App.Path.configPath("redis.ts");
|
|
112
|
+
if (fs.existsSync(configPath))
|
|
113
|
+
config = require(configPath).default;
|
|
114
|
+
else
|
|
115
|
+
config = RedisConf;
|
|
116
|
+
return config;
|
|
117
|
+
}
|
|
105
118
|
static buildUrl(cfg) {
|
|
106
119
|
const url = new URL(`redis://${cfg.host}:${cfg.port}`);
|
|
107
120
|
if (isNotEmpty(cfg.password))
|
|
@@ -130,14 +143,14 @@ export default class RedisBuilder {
|
|
|
130
143
|
};
|
|
131
144
|
}
|
|
132
145
|
static getConfig(name) {
|
|
133
|
-
const connectionName = defineValue(name, config.default);
|
|
134
|
-
const connection = config.connections[connectionName];
|
|
146
|
+
const connectionName = defineValue(name, this.config.default);
|
|
147
|
+
const connection = this.config.connections[connectionName];
|
|
135
148
|
if (isEmpty(connection))
|
|
136
149
|
throw new RedisException(`Connection "${connectionName}" not found.`);
|
|
137
150
|
return connection;
|
|
138
151
|
}
|
|
139
152
|
static getClient(name) {
|
|
140
|
-
const connectionName = defineValue(name, config.default);
|
|
153
|
+
const connectionName = defineValue(name, this.config.default);
|
|
141
154
|
this.ensureExitHooks();
|
|
142
155
|
if (isEmpty(this.clients[connectionName])) {
|
|
143
156
|
const cfg = this.getConfig(connectionName);
|