redis-sentinel-crystal
Redis Sentinel for Crystal
Basic Redis Sentinel support for Crystal. Ported directly from the Ruby Redis gem.
Installation
-
Add the dependency to your
shard.yml
:dependencies: redis-sentinel: github: pgeraghty/redis-sentinel-crystal
-
Run
shards install
Usage
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"}]
Development
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.
Contributing
- 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
Contributors
- Paul Geraghty - creator and maintainer
redis-sentinel-crystal
- 1
- 0
- 0
- 1
- 1
- about 5 years ago
- July 25, 2019
MIT License
Sun, 24 Nov 2024 05:29:29 GMT