Redis connection via socket on Node.js

Due to shared hosting, my redis server on the target host does not start on the port, but in a very specific socket, which can be connected via the socket file, is available only to my user.

However, I did not find how I can specify a socket connection in the packets node_redisand connect-redisthat I want to use.

Does anyone know how to do this?

+3
source share
2 answers

Update: My answer below is not entirely correct. It turns out that the solution in the question that I mention below is actually still working. This is more of a coincidence, IMO, but you can do something similar, and it should work:

var redis = require('redis'),
    client = redis.createClient('/tmp/redis.sock');

, net.createConnection, unix- /tmp/redis.sock.

:

node_redis/issues/204. , , node.js net.createConnection API . , node_redis 'exports.createClient:

exports.createClient = function (port_arg, host_arg, options) {
    var port = port_arg || default_port,
        host = host_arg || default_host,
        redis_client, net_client;

    net_client = net.createConnection(port, host);

    redis_client = new RedisClient(net_client, options);

    redis_client.port = port;
    redis_client.host = host;

    return redis_client;
};

, net.createConnection unix, , . , , .

+3

...

var client = redis.createClient(9000); // Open a port on localhost
var client = redis.createClient('/tmp/redis.sock'); // Open a unix socket
var client = redis.createClient(9000, 'example.com'); 

README.

0

All Articles