Skip to content

sylvek/redis-sentinel-docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Redis + Sentinel + Docker = ❤️

Tired of trying to make Redis, Sentinel and Docker work together?

As Developer, it's frustrating to deal with Redis configuration. Locally you should have a single Redis instance and in production we have to handle a connection with Sentinel. Unfortunately, most of Redis clients do not offer a single way to configure Redis and Sentinel.

And, if you work on MacOS (and M1) you hit the jackpot!

In fact, Sentinel does only one thing, it ensures to always maintain integrity between clients and a Redis Master/Replicas. The client connects to the sentinel and asks two things :

If you answer correctly to these two questions, your client will switch and connect to the correct Redis instance.

So the main objective was to mock this handshake and return "localhost:6379" as the current Redis Master.

Battle tested with ioredis.

How to use ?

> git clone https://github.com/sylvek/redis-sentinel-docker.git
> cd redis-sentinel-docker
> docker-compose up

Example of client configuration :

var redis = new Redis({
  sentinels: [{ host: 'localhost', port: 26379 }],
  name: 'master-group-name'
});
redis.set('foo', 'bar');

A full example is available on example.

$> cd example
$> npm install
$> npm start run

// should display
> [email protected] start
> node test.js "run"

bar

You could replace master-group-name by your own "master group name". You should rename files :

  • "sentinel-get-master-addr-by-name-master-group-name"
  • "sentinel-sentinels-master-group-name"

by you own group name. :)

About

Redis + Sentinel + Docker = ❤️

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published