Basic Redis Sentinel support for Crystal. Ported directly from the Ruby Redis gem.
-
Add the dependency to your
shard.yml
:dependencies: redis-sentinel: github: pgeraghty/redis-sentinel-crystal
-
Run
shards install
require "redis-sentinel"
Given the environment established via the example Redis 4 Docker Compose file, the following should execute successfully:
r = Redis.new host: "the-master", password: "abc", sentinels: [{:host => "172.22.0.15", :port => 26379}, {:host => "172.22.0.20", :port => 26379}]
Due to the implementation monkey-patching the base Redis shard, you can also use Redis::PooledClient with the arguments above.
Redis version 5.0.1 and above support password protection for Sentinel instances (in addition to the underlying Redis infrastructure) if they are configured with the "requirepass" directive (as per this commit). To configure this in the client, you simply add a password to the hash, so to connect to the Sentinel instances established in the example Redis 5 Docker Compose file, you'd use:
r = Redis.new host: "the-master", password: "abc", sentinels: [{:host => "172.21.0.15", :port => 26379, :password => "abcd"}, {:host => "172.21.0.20", :port => 26379, :password => "abcd"}]
Testing and development require a functional Redis Sentinel configuration; I have provided Docker Compose files to establish these for Redis 4 or 5. Both set up a separate static network so that IP addresses are pre-established.
TODO experiment with SSL configuration in conjunction with Client.from_hash.
- Fork it (https://github.com/pgeraghty/redis-sentinel-crystal/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
- Paul Geraghty - creator and maintainer