question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there a unified way to connect to Redis regardless of weather it's a cluster or single server?

See original GitHub issue

I had to add an if to handle the both the cluster mode and the single node mode:

let redis = null;
if (program.cluster) {
    redis = new Redis.Cluster([
        {
            port: program.port,
            host: program.hostname,
        },
    ]);
} else {
    redis = new Redis(program.hostname, program.port);
}

Is there a unified way to connect to Redis regardless of weather it’s a cluster or single server?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jcstanawaycommented, Jun 28, 2018

Having two classes makes it obvious that something is different but not exactly what is different.

If that’s all the developer is aware of (that there are two classes), then they’re mostly likely going to use Redis incorrectly. As @luin points out, if a developer doesn’t know the differences between a standalone redis instance and redis cluster, then the developer is likely going to create problems for themselves. In particular, multi-key operations (such as mget or multi/exec operations) can only be executed if all of the keys in those operations map to the same hash slot. This is described at https://github.com/luin/ioredis#transaction-and-pipeline-in-cluster-mode and https://redis.io/topics/cluster-tutorial#migrating-to-redis-cluster. An application may work just fine when using a standalone instance, but if you try to transparently replace that standalone instance with a cluster - and not examine the application design and use of redis - then developers will have no idea why certain operations start to fail. You generally can’t simply “flip a switch” and move to using a redis cluster without making sure your application is using it correctly - this goes beyond simply switching which class you use to instantiate the client.

Any developer wanting to use redis needs to know if they are using a standalone redis instance or a redis cluster and familiar with the redis documentation that describes the differences between them. If they’re relying simply on which class is being used to instantiate the client, it’s not going to go well. At a minimum they really need to read through the redis cluster tutorial: https://redis.io/topics/cluster-tutorial.

In addition, when connecting to a redis cluster, it is a good idea to list more than one node when instantiating the client. While the client can auto-discover all of the nodes in the cluster, if the one node you’ve configured your client with happens to down for whatever reason (upgrade, h/w fault, etc), then your application won’t be able to connect and you’ve a complete outage. If you specify multiple nodes (not necessarily all, but say 3), then the chances of not being able to connect are generally drastically reduced. So again, the application code needs to know if there is one node (standalone) or multiple nodes (cluster).

0reactions
stale[bot]commented, Jul 28, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 7 days if no further activity occurs, but feel free to re-open a closed issue if needed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Step 4: Connect to the cluster's node - Amazon ElastiCache ...
Log in to an Amazon EC2 instance and connect to a node in the cache cluster.
Read more >
Redis Solutions: Standalone vs Sentinel vs Cluster - Medium
It's a solution using the single Redis node deployment architecture. ... and you have more data than RAM on a server -> Use...
Read more >
Connect to a Redis instance - Memorystore - Google Cloud
Connecting to a Redis instance that uses AUTH · Install redis-cli on the Compute Engine VM by running the following command from the...
Read more >
More Than 8,000 Unsecured Redis Instances Found in the ...
It is important to note that when TLS is enabled in a Redis server, it is securing the communication transport channel. This means...
Read more >
Elasticsearch output plugin | Logstash Reference [8.5] | Elastic
If you're sending events to the same Elasticsearch cluster, but you're targeting different indices you can: use different Elasticsearch outputs, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found