dalli 0.9.7 → 0.9.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.md CHANGED
@@ -1,6 +1,13 @@
1
1
  Dalli Changelog
2
2
  =====================
3
3
 
4
+ 0.9.8
5
+ -----
6
+
7
+ - Implement namespace support
8
+ - Misc fixes
9
+
10
+
4
11
  0.9.7
5
12
  -----
6
13
 
data/TODO.md CHANGED
@@ -3,3 +3,5 @@ TODO
3
3
 
4
4
  * More of the memcached instruction set. This will be done based on user demand. Email me if the API is missing a feature you'd like to use.
5
5
  * Better API documentation
6
+ * Add noreply support for all commands
7
+ * Better pipelining support
@@ -68,8 +68,8 @@ module ActiveSupport
68
68
  def increment(key, amount = 1) # :nodoc:
69
69
  log("incrementing", key, amount)
70
70
  @data.incr(escape_key(key), amount)
71
- rescue Dalli::DalliError
72
- logger.error("DalliError (#{e}): #{e.message}")
71
+ rescue Dalli::DalliError => e
72
+ logger.error("DalliError (#{e}): #{e.message}") if logger
73
73
  nil
74
74
  end
75
75
 
@@ -80,8 +80,8 @@ module ActiveSupport
80
80
  def decrement(key, amount = 1) # :nodoc:
81
81
  log("decrement", key, amount)
82
82
  @data.decr(escape_key(key), amount)
83
- rescue Dalli::DalliError
84
- logger.error("DalliError (#{e}): #{e.message}")
83
+ rescue Dalli::DalliError => e
84
+ logger.error("DalliError (#{e}): #{e.message}") if logger
85
85
  nil
86
86
  end
87
87
 
@@ -167,7 +167,7 @@ module Dalli
167
167
  key = key.to_s
168
168
  args[0] = key
169
169
  end
170
- validate_key(key)
170
+ args[0] = key = validate_key(key)
171
171
  server = ring.server_for_key(key)
172
172
  server.request(op, *args)
173
173
  end
@@ -176,6 +176,7 @@ module Dalli
176
176
  raise ArgumentError, "illegal character in key #{key.inspect}" if key =~ /\s/
177
177
  raise ArgumentError, "key cannot be blank" if key.nil? || key.strip.size == 0
178
178
  raise ArgumentError, "key too long #{key.inspect}" if key.length > 250
179
+ @options[:namespace] ? "#{@options[:namespace]}:#{key}" : key
179
180
  end
180
181
  end
181
182
  end
@@ -208,7 +208,7 @@ module Dalli
208
208
  data = read(count) if count > 0
209
209
  if status == 1
210
210
  nil
211
- elsif status == 2
211
+ elsif status == 2 || status == 5
212
212
  false # Not stored, normal status for add operation
213
213
  elsif status != 0
214
214
  raise Dalli::DalliError, "Response error #{status}: #{RESPONSE_CODES[status]}"
@@ -1,3 +1,3 @@
1
1
  module Dalli
2
- VERSION = '0.9.7'
2
+ VERSION = '0.9.8'
3
3
  end
@@ -1,5 +1,7 @@
1
1
  require "socket"
2
2
 
3
+ $started = {}
4
+
3
5
  module MemcachedMock
4
6
  def self.start(port=19123, &block)
5
7
  server = TCPServer.new("localhost", port)
@@ -31,7 +33,7 @@ module MemcachedMock
31
33
  end
32
34
  end
33
35
 
34
- sleep 0.5 # Give time for the socket to start listening.
36
+ sleep 0.3 # Give time for the socket to start listening.
35
37
  yield
36
38
  ensure
37
39
  if pid
@@ -66,15 +68,21 @@ module MemcachedMock
66
68
  def memcached(port=19122, args='')
67
69
  Memcached.path ||= find_memcached
68
70
  cmd = "#{Memcached.path}memcached #{args} -p #{port}"
69
- # puts "Starting: #{cmd}..."
70
- pid = IO.popen(cmd).pid
71
- begin
72
- sleep 0.5
73
- yield Dalli::Client.new(["localhost:#{port}", "127.0.0.1:#{port}"])
74
- ensure
75
- Process.kill("TERM", pid)
76
- Process.wait(pid)
71
+ $started[port] ||= begin
72
+ #puts "Starting: #{cmd}..."
73
+ pid = IO.popen(cmd).pid
74
+ at_exit do
75
+ begin
76
+ Process.kill("TERM", pid)
77
+ Process.wait(pid)
78
+ rescue Errno::ECHILD
79
+ end
80
+ end
81
+ sleep 0.2
82
+ pid
77
83
  end
84
+
85
+ yield Dalli::Client.new(["localhost:#{port}", "127.0.0.1:#{port}"])
78
86
  end
79
87
  end
80
88
  end
@@ -118,6 +118,15 @@ class TestActiveSupport < Test::Unit::TestCase
118
118
  assert_equal ms.keys.sort, ds.keys.sort
119
119
  assert_equal ms[ms.keys.first].keys.sort, ds[ds.keys.first].keys.sort
120
120
 
121
+ assert_equal true, @dalli.write(:foo, 'a')
122
+ assert_equal true, @mc.write(:foo, 'a')
123
+
124
+ assert_equal true, @mc.exist?(:foo)
125
+ assert_equal true, @dalli.exist?(:foo)
126
+
127
+ assert_equal false, @mc.exist?(:bar)
128
+ assert_equal false, @dalli.exist?(:bar)
129
+
121
130
  @dalli.reset
122
131
  end
123
132
  end
@@ -28,7 +28,7 @@ class TestDalli < Test::Unit::TestCase
28
28
 
29
29
  context 'using a live server' do
30
30
 
31
- should "support huge get/set" do
31
+ should "support get/set" do
32
32
  memcached do |dc|
33
33
  dc.flush
34
34
 
@@ -43,6 +43,9 @@ class TestDalli < Test::Unit::TestCase
43
43
  dc.set('a', val1)
44
44
  val2 = dc.get('a')
45
45
  assert_equal val1, val2
46
+
47
+ assert_equal true, dc.set('a', nil)
48
+ assert_nil dc.get('a')
46
49
  end
47
50
  end
48
51
 
@@ -188,6 +191,23 @@ class TestDalli < Test::Unit::TestCase
188
191
  end
189
192
  end
190
193
 
194
+ should 'support the append and prepend operations' do
195
+ memcached do |dc|
196
+ resp = dc.flush
197
+ assert_equal true, dc.set('456', 'xyz', 0, :raw => true)
198
+ assert_equal true, dc.prepend('456', '0')
199
+ assert_equal true, dc.append('456', '9')
200
+ assert_equal '0xyz9', dc.get('456', :raw => true)
201
+
202
+ assert_raises Dalli::DalliError do
203
+ assert_equal '0xyz9', dc.get('456')
204
+ end
205
+
206
+ assert_equal false, dc.append('nonexist', 'abc')
207
+ assert_equal false, dc.prepend('nonexist', 'abc')
208
+ end
209
+ end
210
+
191
211
  should "pass a simple smoke test" do
192
212
  memcached do |dc|
193
213
  resp = dc.flush
@@ -241,7 +261,7 @@ class TestDalli < Test::Unit::TestCase
241
261
  end
242
262
 
243
263
  should "support multithreaded access" do
244
- memcached(19123) do |cache|
264
+ memcached do |cache|
245
265
  cache.flush
246
266
  workers = []
247
267
 
@@ -280,13 +300,24 @@ class TestDalli < Test::Unit::TestCase
280
300
  end
281
301
 
282
302
  should 'gracefully handle authentication failures' do
283
- memcached(19122, '-S') do |dc|
303
+ memcached(19124, '-S') do |dc|
284
304
  assert_raise Dalli::DalliError, /32/ do
285
305
  dc.set('abc', 123)
286
306
  end
287
307
  end
288
308
  end
289
309
 
310
+ should "handle namespaced keys" do
311
+ memcached do |dc|
312
+ dc = Dalli::Client.new('localhost:19122', :namespace => 'a')
313
+ dc.set('namespaced', 1)
314
+ dc2 = Dalli::Client.new('localhost:19122', :namespace => 'b')
315
+ dc2.set('namespaced', 2)
316
+ assert_equal 1, dc.get('namespaced')
317
+ assert_equal 2, dc2.get('namespaced')
318
+ end
319
+ end
320
+
290
321
  # OSX: Create a SASL user for the memcached application like so:
291
322
  #
292
323
  # saslpasswd2 -a memcached -c testuser
@@ -304,7 +335,7 @@ class TestDalli < Test::Unit::TestCase
304
335
  end
305
336
 
306
337
  should 'support SASL authentication' do
307
- memcached(19121, '-S') do |dc|
338
+ memcached(19124, '-S') do |dc|
308
339
  # I get "Dalli::NetworkError: Error authenticating: 32" in OSX
309
340
  # but SASL works on Heroku servers. YMMV.
310
341
  assert_equal true, dc.set('abc', 123)
@@ -6,7 +6,7 @@ class TestNetwork < Test::Unit::TestCase
6
6
 
7
7
  should 'handle connection refused' do
8
8
  assert_raise Dalli::NetworkError do
9
- dc = Dalli::Client.new 'localhost:19123'
9
+ dc = Dalli::Client.new 'localhost:19333'
10
10
  dc.get 'foo'
11
11
  end
12
12
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 9
8
- - 7
9
- version: 0.9.7
8
+ - 8
9
+ version: 0.9.8
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mike Perham
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-09-17 00:00:00 -07:00
17
+ date: 2010-09-29 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency