redis-sentinel-crystal

Redis Sentinel support for Crystal

Redis Sentinel for Crystal

Build Status

Basic Redis Sentinel support for Crystal. Ported directly from the Ruby Redis gem.

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      redis-sentinel:
        github: pgeraghty/redis-sentinel-crystal
    
  2. 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

  1. Fork it (https://github.com/pgeraghty/redis-sentinel-crystal/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

Repository

redis-sentinel-crystal

Owner
Statistic
  • 1
  • 0
  • 0
  • 1
  • 1
  • over 5 years ago
  • July 25, 2019
License

MIT License

Links
Synced at

Thu, 26 Dec 2024 13:58:30 GMT

Languages