redis 2.0.11 → 2.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/redis.rb +9 -1
- data/lib/redis/client.rb +4 -2
- data/lib/redis/url.rb +69 -0
- metadata +4 -3
data/lib/redis.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'socket'
|
2
2
|
|
3
3
|
class Redis
|
4
|
-
VERSION = "2.0.
|
4
|
+
VERSION = "2.0.12"
|
5
5
|
|
6
6
|
class ProtocolError < RuntimeError
|
7
7
|
def initialize(reply_type)
|
@@ -36,6 +36,14 @@ class Redis
|
|
36
36
|
new(options)
|
37
37
|
end
|
38
38
|
|
39
|
+
def self.current
|
40
|
+
Thread.current[:redis] ||= Redis.connect
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.current=(redis)
|
44
|
+
Thread.current[:redis] = redis
|
45
|
+
end
|
46
|
+
|
39
47
|
def initialize(options = {})
|
40
48
|
if options[:thread_safe]
|
41
49
|
@client = Client::ThreadSafe.new(options)
|
data/lib/redis/client.rb
CHANGED
data/lib/redis/url.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require "uri/generic"
|
2
|
+
|
3
|
+
module URI
|
4
|
+
class Redis < Generic
|
5
|
+
DEFAULT_PORT = 6379
|
6
|
+
|
7
|
+
COMPONENT = [:scheme, :password, :host, :port, :db].freeze
|
8
|
+
|
9
|
+
def db
|
10
|
+
path[1..-1].to_i
|
11
|
+
end
|
12
|
+
|
13
|
+
alias password user
|
14
|
+
|
15
|
+
protected
|
16
|
+
def check_path(value)
|
17
|
+
if super(value)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
@@schemes["REDIS"] = Redis
|
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
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 2
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 2.0.
|
8
|
+
- 12
|
9
|
+
version: 2.0.12
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Ezra Zygmuntowicz
|
@@ -21,7 +21,7 @@ autorequire: redis
|
|
21
21
|
bindir: bin
|
22
22
|
cert_chain: []
|
23
23
|
|
24
|
-
date: 2010-10-
|
24
|
+
date: 2010-10-27 00:00:00 -03:00
|
25
25
|
default_executable:
|
26
26
|
dependencies: []
|
27
27
|
|
@@ -43,6 +43,7 @@ files:
|
|
43
43
|
- lib/redis/hash_ring.rb
|
44
44
|
- lib/redis/pipeline.rb
|
45
45
|
- lib/redis/subscribe.rb
|
46
|
+
- lib/redis/url.rb
|
46
47
|
- lib/redis.rb
|
47
48
|
has_rdoc: true
|
48
49
|
homepage: http://github.com/ezmobius/redis-rb
|