dalli 0.9.6 → 0.9.7

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,6 +1,12 @@
1
1
  Dalli Changelog
2
2
  =====================
3
3
 
4
+ 0.9.7
5
+ -----
6
+
7
+ - Small fix for NewRelic integration.
8
+ - Detect and fail on older memcached servers (pre-1.4).
9
+
4
10
  0.9.6
5
11
  -----
6
12
 
data/TODO.md CHANGED
@@ -3,4 +3,3 @@ 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
- * Detect and fail on older memcached servers (pre-1.4)
data/lib/dalli/client.rb CHANGED
@@ -16,7 +16,7 @@ module Dalli
16
16
  # :threadsafe - ensure that only one thread is actively using a socket at a time. Default: true.
17
17
  #
18
18
  def initialize(servers=nil, options={})
19
- @servers = servers
19
+ @servers = servers || 'localhost:11211'
20
20
  @options = options
21
21
  end
22
22
 
@@ -104,7 +104,7 @@ module Dalli
104
104
  # If default is nil, the counter must already exist or the operation
105
105
  # will fail and will return nil. Otherwise this method will return
106
106
  # the new value for the counter.
107
- def incr(key, amt, ttl=0, default=nil)
107
+ def incr(key, amt=1, ttl=0, default=nil)
108
108
  raise ArgumentError, "Positive values only: #{amt}" if amt < 0
109
109
  perform(:incr, key, amt, ttl, default)
110
110
  end
@@ -119,7 +119,7 @@ module Dalli
119
119
  # If default is nil, the counter must already exist or the operation
120
120
  # will fail and will return nil. Otherwise this method will return
121
121
  # the new value for the counter.
122
- def decr(key, amt, ttl=0, default=nil)
122
+ def decr(key, amt=1, ttl=0, default=nil)
123
123
  raise ArgumentError, "Positive values only: #{amt}" if amt < 0
124
124
  perform(:decr, key, amt, ttl, default)
125
125
  end
data/lib/dalli/server.rb CHANGED
@@ -15,7 +15,9 @@ module Dalli
15
15
  @weight = Integer(@weight)
16
16
  @down_at = nil
17
17
  connection
18
- Dalli.logger.debug { "#{@hostname}:#{@port} running memcached v#{request(:version)}" }
18
+ @version = detect_memcached_version
19
+ raise NotImplementedError, "Dalli does not support memcached versions < 1.4.0, found #{@version} at #{@hostname}:#{@port}" if @version < '1.4.0'
20
+ Dalli.logger.debug { "#{@hostname}:#{@port} running memcached v#{@version}" }
19
21
  end
20
22
 
21
23
  # Chokepoint method for instrumentation
@@ -51,6 +53,19 @@ module Dalli
51
53
 
52
54
  private
53
55
 
56
+ def detect_memcached_version
57
+ # HACK, the server does not appear to have a way to negotiate the protocol.
58
+ # If you ask for the version in text, the socket is immediately locked to the text
59
+ # protocol. All we can do is use binary and handle the failure if the server is old.
60
+ # Alternative suggestions welcome.
61
+ begin
62
+ binary_version
63
+ rescue Dalli::NetworkError
64
+ sleep 1
65
+ text_version
66
+ end
67
+ end
68
+
54
69
  def down!
55
70
  close
56
71
  @down_at = Time.now.to_i
@@ -147,12 +162,6 @@ module Dalli
147
162
  generic_response
148
163
  end
149
164
 
150
- def version
151
- req = [REQUEST, OPCODES[:version], 0, 0, 0, 0, 0, 0, 0].pack(FORMAT[:noop])
152
- write(req)
153
- generic_response
154
- end
155
-
156
165
  def stats(info='')
157
166
  req = [REQUEST, OPCODES[:stat], info.size, 0, 0, 0, info.size, 0, 0, info].pack(FORMAT[:stat])
158
167
  write(req)
@@ -165,6 +174,18 @@ module Dalli
165
174
  cas_response
166
175
  end
167
176
 
177
+ def binary_version
178
+ req = [REQUEST, OPCODES[:version], 0, 0, 0, 0, 0, 0, 0].pack(FORMAT[:noop])
179
+ write(req)
180
+ generic_response
181
+ end
182
+
183
+ def text_version
184
+ write("version\r\n")
185
+ connection.gets =~ /VERSION (.*)\r\n/
186
+ $1
187
+ end
188
+
168
189
  def cas_response
169
190
  header = read(24)
170
191
  raise Dalli::NetworkError, 'No response' if !header
data/lib/dalli/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dalli
2
- VERSION = '0.9.6'
2
+ VERSION = '0.9.7'
3
3
  end
data/test/test_dalli.rb CHANGED
@@ -2,6 +2,30 @@ require 'helper'
2
2
  require 'memcached_mock'
3
3
 
4
4
  class TestDalli < Test::Unit::TestCase
5
+
6
+ should "default to localhost:11211" do
7
+ dc = Dalli::Client.new
8
+ ring = dc.send(:ring)
9
+ s1 = ring.servers.first.hostname
10
+ assert_equal 1, ring.servers.size
11
+ dc.close
12
+
13
+ dc = Dalli::Client.new('localhost:11211')
14
+ ring = dc.send(:ring)
15
+ s2 = ring.servers.first.hostname
16
+ assert_equal 1, ring.servers.size
17
+ dc.close
18
+
19
+ dc = Dalli::Client.new(['localhost:11211'])
20
+ ring = dc.send(:ring)
21
+ s3 = ring.servers.first.hostname
22
+ assert_equal 1, ring.servers.size
23
+ dc.close
24
+
25
+ assert_equal s1, s2
26
+ assert_equal s2, s3
27
+ end
28
+
5
29
  context 'using a live server' do
6
30
 
7
31
  should "support huge get/set" do
data/test/test_network.rb CHANGED
@@ -12,6 +12,9 @@ class TestNetwork < Test::Unit::TestCase
12
12
  end
13
13
 
14
14
  context 'with a fake server' do
15
+ setup do
16
+ Dalli::Server.any_instance.expects(:detect_memcached_version).returns('1.4.5')
17
+ end
15
18
 
16
19
  should 'handle connection reset' do
17
20
  memcached_mock(lambda {|sock| sock.close }) do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 9
8
- - 6
9
- version: 0.9.6
8
+ - 7
9
+ version: 0.9.7
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-16 00:00:00 -07:00
17
+ date: 2010-09-17 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency