Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: fictorial/redis-node-client
base: master
...
head fork: sco/redis-node-client
compare: master
Checking mergeability… Don't worry, you can still create the pull request.
  • 1 commit
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Commits on May 09, 2010
@sco sco Add support for subscribing to multiple channels at once, by passing …
…an array of channel names/patterns to subscribeTo
e07fdcf
Showing with 16 additions and 9 deletions.
  1. +16 −9 lib/redis-client.js
View
25 lib/redis-client.js
@@ -856,20 +856,27 @@ Client.prototype.maybeReconnect = function () {
// when there are >= 1 subscriptions active. Should you need to
// issue other commands, use a second client instance.
-Client.prototype.subscribeTo = function (nameOrPattern, callback) {
- if (typeof this.channelCallbacks[nameOrPattern] === 'function')
- return;
-
+Client.prototype.subscribeTo = function (namesOrPatterns, callback) {
+ if (!(namesOrPatterns instanceof Array))
+ namesOrPatterns = [namesOrPatterns];
+
if (typeof(callback) !== 'function')
throw new Error("requires a callback function");
- this.channelCallbacks[nameOrPattern] = callback;
+ for (var i=0; i < namesOrPatterns.length; ++i) {
+ var nameOrPattern = namesOrPatterns[i];
- var method = nameOrPattern.match(/[\*\?\[]/)
- ? "psubscribe"
- : "subscribe";
+ if (typeof this.channelCallbacks[nameOrPattern] === 'function')
+ return;
- this[method](nameOrPattern);
+ this.channelCallbacks[nameOrPattern] = callback;
+
+ var method = nameOrPattern.match(/[\*\?\[]/)
+ ? "psubscribe"
+ : "subscribe";
+
+ this[method](nameOrPattern);
+ }
};
Client.prototype.unsubscribeFrom = function (nameOrPattern) {

No commit comments for this range

Something went wrong with that request. Please try again.