mielk-fn 1.2.0 → 1.2.2
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/redis/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { getRedisClient } from './redisClient.js';
|
|
2
|
-
export { getRedisClient };
|
|
1
|
+
import { getRedisClient, RedisConfig } from './redisClient.js';
|
|
2
|
+
export { getRedisClient, RedisConfig };
|
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
import { RedisClientType } from 'redis';
|
|
2
|
-
export
|
|
2
|
+
export interface RedisConfig {
|
|
3
|
+
host?: string;
|
|
4
|
+
port?: string;
|
|
5
|
+
password?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function getRedisClient(config?: RedisConfig): Promise<RedisClientType>;
|
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
import { createClient } from 'redis';
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
redisClient
|
|
2
|
+
const defaultHost = '127.0.0.1'; //'127.0.0.1';
|
|
3
|
+
const defaultPort = '6179'; //'6379';
|
|
4
|
+
let redisConfig = { host: defaultHost, port: defaultPort };
|
|
5
|
+
let redisClient = null;
|
|
6
6
|
let connected = false;
|
|
7
|
-
|
|
7
|
+
const createRedisClient = (config) => {
|
|
8
|
+
const { host, port } = config;
|
|
9
|
+
const client = createClient({
|
|
10
|
+
url: `redis://${host}:${port}`,
|
|
11
|
+
});
|
|
12
|
+
client.on('error', (err) => console.error('Redis error:', err));
|
|
13
|
+
console.log('Redis URL:', `redis://${host}:${port}`);
|
|
14
|
+
return client;
|
|
15
|
+
};
|
|
16
|
+
export async function getRedisClient(config) {
|
|
17
|
+
if (redisClient === null) {
|
|
18
|
+
redisConfig = {
|
|
19
|
+
...redisConfig,
|
|
20
|
+
...config,
|
|
21
|
+
};
|
|
22
|
+
redisClient = createRedisClient(redisConfig);
|
|
23
|
+
}
|
|
8
24
|
if (!connected) {
|
|
9
25
|
await redisClient.connect();
|
|
10
26
|
connected = true;
|