em-redis 0.1.1 → 0.2

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.
@@ -76,14 +76,14 @@ EM.describe EM::Protocols::Redis, "connected to an empty db" do
76
76
 
77
77
  should "be able to add a member to a nonexistent set" do
78
78
  @c.sadd("set_foo", "bar") do |r|
79
- r.should == 1
79
+ r.should == true
80
80
  done
81
81
  end
82
82
  end
83
83
 
84
84
  should "be able to get info about the db as a hash" do
85
85
  @c.info do |r|
86
- r.should.key? "redis_version"
86
+ r.should.key? :redis_version
87
87
  done
88
88
  end
89
89
  end
@@ -131,9 +131,9 @@ EM.describe EM::Protocols::Redis, "connected to a db containing some simple stri
131
131
 
132
132
  should "be able to set a value if a key doesn't exist" do
133
133
  @c.setnx "a", "foo" do |r|
134
- r.should == 0
134
+ r.should == false
135
135
  @c.setnx "zzz", "foo" do |r|
136
- r.should == 1
136
+ r.should == true
137
137
  done
138
138
  end
139
139
  end
@@ -141,9 +141,9 @@ EM.describe EM::Protocols::Redis, "connected to a db containing some simple stri
141
141
 
142
142
  should "be able to test for the existence of a key" do
143
143
  @c.exists "a" do |r|
144
- r.should == 1
144
+ r.should == true
145
145
  @c.exists "zzz" do |r|
146
- r.should == 0
146
+ r.should == false
147
147
  done
148
148
  end
149
149
  end
@@ -151,11 +151,11 @@ EM.describe EM::Protocols::Redis, "connected to a db containing some simple stri
151
151
 
152
152
  should "be able to delete a key" do
153
153
  @c.del "a" do |r|
154
- r.should == 1
154
+ r.should == true
155
155
  @c.exists "a" do |r|
156
- r.should == 0
156
+ r.should == false
157
157
  @c.del "a" do |r|
158
- r.should == 0
158
+ r.should == false
159
159
  done
160
160
  end
161
161
  end
@@ -183,9 +183,9 @@ EM.describe EM::Protocols::Redis, "connected to a db containing some simple stri
183
183
 
184
184
  should "be able to rename a key unless it exists" do
185
185
  @c.renamenx "a", "x" do |r|
186
- r.should == 0
186
+ r.should == false
187
187
  @c.renamenx "a", "zzz" do |r|
188
- r.should == 1
188
+ r.should == true
189
189
  @c.get "zzz" do |r|
190
190
  r.should == "b"
191
191
  done
@@ -252,14 +252,14 @@ EM.describe EM::Protocols::Redis, "connected to a db containing a list" do
252
252
  end
253
253
 
254
254
  should "be able to get a range of values from a list" do
255
- @c.lrange("foo", 0,1) do |r|
255
+ @c.lrange("foo", 0, 1) do |r|
256
256
  r.should == ["a", "b"]
257
257
  done
258
258
  end
259
259
  end
260
260
 
261
261
  should "be able to 'ltrim' a list" do
262
- @c.ltrim("foo", 0,1) do |r|
262
+ @c.ltrim("foo", 0, 1) do |r|
263
263
  r.should == "OK"
264
264
  @c.llen("foo") do |r|
265
265
  r.should == 2
@@ -269,7 +269,7 @@ EM.describe EM::Protocols::Redis, "connected to a db containing a list" do
269
269
  end
270
270
 
271
271
  should "be able to 'rem' a list element" do
272
- @c.lrem("foo", "a", 0) do |r|
272
+ @c.lrem("foo", 0, "a") do |r|
273
273
  r.should == 1
274
274
  @c.llen("foo") do |r|
275
275
  r.should == 2
@@ -309,9 +309,9 @@ EM.describe EM::Protocols::Redis, "connected to a db containing two sets" do
309
309
 
310
310
  should "be able to add a new member to a set unless it is a duplicate" do
311
311
  @c.sadd("foo", "d") do |r|
312
- r.should == 1 # success
312
+ r.should == true # success
313
313
  @c.sadd("foo", "a") do |r|
314
- r.should == 0 # failure
314
+ r.should == false # failure
315
315
  @c.scard("foo") do |r|
316
316
  r.should == 4
317
317
  done
@@ -322,9 +322,9 @@ EM.describe EM::Protocols::Redis, "connected to a db containing two sets" do
322
322
 
323
323
  should "be able to remove a set member if it exists" do
324
324
  @c.srem("foo", "a") do |r|
325
- r.should == 1
325
+ r.should == true
326
326
  @c.srem("foo", "z") do |r|
327
- r.should == 0
327
+ r.should == false
328
328
  @c.scard("foo") do |r|
329
329
  r.should == 2
330
330
  done
@@ -342,9 +342,9 @@ EM.describe EM::Protocols::Redis, "connected to a db containing two sets" do
342
342
 
343
343
  should "be able to detect set membership" do
344
344
  @c.sismember("foo", "a") do |r|
345
- r.should == 1
345
+ r.should == true
346
346
  @c.sismember("foo", "z") do |r|
347
- r.should == 0
347
+ r.should == false
348
348
  done
349
349
  end
350
350
  end
@@ -367,25 +367,22 @@ EM.describe EM::Protocols::Redis, "connected to a db containing two sets" do
367
367
  end
368
368
  end
369
369
 
370
- # UNION SET MANIP NOT IN RELEASE BUILDS YET
371
- ###########################################
372
- #
373
- # should "be able to find the sets' union" do
374
- # @c.sunion("foo", "bar") do |r|
375
- # r.should == ["a","b","c","d","e"]
376
- # done
377
- # end
378
- # end
370
+ should "be able to find the sets' union" do
371
+ @c.sunion("foo", "bar") do |r|
372
+ r.sort.should == ["a","b","c","d","e"]
373
+ done
374
+ end
375
+ end
379
376
 
380
- # should "be able to find and store the sets' union" do
381
- # @c.sunionstore("baz", "foo", "bar") do |r|
382
- # r.should == "OK"
383
- # @c.smembers("baz") do |r|
384
- # r.should == ["a","b","c","d","e"]
385
- # done
386
- # end
387
- # end
388
- # end
377
+ should "be able to find and store the sets' union" do
378
+ @c.sunionstore("baz", "foo", "bar") do |r|
379
+ r.should == 5
380
+ @c.smembers("baz") do |r|
381
+ r.sort.should == ["a","b","c","d","e"]
382
+ done
383
+ end
384
+ end
385
+ end
389
386
 
390
387
  should "be able to detect the type of a set" do
391
388
  @c.type "foo" do |r|
@@ -411,7 +408,7 @@ EM.describe EM::Protocols::Redis, "connected to a db containing three linked lis
411
408
  end
412
409
 
413
410
  should "be able to collate a sorted set of data" do
414
- @c.sort("foo", "*_sort", nil, nil, "*_data") do |r|
411
+ @c.sort("foo", :by => "*_sort", :get => "*_data") do |r|
415
412
  r.should == ["bar", "foo"]
416
413
  done
417
414
  end
@@ -1,6 +1,7 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/test_helper.rb")
2
2
 
3
3
  EM.describe EM::Protocols::Redis do
4
+ default_timeout 1
4
5
 
5
6
  before do
6
7
  @c = TestConnection.new
@@ -8,27 +9,27 @@ EM.describe EM::Protocols::Redis do
8
9
 
9
10
  # Inline request protocol
10
11
  should 'send inline commands correctly' do
11
- @c.inline_command("GET", 'a')
12
- @c.sent_data.should == "GET a\r\n"
12
+ @c.call_command(["GET", 'a'])
13
+ @c.sent_data.should == "get a\r\n"
13
14
  done
14
15
  end
15
-
16
+
16
17
  should "space-separate multiple inline arguments" do
17
- @c.inline_command("GET", 'a', 'b', 'c')
18
- @c.sent_data.should == "GET a b c\r\n"
18
+ @c.call_command(["GET", 'a', 'b', 'c'])
19
+ @c.sent_data.should == "get a b c\r\n"
19
20
  done
20
21
  end
21
22
 
22
23
  # Multiline request protocol
23
24
  should "send multiline commands correctly" do
24
- @c.multiline_command("SET", "foo", "abc")
25
- @c.sent_data.should == "SET foo 3\r\nabc\r\n"
25
+ @c.call_command(["SET", "foo", "abc"])
26
+ @c.sent_data.should == "set foo 3\r\nabc\r\n"
26
27
  done
27
28
  end
28
29
 
29
30
  should "send integers in multiline commands correctly" do
30
- @c.multiline_command("SET", "foo", 1_000_000)
31
- @c.sent_data.should == "SET foo 7\r\n1000000\r\n"
31
+ @c.call_command(["SET", "foo", 1_000_000])
32
+ @c.sent_data.should == "set foo 7\r\n1000000\r\n"
32
33
  done
33
34
  end
34
35
 
@@ -37,18 +38,18 @@ EM.describe EM::Protocols::Redis do
37
38
  # SORT
38
39
  should "send sort command" do
39
40
  @c.sort "foo"
40
- @c.sent_data.should == "SORT foo\r\n"
41
+ @c.sent_data.should == "sort foo\r\n"
41
42
  done
42
43
  end
43
44
 
44
45
  should "send sort command with all optional parameters" do
45
- @c.sort "foo", "foo_sort_*", 0, 10, "data_*", true, true
46
- @c.sent_data.should == "SORT foo BY foo_sort_* LIMIT 0 10 GET data_* DESC ALPHA\r\n"
46
+ @c.sort "foo", :by => "foo_sort_*", :limit => [0, 10], :get => "data_*", :order => "DESC ALPHA"
47
+ @c.sent_data.should == "sort foo BY foo_sort_* GET data_* DESC ALPHA LIMIT 0 10\r\n"
47
48
  done
48
49
  end
49
50
 
50
51
  should "parse keys response into an array" do
51
- @c.keys "*" do |resp|
52
+ @c.keys("*") do |resp|
52
53
  resp.should == ["a","b","c"]
53
54
  done
54
55
  end
@@ -58,7 +59,7 @@ EM.describe EM::Protocols::Redis do
58
59
 
59
60
  # Inline response
60
61
  should "parse an inline response" do
61
- @c.inline_command("PING") do |resp|
62
+ @c.call_command(["PING"]) do |resp|
62
63
  resp.should == "OK"
63
64
  done
64
65
  end
@@ -66,16 +67,24 @@ EM.describe EM::Protocols::Redis do
66
67
  end
67
68
 
68
69
  should "parse an inline integer response" do
69
- @c.inline_command("EXISTS") do |resp|
70
+ @c.call_command(["integer"]) do |resp|
70
71
  resp.should == 0
71
72
  done
72
73
  end
73
74
  @c.receive_data ":0\r\n"
74
75
  end
75
76
 
77
+ should "call processor if any" do
78
+ @c.call_command(["EXISTS"]) do |resp|
79
+ resp.should == false
80
+ done
81
+ end
82
+ @c.receive_data ":0\r\n"
83
+ end
84
+
76
85
  should "parse an inline error response" do
77
86
  lambda do
78
- @c.inline_command("BLARG")
87
+ @c.call_command(["blarg"])
79
88
  @c.receive_data "-FAIL\r\n"
80
89
  end.should.raise(EM::P::Redis::RedisError)
81
90
  done
@@ -83,7 +92,7 @@ EM.describe EM::Protocols::Redis do
83
92
 
84
93
  should "trigger a given error callback for inline error response instead of raising an error" do
85
94
  lambda do
86
- @c.inline_command("BLARG")
95
+ @c.call_command(["blarg"])
87
96
  @c.on_error {|code| code.should == "FAIL"; done }
88
97
  @c.receive_data "-FAIL\r\n"
89
98
  end.should.not.raise(EM::P::Redis::RedisError)
@@ -92,7 +101,7 @@ EM.describe EM::Protocols::Redis do
92
101
 
93
102
  # Bulk response
94
103
  should "parse a bulk response" do
95
- @c.inline_command("GET", "foo") do |resp|
104
+ @c.call_command(["GET", "foo"]) do |resp|
96
105
  resp.should == "bar"
97
106
  done
98
107
  end
@@ -101,16 +110,15 @@ EM.describe EM::Protocols::Redis do
101
110
  end
102
111
 
103
112
  should "distinguish nil in a bulk response" do
104
- @c.inline_command("GET", "bar") do |resp|
113
+ @c.call_command(["GET", "bar"]) do |resp|
105
114
  resp.should == nil
106
115
  end
107
116
  @c.receive_data "$-1\r\n"
108
117
  end
109
-
118
+
110
119
  # Multi-bulk response
111
-
112
120
  should "parse a multi-bulk response" do
113
- @c.inline_command "RANGE", 0, 10 do |resp|
121
+ @c.call_command(["RANGE", 0, 10]) do |resp|
114
122
  resp.should == ["a", "b", "foo"]
115
123
  done
116
124
  end
@@ -121,7 +129,7 @@ EM.describe EM::Protocols::Redis do
121
129
  end
122
130
 
123
131
  should "distinguish nil in a multi-bulk response" do
124
- @c.inline_command "RANGE", 0, 10 do |resp|
132
+ @c.call_command(["RANGE", 0, 10]) do |resp|
125
133
  resp.should == ["a", nil, "foo"]
126
134
  done
127
135
  end
@@ -0,0 +1,12 @@
1
+ namespace :redis do
2
+ desc "Test em-redis against a live Redis"
3
+ task :live_test do
4
+ require 'bacon'
5
+ sh "bacon spec/live_redis_protocol_spec.rb"
6
+ end
7
+
8
+ desc "Test em-redis offline"
9
+ task :offline_test do
10
+ sh "bacon spec/redis_protocol_spec.rb"
11
+ end
12
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: "0.2"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Broad
@@ -13,14 +13,44 @@ date: 2009-12-15 00:00:00 +03:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: bacon
16
+ name: eventmachine
17
17
  type: :runtime
18
18
  version_requirement:
19
19
  version_requirements: !ruby/object:Gem::Requirement
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: "0"
23
+ version: 0.12.11
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: bacon
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.0
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: em-spec
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.2.0
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: bones
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 3.2.0
24
54
  version:
25
55
  description: |-
26
56
  An EventMachine[http://rubyeventmachine.com/] based library for interacting with the very cool Redis[http://code.google.com/p/redis/] data store by Salvatore 'antirez' Sanfilippo.
@@ -28,12 +58,8 @@ description: |-
28
58
 
29
59
  This library is only useful when used as part of an application that relies on
30
60
  Event Machine's event loop. It implements an EM-based client protocol, which
31
- leverages the non-blocking nature of the EM interface to acheive significant
61
+ leverages the non-blocking nature of the EM interface to achieve significant
32
62
  parallelization without threads.
33
-
34
- WARNING: this library is my first attempt to write an evented client protocol,
35
- and isn't currently used in production anywhere. All that bit in the license
36
- about not being warranted to work for any particular purpose really applies.
37
63
  email: jonathan@relativepath.org
38
64
  executables: []
39
65
 
@@ -41,18 +67,21 @@ extensions: []
41
67
 
42
68
  extra_rdoc_files:
43
69
  - History.txt
70
+ - Manifest.txt
44
71
  - README.rdoc
45
72
  files:
73
+ - .gitignore
46
74
  - History.txt
47
75
  - Manifest.txt
48
76
  - README.rdoc
49
- - em-redis.gemspec
50
77
  - Rakefile
78
+ - em-redis.gemspec
51
79
  - lib/em-redis.rb
52
80
  - lib/em-redis/redis_protocol.rb
53
- - spec/test_helper.rb
54
81
  - spec/live_redis_protocol_spec.rb
55
82
  - spec/redis_protocol_spec.rb
83
+ - spec/test_helper.rb
84
+ - tasks/em-redis.rake
56
85
  has_rdoc: true
57
86
  homepage:
58
87
  licenses: []