redis 2.0.3 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -60,7 +60,8 @@ task :stop do
60
60
  end
61
61
 
62
62
  Rake::TestTask.new(:test) do |t|
63
- t.pattern = 'test/**/*_test.rb'
63
+ t.pattern = "test/**/*_test.rb"
64
+ t.ruby_opts << "-r rubygems"
64
65
  end
65
66
 
66
67
  Rake::GemPackageTask.new(spec) do |pkg|
@@ -1,7 +1,7 @@
1
1
  require 'socket'
2
2
 
3
3
  class Redis
4
- VERSION = "2.0.3"
4
+ VERSION = "2.0.4"
5
5
 
6
6
  class ProtocolError < RuntimeError
7
7
  def initialize(reply_type)
@@ -284,6 +284,10 @@ class Redis
284
284
  @client.call(:zrangebyscore, key, min, max, *command.to_a)
285
285
  end
286
286
 
287
+ def zcount(key, start, stop)
288
+ @client.call(:zcount, key, start, stop)
289
+ end
290
+
287
291
  def zrevrange(key, start, stop, options = {})
288
292
  command = CommandOptions.new(options) do |c|
289
293
  c.bool :with_scores
@@ -617,18 +621,6 @@ private
617
621
 
618
622
  end
619
623
 
620
- begin
621
- if RUBY_VERSION >= '1.9'
622
- require 'timeout'
623
- Redis::Timer = Timeout
624
- else
625
- require 'system_timer'
626
- Redis::Timer = SystemTimer
627
- end
628
- rescue LoadError
629
- Redis::Timer = nil
630
- end
631
-
632
624
  require 'redis/client'
633
625
  require 'redis/pipeline'
634
626
  require 'redis/subscribe'
@@ -84,7 +84,6 @@ class Redis
84
84
  end
85
85
 
86
86
  def read
87
-
88
87
  # We read the first byte using read() mainly because gets() is
89
88
  # immune to raw socket timeouts.
90
89
  begin
@@ -182,7 +181,7 @@ class Redis
182
181
  def format_bulk_reply(line)
183
182
  bulklen = line.to_i
184
183
  return if bulklen == -1
185
- reply = @sock.read(bulklen)
184
+ reply = encode(@sock.read(bulklen))
186
185
  @sock.read(2) # Discard CRLF.
187
186
  reply
188
187
  end
@@ -191,9 +190,7 @@ class Redis
191
190
  n = line.to_i
192
191
  return if n == -1
193
192
 
194
- reply = []
195
- n.times { reply << read }
196
- reply
193
+ Array.new(n) { read }
197
194
  end
198
195
 
199
196
  def logging(commands)
@@ -211,18 +208,9 @@ class Redis
211
208
  end
212
209
  end
213
210
 
214
- if defined?(Timeout)
215
- TimeoutError = Timeout::Error
216
- else
217
- TimeoutError = Exception
218
- end
219
-
220
211
  def connect_to(host, port)
221
- begin
212
+ with_timeout(@timeout) do
222
213
  @sock = TCPSocket.new(host, port)
223
- rescue TimeoutError
224
- @sock = nil
225
- raise
226
214
  end
227
215
 
228
216
  @sock.setsockopt Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1
@@ -253,7 +241,7 @@ class Redis
253
241
 
254
242
  begin
255
243
  yield
256
- rescue Errno::ECONNRESET, Errno::EPIPE, Errno::ECONNABORTED
244
+ rescue Errno::ECONNRESET, Errno::EPIPE, Errno::ECONNABORTED, Errno::EBADF
257
245
  if reconnect
258
246
  yield
259
247
  else
@@ -275,10 +263,40 @@ class Redis
275
263
  end
276
264
 
277
265
  def ensure_connected(&block)
278
- super do
279
- synchronize(&block)
266
+ synchronize { super }
267
+ end
268
+ end
269
+
270
+ if RUBY_VERSION >= "1.9"
271
+ require "timeout"
272
+
273
+ def with_timeout(seconds, &block)
274
+ Timeout.timeout(seconds, &block)
275
+ end
276
+ else
277
+ begin
278
+ require "system_timer"
279
+
280
+ def with_timeout(seconds, &block)
281
+ SystemTimer.timeout_after(seconds, &block)
282
+ end
283
+ rescue LoadError
284
+ $stderr.puts "WARNING: Could not find a good alternative for performing time outs -- connecting to Redis will not time out. Try installing the SystemTimer gem."
285
+
286
+ def with_timeout(*args)
287
+ yield
280
288
  end
281
289
  end
282
290
  end
291
+
292
+ if defined?(Encoding)
293
+ def encode(string)
294
+ string.force_encoding(Encoding::default_external)
295
+ end
296
+ else
297
+ def encode(string)
298
+ string
299
+ end
300
+ end
283
301
  end
284
302
  end
@@ -21,3 +21,49 @@ module URI
21
21
 
22
22
  @@schemes["REDIS"] = Redis
23
23
  end
24
+ require File.expand_path(File.join(File.dirname(__FILE__), "test_helper"))
25
+ require "redis/url"
26
+
27
+ class RedisURLTest < Test::Unit::TestCase
28
+ test "default values" do
29
+ uri = URI.parse("redis://localhost")
30
+
31
+ assert_equal "localhost", uri.host
32
+ assert_equal 6379, uri.port
33
+ assert_equal 0, uri.db
34
+ assert_equal nil, uri.password
35
+ end
36
+
37
+ test "password" do
38
+ uri = URI.parse("redis://secret@localhost")
39
+
40
+ assert_equal "localhost", uri.host
41
+ assert_equal 6379, uri.port
42
+ assert_equal 0, uri.db
43
+ assert_equal "secret", uri.password
44
+ end
45
+
46
+ test "db number" do
47
+ uri = URI.parse("redis://secret@localhost/15")
48
+
49
+ assert_equal "localhost", uri.host
50
+ assert_equal 6379, uri.port
51
+ assert_equal 15, uri.db
52
+ assert_equal "secret", uri.password
53
+ end
54
+
55
+ test "port" do
56
+ uri = URI.parse("redis://localhost:6380")
57
+
58
+ assert_equal "localhost", uri.host
59
+ assert_equal 6380, uri.port
60
+ assert_equal 0, uri.db
61
+ assert_equal nil, uri.password
62
+ end
63
+
64
+ test "to_s" do
65
+ uri = URI.parse("redis://secret@localhost:6380/15")
66
+
67
+ assert_equal "redis://secret@localhost:6380/15", uri.to_s
68
+ end
69
+ end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 7
4
5
  prerelease: false
5
6
  segments:
6
7
  - 2
7
8
  - 0
8
- - 3
9
- version: 2.0.3
9
+ - 4
10
+ version: 2.0.4
10
11
  platform: ruby
11
12
  authors:
12
13
  - Ezra Zygmuntowicz
@@ -21,7 +22,7 @@ autorequire: redis
21
22
  bindir: bin
22
23
  cert_chain: []
23
24
 
24
- date: 2010-06-22 00:00:00 -03:00
25
+ date: 2010-07-22 00:00:00 -03:00
25
26
  default_executable:
26
27
  dependencies: []
27
28
 
@@ -59,6 +60,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
59
60
  requirements:
60
61
  - - ">="
61
62
  - !ruby/object:Gem::Version
63
+ hash: 3
62
64
  segments:
63
65
  - 0
64
66
  version: "0"
@@ -67,6 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
69
  requirements:
68
70
  - - ">="
69
71
  - !ruby/object:Gem::Version
72
+ hash: 3
70
73
  segments:
71
74
  - 0
72
75
  version: "0"