Pono
Pono

Reputation: 11776

Node.JS subscribing to a channel on a given IP

Scenario: PHP app that publishes to redis channel called "message" sitting on IP 1.2.3.4

How to connect from node to that channel on that IP?

var listener = redis.createClient();
listener.subscribe('message', /* ? '1.2.3.4' ? */);

listener.on("messages", function(channel, message) {
  // do something with data
});

Upvotes: 4

Views: 1030

Answers (1)

Alfred
Alfred

Reputation: 61783

I assume you are using node_redis. You can specify the host you are using:

redis.createClient(port, host, options)
---
Create a new client connection. 
port defaults to 6379 and host defaults to 127.0.0.1.

So you should use:

redis.createClient('1.2.3.4');

It is in the documentation which is pretty good and I think you should read it completely.

P.S: When you make redis available for remote host(s) I think you should have your firewall setup properly to deny access from other IPs(whitelist).

Upvotes: 5

Related Questions