redis 2.0.7 → 2.0.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.
Files changed (4) hide show
  1. data/Rakefile +19 -32
  2. data/lib/redis.rb +29 -1
  3. data/lib/redis/url.rb +69 -0
  4. metadata +4 -3
data/Rakefile CHANGED
@@ -93,21 +93,7 @@ namespace :commands do
93
93
  def redis_commands
94
94
  $redis_commands ||= begin
95
95
  require "open-uri"
96
- require "nokogiri"
97
-
98
- doc = Nokogiri::HTML(open("http://code.google.com/p/redis/wiki/CommandReference"))
99
-
100
- commands = {}
101
-
102
- doc.xpath("//ul/li").each do |node|
103
- node.at_xpath("./a").text.split("/").each do |name|
104
- if name =~ /^[A-Z]+$/
105
- commands[name.downcase] = node.at_xpath("./tt").text
106
- end
107
- end
108
- end
109
-
110
- commands
96
+ open("http://dimaion.com/redis/master").read.split
111
97
  end
112
98
  end
113
99
 
@@ -134,33 +120,34 @@ namespace :commands do
134
120
 
135
121
  task :verify do
136
122
  require "redis"
137
-
138
- Dir["test/**/*_test.rb"].each { |f| require "./#{f}" }
123
+ require "stringio"
139
124
 
140
125
  log = StringIO.new
141
126
 
142
- RedisTest::OPTIONS[:logger] = Logger.new(log)
143
-
144
- redis = Redis.new
127
+ at_exit do
128
+ redis = Redis.new
145
129
 
146
- Test::Unit::AutoRunner.run
130
+ report = ["Command", "\033[0mDefined?\033[0m", "\033[0mTested?\033[0m"]
147
131
 
148
- report = ["Command", "\033[0mDefined?\033[0m", "\033[0mTested?\033[0m"]
132
+ yes, no = "\033[1;32mYes\033[0m", "\033[1;31mNo\033[0m"
149
133
 
150
- yes, no = "\033[1;32mYes\033[0m", "\033[1;31mNo\033[0m"
134
+ redis_commands.sort.each do |name, _|
135
+ defined, tested = redis.respond_to?(name), log.string[">> #{name.upcase}"]
151
136
 
152
- redis_commands.sort.each do |name, _|
153
- defined, tested = redis.respond_to?(name), log.string[">> #{name.upcase}"]
137
+ next if defined && tested
154
138
 
155
- next if defined && tested
139
+ report << name
140
+ report << (defined ? yes : no)
141
+ report << (tested ? yes : no)
142
+ end
156
143
 
157
- report << name
158
- report << (defined ? yes : no)
159
- report << (tested ? yes : no)
144
+ IO.popen("rs 0 3", "w") do |io|
145
+ io.puts report.join("\n")
146
+ end
160
147
  end
161
148
 
162
- IO.popen("rs 0 3", "w") do |io|
163
- io.puts report.join("\n")
164
- end
149
+ Dir["test/**/redis_test.rb"].each { |f| require "./#{f}" }
150
+
151
+ RedisTest::OPTIONS[:logger] = Logger.new(log)
165
152
  end
166
153
  end
data/lib/redis.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'socket'
2
2
 
3
3
  class Redis
4
- VERSION = "2.0.7"
4
+ VERSION = "2.0.8"
5
5
 
6
6
  class ProtocolError < RuntimeError
7
7
  def initialize(reply_type)
@@ -97,6 +97,10 @@ class Redis
97
97
  @client.call(:substr, key, start, stop)
98
98
  end
99
99
 
100
+ def strlen(key)
101
+ @client.call(:strlen, key)
102
+ end
103
+
100
104
  def hgetall(key)
101
105
  Hash[*@client.call(:hgetall, key)]
102
106
  end
@@ -157,6 +161,10 @@ class Redis
157
161
  @client.call(:lindex, key, index)
158
162
  end
159
163
 
164
+ def linsert(key, where, pivot, value)
165
+ @client.call(:linsert, key, where, pivot, value)
166
+ end
167
+
160
168
  def lset(key, index, value)
161
169
  @client.call(:lset, key, index, value)
162
170
  end
@@ -169,10 +177,18 @@ class Redis
169
177
  @client.call(:rpush, key, value)
170
178
  end
171
179
 
180
+ def rpushx(key, value)
181
+ @client.call(:rpushx, key, value)
182
+ end
183
+
172
184
  def lpush(key, value)
173
185
  @client.call(:lpush, key, value)
174
186
  end
175
187
 
188
+ def lpushx(key, value)
189
+ @client.call(:lpushx, key, value)
190
+ end
191
+
176
192
  def rpop(key)
177
193
  @client.call(:rpop, key)
178
194
  end
@@ -372,6 +388,10 @@ class Redis
372
388
  _bool @client.call(:hset, key, field, value)
373
389
  end
374
390
 
391
+ def hsetnx(key, field, value)
392
+ _bool @client.call(:hsetnx, key, field, value)
393
+ end
394
+
375
395
  def hmset(key, *attrs)
376
396
  @client.call(:hmset, key, *attrs)
377
397
  end
@@ -412,6 +432,14 @@ class Redis
412
432
  @client.call_loop(:monitor, &block)
413
433
  end
414
434
 
435
+ def debug(*args)
436
+ @client.call(:debug, *args)
437
+ end
438
+
439
+ def sync
440
+ @client.call(:sync)
441
+ end
442
+
415
443
  def [](key)
416
444
  get(key)
417
445
  end
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
- - 7
9
- version: 2.0.7
8
+ - 8
9
+ version: 2.0.8
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-09-13 00:00:00 -03:00
24
+ date: 2010-09-14 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