redis-cluster library for Crystal.
- supported versions : 0.27.2 0.31.1 0.32.1 0.33.0 0.34.0
- crystal-redis : using forked maiha/crystal-redis
- The original version stefanwille/crystal-redis only supports the latest version of CRYSTAL.
- Redis : a redis standard client (stefanwille/crystal-redis)
- Redis::Cluster : a redis cluster client (in this library)
- Redis::Client : a hybrid proxy to above clients (in this library)
Add this to your application's
dependencies: redis-cluster: github: maiha/redis-cluster.cr version: 0.8.3
- assumes that our cluster is runing on localhost:7001 and 7002, ...
require "redis-cluster" bootstrap = "127.0.0.1:7001,127.0.0.1:7002" cluster = Redis::Cluster.new(bootstrap) # cluster = Redis::Cluster.new(bootstrap, password: "secret") cluster.set "foo", "123" cluster.get "foo" # => "123" cluster.counts.values # => [0, 0, 1] cluster.close
See crystal-redis because most of all methods are thin proxy to it.
Redis client (enhancement)
This library also add some features to standard
This class is a high level hybrid client which can speak to both standard and clustered redis nodes. And it also has a reconnecting feature. Well, we don't care anything about the node is restarted or clustered or not.
So, the following code works on either redis mode.
redis = Redis::Client.new(host: "127.0.0.1", port: 6379) redis.get("foo")
multi and pipelined
pipelined requires a key to resolve redis node.
In standard redis, the information is just ignored but it is necessary for hybrid api.
redis.pipelined("foo") do |api| api.set("foo", 1) api.set("bar", 2) # raises unless both "foo" and "bar" are in the same node end
reconnect option is set, operations will be executed once again after connection error or hash slot error.
redis.pipelined("foo", reconnect: true) do |api| ...
SCAN especially for block.
redis = Redis.new redis.each(count: 1000) |key| redis.each_keys(count: 1000) |keys|
keyfor its first arg to resolve master node
redis.multi("foo1") do |multi| multi.set("foo1", "first") multi.set("foo2", "second") end
- [ ] define method explicitly
- [x] Commands : Pipeline
- Fork it ( https://github.com/maiha/redis-cluster.cr/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
- maiha maiha - creator, maintainer