shuttlepro-shared 1.1.99 → 1.2.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/config/redis.js +6 -5
- package/package.json +1 -1
package/config/redis.js
CHANGED
|
@@ -53,12 +53,13 @@ const publishToChannel = async (channel, message) => {
|
|
|
53
53
|
* @param {string} channel - The Redis Pub/Sub channel
|
|
54
54
|
* @param {function} callback - Callback function to handle messages
|
|
55
55
|
*/
|
|
56
|
-
const subscribeToChannel = async (channel, callback) => {
|
|
56
|
+
const subscribeToChannel = async (channel, callback, expiry = false) => {
|
|
57
57
|
try {
|
|
58
58
|
await connectRedis();
|
|
59
59
|
await subscriber.subscribe(channel, (message) => {
|
|
60
60
|
console.log(`📥 Message received on channel: ${channel}`);
|
|
61
|
-
callback(
|
|
61
|
+
if (expiry) callback(message);
|
|
62
|
+
else callback(JSON.parse(message));
|
|
62
63
|
});
|
|
63
64
|
} catch (err) {
|
|
64
65
|
console.error("❌ Error subscribing to channel:", err);
|
|
@@ -97,7 +98,7 @@ const setRedisData = async (
|
|
|
97
98
|
const addDataToRedisSet = async (key, value) => {
|
|
98
99
|
try {
|
|
99
100
|
await connectRedis();
|
|
100
|
-
await
|
|
101
|
+
await client.sAdd(key, value);
|
|
101
102
|
return true;
|
|
102
103
|
} catch (err) {
|
|
103
104
|
return false;
|
|
@@ -106,7 +107,7 @@ const addDataToRedisSet = async (key, value) => {
|
|
|
106
107
|
const removeDataFromRedisSet = async (key, value) => {
|
|
107
108
|
try {
|
|
108
109
|
await connectRedis();
|
|
109
|
-
await
|
|
110
|
+
await client.sRem(key, value);
|
|
110
111
|
return true;
|
|
111
112
|
} catch (err) {
|
|
112
113
|
return false;
|
|
@@ -115,7 +116,7 @@ const removeDataFromRedisSet = async (key, value) => {
|
|
|
115
116
|
const isMemberOfRedisSet = async (key, value) => {
|
|
116
117
|
try {
|
|
117
118
|
await connectRedis();
|
|
118
|
-
await
|
|
119
|
+
await client.sIsMember(key, value);
|
|
119
120
|
} catch (err) {
|
|
120
121
|
return false;
|
|
121
122
|
}
|