mielk-fn 1.2.2 → 1.2.4

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.
@@ -1,2 +1,4 @@
1
1
  import { getRedisClient, RedisConfig } from './redisClient.js';
2
+ import { addRedisKey, removeRedisKey } from './redisActions.js';
2
3
  export { getRedisClient, RedisConfig };
4
+ export { addRedisKey, removeRedisKey };
@@ -1,2 +1,4 @@
1
1
  import { getRedisClient } from './redisClient.js';
2
+ import { addRedisKey, removeRedisKey } from './redisActions.js';
2
3
  export { getRedisClient };
4
+ export { addRedisKey, removeRedisKey };
@@ -0,0 +1,2 @@
1
+ export declare const removeRedisKey: (key: string) => Promise<void>;
2
+ export declare const addRedisKey: (key: string, content: Record<string, unknown>, ttlSeconds?: number) => Promise<void>;
@@ -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(content), 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'; //'127.0.0.1';
3
- const defaultPort = '6179'; //'6379';
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mielk-fn",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "keywords": [],
5
5
  "author": "mielk",
6
6
  "description": "Generic functions used in various projects",