mielk-fn 1.2.2 → 1.2.3
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
package/dist/redis/index.js
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { getRedisClient } from "./redisClient";
|
|
2
|
+
export const removeRedisKey = async (key) => {
|
|
3
|
+
const redisClient = await getRedisClient();
|
|
4
|
+
await redisClient.del(key);
|
|
5
|
+
};
|
|
6
|
+
export const addRedisKey = async (key, content, ttlSeconds) => {
|
|
7
|
+
const redisClient = await getRedisClient();
|
|
8
|
+
const options = ttlSeconds ? createExpirationOptionObject(ttlSeconds) : {};
|
|
9
|
+
await redisClient.set(key, JSON.stringify({ locked: true }), options);
|
|
10
|
+
};
|
|
11
|
+
const createExpirationOptionObject = (ttlSeconds) => {
|
|
12
|
+
return {
|
|
13
|
+
expiration: {
|
|
14
|
+
type: 'EX',
|
|
15
|
+
value: ttlSeconds
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createClient } from 'redis';
|
|
2
|
-
const defaultHost = '127.0.0.1';
|
|
3
|
-
const defaultPort = '
|
|
2
|
+
const defaultHost = '127.0.0.1';
|
|
3
|
+
const defaultPort = '6379';
|
|
4
4
|
let redisConfig = { host: defaultHost, port: defaultPort };
|
|
5
5
|
let redisClient = null;
|
|
6
6
|
let connected = false;
|