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 +4 -4
- data/Gemfile +4 -0
- data/README.md +42 -0
- data/dalli-ext-spymemcached-debug.gemspec +22 -0
- data/lib/dalli-ext-spymemcached/ring.rb +46 -0
- data/lib/dalli-ext-spymemcached/version.rb +7 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b98a8aab32d0677c2281a9868232977d47eb3e57
|
4
|
+
data.tar.gz: 616160f912df473fe61c223c959a39a2946456c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cf6f749198f0d41926d8b2b4d0304c829d5d949488d587518a94e727ca69fc9dac2bb587b5c0b5ebdf3a6af9dd81753321cbd777eaa7a947215706e568f9cc2
|
7
|
+
data.tar.gz: 325c759faf3045ed4b6561b303e11f9bbe89ba8e86de5f9ef60ed5aa9b2e25f38db8887ee7ada2b7fe17dab7821b4ff1055b89d15bdbcd49c1143a3758ecbebc
|
data/Gemfile
ADDED
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
|
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
|
+
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
|
-
|
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: {}
|