dalli 0.11.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of dalli might be problematic. Click here for more details.

data/History.md CHANGED
@@ -1,10 +1,19 @@
1
1
  Dalli Changelog
2
2
  =====================
3
3
 
4
+ 1.0.0
5
+ =======
6
+
7
+ Welcome gucki as a Dalli committer!
8
+
9
+ - Fix network and namespace issues in get_multi (gucki)
10
+ - Better handling of unmarshalling errors (mperham)
11
+
4
12
  0.11.2
5
13
  =======
6
14
 
7
15
  - Major reworking of socket error and failover handling (gucki)
16
+ - Add basic JRuby support (mperham)
8
17
 
9
18
  0.11.1
10
19
  ======
data/README.md CHANGED
@@ -114,15 +114,21 @@ Put this at the bottom of `config/environment.rb`:
114
114
 
115
115
  Configuration
116
116
  ------------------------
117
- Dalli accepts the following options. All times are in seconds and maybe fractional.
117
+ Dalli::Client accepts the following options. All times are in seconds.
118
+
119
+ **expires_in**: Global default for key TTL. No default.
120
+
121
+ **failover**: Boolean, if true Dalli will failover to another server if the main server for a key is down.
122
+
123
+ **compression**: Boolean, if true Dalli will gzip-compress values larger than 1K.
118
124
 
119
125
  **socket_timeout**: Timeout for all socket operations (connect, read, write). Default is 0.5.
120
126
 
121
127
  **socket_max_failures**: When a socket operation fails after socket_timeout, the same operation is retried. This is to not immediately mark a server down when there's a very slight network problem. Default is 2.
122
128
 
123
- **socket_failure_delay**: Before retrying a socket operation, the process sleeps for this amount of time. Default is 0.01.
129
+ **socket_failure_delay**: Before retrying a socket operation, the process sleeps for this amount of time. Default is 0.01. Set to nil for no delay.
124
130
 
125
- **down_retry_delay**: When a server has been marked down due to many failures, the server will be checked again for being alive only after this amount of time. Don't set this value to low, otherwise each request which tries the failed server might hang for the maximum timeout (see below). Default is 30 seconds.
131
+ **down_retry_delay**: When a server has been marked down due to many failures, the server will be checked again for being alive only after this amount of time. Don't set this value to low, otherwise each request which tries the failed server might hang for the maximum timeout (see below). Default is 1 second.
126
132
 
127
133
 
128
134
  Features and Changes
@@ -61,7 +61,15 @@ module Dalli
61
61
 
62
62
  values = {}
63
63
  ring.servers.each do |server|
64
- values.merge!(server.request(:noop)) if server.alive?
64
+ next unless server.alive?
65
+ begin
66
+ server.request(:noop).each_pair do |key, value|
67
+ values[key_without_namespace(key)] = value
68
+ end
69
+ rescue NetworkError => e
70
+ Dalli.logger.debug { e.message }
71
+ Dalli.logger.debug { "results from this server will be missing" }
72
+ end
65
73
  end
66
74
  values
67
75
  end
@@ -210,16 +218,13 @@ module Dalli
210
218
  end
211
219
 
212
220
  # Chokepoint method for instrumentation
213
- def perform(op, *args)
214
- key = args.first
215
- if !key.is_a?(String)
216
- key = key.to_s
217
- args[0] = key
218
- end
219
- args[0] = key = validate_key(key)
221
+ def perform(op, key, *args)
222
+ key = key.to_s
223
+ validate_key(key)
224
+ key = key_with_namespace(key)
220
225
  begin
221
226
  server = ring.server_for_key(key)
222
- server.request(op, *args)
227
+ server.request(op, key, *args)
223
228
  rescue NetworkError => e
224
229
  Dalli.logger.debug { e.message }
225
230
  Dalli.logger.debug { "retrying request with new server" }
@@ -233,7 +238,14 @@ module Dalli
233
238
  raise ArgumentError, "illegal character in key #{key}" if key =~ /[\x00-\x20\x80-\xFF]/
234
239
  raise ArgumentError, "key cannot be blank" if key.nil? || key.strip.size == 0
235
240
  raise ArgumentError, "key too long #{key.inspect}" if key.length > 250
241
+ end
242
+
243
+ def key_with_namespace(key)
236
244
  @options[:namespace] ? "#{@options[:namespace]}:#{key}" : key
237
245
  end
246
+
247
+ def key_without_namespace(key)
248
+ @options[:namespace] ? key.gsub(%r(\A#{@options[:namespace]}:), '') : key
249
+ end
238
250
  end
239
251
  end
@@ -59,7 +59,7 @@ module Dalli
59
59
  end
60
60
 
61
61
  connect
62
- @sock
62
+ !!@sock
63
63
  rescue Dalli::NetworkError
64
64
  false
65
65
  end
@@ -234,7 +234,7 @@ module Dalli
234
234
  generic_response
235
235
  end
236
236
 
237
- COMPRESSION_MIN_SIZE = 100
237
+ COMPRESSION_MIN_SIZE = 1024
238
238
 
239
239
  # http://www.hjp.at/zettel/m/memcached_flags.rxml
240
240
  # Looks like most clients use bit 0 to indicate native language serialization
@@ -266,10 +266,10 @@ module Dalli
266
266
  value = Zlib::Inflate.inflate(value) if (flags & FLAG_COMPRESSED) != 0
267
267
  value = Marshal.load(value) if (flags & FLAG_MARSHALLED) != 0
268
268
  value
269
- rescue TypeError
270
- raise DalliError, "Unable to unmarshal value: '#{value}'"
269
+ rescue TypeError, ArgumentError
270
+ raise DalliError, "Unable to unmarshal value: #{$!.message}"
271
271
  rescue Zlib::Error
272
- raise DalliError, "Unable to uncompress value: '#{value}'"
272
+ raise DalliError, "Unable to uncompress value: #{$!.message}"
273
273
  end
274
274
 
275
275
  def cas_response
@@ -1,3 +1,3 @@
1
1
  module Dalli
2
- VERSION = '0.11.2'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -320,6 +320,15 @@ class TestDalli < Test::Unit::TestCase
320
320
  end
321
321
  end
322
322
 
323
+ should "handle namespaced keys in multi_get" do
324
+ memcached do |dc|
325
+ dc = Dalli::Client.new('localhost:19122', :namespace => 'a')
326
+ dc.set('a', 1)
327
+ dc.set('b', 2)
328
+ assert_equal({'a' => 1, 'b' => 2}, dc.get_multi('a', 'b'))
329
+ end
330
+ end
331
+
323
332
  context 'with compression' do
324
333
  should 'allow large values' do
325
334
  memcached do |dc|
@@ -25,6 +25,22 @@ class TestFailover < Test::Unit::TestCase
25
25
  end
26
26
  end
27
27
 
28
+ should 'handle them gracefully in get_multi' do
29
+ memcached(29125) do
30
+ memcached(29126) do
31
+ dc = Dalli::Client.new ['localhost:29125', 'localhost:29126']
32
+ dc.set 'a', 'a1'
33
+ result = dc.get_multi ['a']
34
+ assert_equal result, {'a' => 'a1'}
35
+
36
+ memcached_kill(29125)
37
+
38
+ result = dc.get_multi ['a']
39
+ assert_equal result, {'a' => 'a1'}
40
+ end
41
+ end
42
+ end
43
+
28
44
  should 'handle graceful failover in get_multi' do
29
45
  memcached(29125) do
30
46
  memcached(29126) do
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dalli
3
3
  version: !ruby/object:Gem::Version
4
- hash: 55
5
4
  prerelease: false
6
5
  segments:
6
+ - 1
7
7
  - 0
8
- - 11
9
- - 2
10
- version: 0.11.2
8
+ - 0
9
+ version: 1.0.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - Mike Perham
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-11-19 00:00:00 -08:00
17
+ date: 2010-11-28 00:00:00 -08:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 3
30
28
  segments:
31
29
  - 0
32
30
  version: "0"
@@ -40,7 +38,6 @@ dependencies:
40
38
  requirements:
41
39
  - - ">="
42
40
  - !ruby/object:Gem::Version
43
- hash: 3
44
41
  segments:
45
42
  - 0
46
43
  version: "0"
@@ -54,7 +51,6 @@ dependencies:
54
51
  requirements:
55
52
  - - ">="
56
53
  - !ruby/object:Gem::Version
57
- hash: 5
58
54
  segments:
59
55
  - 3
60
56
  - 0
@@ -70,7 +66,6 @@ dependencies:
70
66
  requirements:
71
67
  - - ">="
72
68
  - !ruby/object:Gem::Version
73
- hash: 61
74
69
  segments:
75
70
  - 1
76
71
  - 8
@@ -135,7 +130,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
130
  requirements:
136
131
  - - ">="
137
132
  - !ruby/object:Gem::Version
138
- hash: 3
139
133
  segments:
140
134
  - 0
141
135
  version: "0"
@@ -144,7 +138,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
138
  requirements:
145
139
  - - ">="
146
140
  - !ruby/object:Gem::Version
147
- hash: 3
148
141
  segments:
149
142
  - 0
150
143
  version: "0"