eip-cloud-services 1.1.7 → 1.1.8

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/redis.js +26 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eip-cloud-services",
3
- "version": "1.1.7",
3
+ "version": "1.1.8",
4
4
  "description": "Houses a collection of helpers for connecting with Cloud services.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -23,4 +23,4 @@
23
23
  "mysql": "^2.18.1",
24
24
  "redis": "^4.6.7"
25
25
  }
26
- }
26
+ }
package/src/redis.js CHANGED
@@ -714,6 +714,32 @@ exports.subscribe = async ( channel, messageHandler ) => {
714
714
  }
715
715
  };
716
716
 
717
+ /**
718
+ * Unsubscribes from a channel.
719
+ * @param {string} channel - The channel to unsubscribe from.
720
+ * @returns {Promise<void>} - A promise that resolves when the unsubscribe is complete.
721
+ *
722
+ * @description This method unsubscribes from the specified channel in Redis for incoming messages.
723
+ */
724
+ exports.unsubscribe = async (channel) => {
725
+ try {
726
+ if (typeof channel === 'string') {
727
+ const client = await getClient(`${channel}_sub`);
728
+
729
+ client.removeAllListeners('message');
730
+
731
+ await client.unsubscribe(channel);
732
+
733
+ return;
734
+ } else {
735
+ throw new Error('redis.unsubscribe expects a string channel and a function as handler');
736
+ }
737
+ } catch (error) {
738
+ console.error('REDIS LIB ERROR [unsubscribe]', error);
739
+ throw error;
740
+ }
741
+ };
742
+
717
743
  /**
718
744
  * Retrieves information and statistics about the Redis server.
719
745
  * @returns {Promise<string>} - A promise that resolves with server information.