dalli-ext-spymemcached-debug 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 46cc94678fcf856d5d37572a2041759bfeac626e
4
- data.tar.gz: c77bf4a8471949ca6391942844d1728c4220abfa
3
+ metadata.gz: b98a8aab32d0677c2281a9868232977d47eb3e57
4
+ data.tar.gz: 616160f912df473fe61c223c959a39a2946456c5
5
5
  SHA512:
6
- metadata.gz: 3b2b9e790532f815a0ebc477315e72a01eace5e63840ef2fea95f1c4ee246870dff0778a2a7f8c11e1f09aa1ca3624cd58d3448565bd9d8db360dc9c2b5b685a
7
- data.tar.gz: d3a839e8cb2eee9aa04fab493bc120966030f78066b36cc206da208c97e8a807aecdc469981f3abfecff3b5d20b170ab32fd52f5f49b2a86746ebfd61fdad983
6
+ metadata.gz: 9cf6f749198f0d41926d8b2b4d0304c829d5d949488d587518a94e727ca69fc9dac2bb587b5c0b5ebdf3a6af9dd81753321cbd777eaa7a947215706e568f9cc2
7
+ data.tar.gz: 325c759faf3045ed4b6561b303e11f9bbe89ba8e86de5f9ef60ed5aa9b2e25f38db8887ee7ada2b7fe17dab7821b4ff1055b89d15bdbcd49c1143a3758ecbebc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :rubygems
2
+
3
+ # Specify your gem's dependencies in dalli-ext-spymemcached.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # Dalli Extension: Spymemcached
2
+
3
+ Memcached clients all use their own way of deciding which server from a list
4
+ of configured servers a specific key should be stored on. Hence different
5
+ memcached libraries often don't work too well together.
6
+
7
+ This gem changes [Dalli][]'s server hashing algorithm to match that of the
8
+ [Spymemcached][] Java client.
9
+
10
+ ## Usage
11
+
12
+ ```ruby
13
+ require 'dalli'
14
+ require 'dalli-ext-spymemcached'
15
+ ```
16
+
17
+ [dalli]: https://github.com/mperham/dalli
18
+ [spymemcached]: http://code.google.com/p/spymemcached/
19
+
20
+ ## Licence
21
+
22
+ (The MIT License)
23
+
24
+ Copyright (c) 2012 Global Personals, Ltd.
25
+
26
+ Permission is hereby granted, free of charge, to any person obtaining a copy
27
+ of this software and associated documentation files (the "Software"), to deal
28
+ in the Software without restriction, including without limitation the rights
29
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
30
+ copies of the Software, and to permit persons to whom the Software is
31
+ furnished to do so, subject to the following conditions:
32
+
33
+ The above copyright notice and this permission notice shall be included in
34
+ all copies or substantial portions of the Software.
35
+
36
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
37
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
38
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
39
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
40
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
41
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
42
+ THE SOFTWARE.
@@ -0,0 +1,22 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'dalli-ext-spymemcached-debug'
3
+ s.version = '1.0.5'
4
+ s.date = '2010-04-28'
5
+ s.summary = "Dalli server-hashing algorithm to match spymemcachedJava library."
6
+ s.description = "Copy of dalli-ext-spymemcached, with gemspec and debug output added so I can watch the behavior"
7
+ s.authors = ["Jim Myhrberg, Mat Sadler, Tim Blair"]
8
+ s.email = ''
9
+ s.files = Dir.glob("lib/**/*") + [
10
+ "README.md",
11
+ "Gemfile",
12
+ "dalli-ext-spymemcached-debug.gemspec",
13
+ ]
14
+ s.homepage =
15
+ 'http://rubygems.org/gems/dalli-ext-spymemcached-debug/versions/1.0.5'
16
+ s.license = 'MIT'
17
+
18
+ s.add_development_dependency 'rake', '~> 0'
19
+ s.add_development_dependency 'rspec', '~> 0'
20
+ s.add_development_dependency 'simplecov', '~> 0'
21
+ s.add_runtime_dependency 'dalli', '>= 0'
22
+ end
@@ -0,0 +1,46 @@
1
+ require 'dalli'
2
+
3
+ module Dalli
4
+ module Ext
5
+ module Spymemcached
6
+
7
+ # Impliments the same hashing algorithm to chose a server as
8
+ # spymemcached Java library.
9
+ class Ring < Dalli::Ring
10
+ MAX = 2 ** 31 - 1 # 32 bit signed int max
11
+ MIN = -2 ** 31 # 32 bit signed int min
12
+
13
+ def hash_for(key)
14
+ hashed_key = key.each_byte.inject(0) do |hash, byte|
15
+ hash = 31 * hash + byte
16
+ hash = MAX - (MIN - hash) + 1 while hash < MIN
17
+ hash = MIN - (MAX - hash) - 1 while hash > MAX
18
+ hash
19
+ end
20
+
21
+ hashed_key & "ffffffff".hex
22
+ end
23
+
24
+ def server_for_key(key)
25
+ server = @servers[hash_for(key) % @servers.length] if @servers.any?
26
+ Dalli.logger.debug { "Dalli::Ext::Spymemcached#server_for_key:
27
+ key: #{key.to_s},
28
+ hash: #{hash_for(key)},
29
+ server: #{server.try(:name)}" }
30
+
31
+ unless server && server.alive?
32
+ raise Dalli::NetworkError, "No servers available"
33
+ end
34
+
35
+ server
36
+ end
37
+
38
+ end
39
+ end
40
+ end
41
+
42
+ # Replace default implementation.
43
+ remove_const :Ring
44
+ Ring = Ext::Spymemcached::Ring
45
+
46
+ end
@@ -0,0 +1,7 @@
1
+ module Dalli
2
+ module Ext
3
+ module Spymemcached
4
+ VERSION = "1.0.5"
5
+ end
6
+ end
7
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dalli-ext-spymemcached-debug
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Myhrberg, Mat Sadler, Tim Blair
@@ -73,8 +73,13 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - Gemfile
77
+ - README.md
78
+ - dalli-ext-spymemcached-debug.gemspec
76
79
  - lib/dalli-ext-spymemcached.rb
77
- homepage: http://rubygems.org/gems/dalli-ext-spymemcached/versions/1.0.2
80
+ - lib/dalli-ext-spymemcached/ring.rb
81
+ - lib/dalli-ext-spymemcached/version.rb
82
+ homepage: http://rubygems.org/gems/dalli-ext-spymemcached-debug/versions/1.0.5
78
83
  licenses:
79
84
  - MIT
80
85
  metadata: {}