redic-cluster 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b6818ee879f5f8871a7b42e22b81b80507bb7f10
4
+ data.tar.gz: 0cac6f75bb1758a018729565713f87198763cbd9
5
+ SHA512:
6
+ metadata.gz: c14622a8bdaf99c260fd0f433f8fe107b13816739315a40fdcee70e3ef7dcef5fea06425e2275b20aba3c11ac3a6a8f810a2ac0d8274824bfd1e0c4429b43354
7
+ data.tar.gz: 757a774b93a4c90556e1d3c513733e183ff5f812c709e3abeb2bf8304d7aceee9305f6e47685017f861a0e3ce387a5719aa0267caebb3b8d0c7b0b0da51fcd12
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Leandro López
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,52 @@
1
+ # redic-cluster
2
+
3
+ Redis Cluster support for Redic
4
+
5
+ ## Description
6
+
7
+ Adds Redis Cluster support for [redic][redic], the lightweight
8
+ [Redis][redis] client.
9
+
10
+ [redic]: https://github.com/amakawa/redic
11
+ [redis]: http://redis.io/documentation
12
+
13
+ ## Usage
14
+
15
+ ```ruby
16
+ require "redic/cluster"
17
+
18
+ # Connect to a node in the cluster
19
+ node = Redic::Cluster.new("redis://localhost:12001")
20
+
21
+ # Use the same as you
22
+ redis.call("SET", "foo", "bar")
23
+ redis.call("GET", "foo")
24
+ ```
25
+
26
+ `Redic::Cluster` will transparently follow the redirection to the node
27
+ that allocates the slot where `foo` exists. If the `debug` property is
28
+ set to `true`, `Redic::Cluster` will inform the redirection in
29
+ `$stderr`:
30
+
31
+ ```ruby
32
+ require "redic/cluster"
33
+
34
+ # Connect to a node in the cluster
35
+ node = Redic::Cluster.new("redis://localhost:12001")
36
+
37
+ # Enable redirections log
38
+ node.debug = true
39
+
40
+ # Use the same as you
41
+ redis.call("SET", "foo", "bar")
42
+ # Will print in $stderr
43
+ # -> Redirected to slot [12182] located at 127.0.0.1:12004
44
+ ```
45
+
46
+ ## Instalation
47
+
48
+ You can install it using rubygems.
49
+
50
+ ```
51
+ $ gem install redic-cluster
52
+ ```
@@ -0,0 +1,36 @@
1
+ require "redic"
2
+
3
+ class Redic::Cluster
4
+ attr :url
5
+ attr :node
6
+ attr_accessor :debug
7
+
8
+ def initialize(url="redis://localhost:12001", timeout=10_000_000)
9
+ @url = url
10
+ @node = Redic::Client.new(url, timeout)
11
+ @debug = false
12
+ end
13
+
14
+ def call(*args)
15
+ res = @node.connect do
16
+ @node.write(args)
17
+ @node.read
18
+ end
19
+
20
+ return res unless res.is_a?(RuntimeError)
21
+
22
+ parts = res.message.split
23
+
24
+ if parts.first == "MOVED"
25
+ slot, addr = parts[1,2]
26
+
27
+ $stderr.puts "-> Redirected to slot [#{slot}] located at #{addr}" if @debug
28
+
29
+ @node = Redic::Client.new("redis://#{addr}", @node.timeout)
30
+
31
+ call(*args)
32
+ else
33
+ res
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "redic-cluster"
5
+ s.version = "0.0.1"
6
+ s.summary = "Redis Cluster support for Redic"
7
+ s.description = "Redis Cluster support for Redic, the lightweight Redis client"
8
+ s.authors = ["Leandro López"]
9
+ s.email = ["inkel.ar@gmail.com"]
10
+ s.homepage = "http://inkel.github.com/redic-cluster"
11
+ s.license = "MIT"
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redic-cluster
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Leandro López
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-14 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Redis Cluster support for Redic, the lightweight Redis client
14
+ email:
15
+ - inkel.ar@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - LICENSE
21
+ - README.md
22
+ - lib/redic/cluster.rb
23
+ - redic-cluster.gemspec
24
+ homepage: http://inkel.github.com/redic-cluster
25
+ licenses:
26
+ - MIT
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 2.0.3
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: Redis Cluster support for Redic
48
+ test_files: []