ohm 0.0.27 → 0.0.28

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -190,7 +190,7 @@ Note that calling these methods results in new sets being created
190
190
  on the fly. This is important so that you can perform further operations
191
191
  before reading the items to the client.
192
192
 
193
- For more information, see (SINTERSTORE)[http://code.google.com/p/redis/wiki/SinterstoreCommand] and (SDIFFSTORE)[http://code.google.com/p/redis/wiki/SdiffstoreCommand].
193
+ For more information, see [SINTERSTORE](http://code.google.com/p/redis/wiki/SinterstoreCommand) and [SDIFFSTORE](http://code.google.com/p/redis/wiki/SdiffstoreCommand).
194
194
 
195
195
  Validations
196
196
  -----------
data/Thorfile CHANGED
@@ -20,8 +20,22 @@ class Ohm < Thor
20
20
 
21
21
  desc "test", "Run all tests"
22
22
  def test
23
+ invoke "ohm:redis:start"
24
+
23
25
  Dir["test/**/*_test.rb"].each do |file|
24
26
  load file
25
27
  end
26
28
  end
29
+
30
+ class Redis < Thor
31
+ desc "start", "Start Redis server"
32
+ def start
33
+ %x{dtach -n /tmp/ohm.dtach redis-server test/test.conf}
34
+ end
35
+
36
+ desc "attach", "Attach to Redis server"
37
+ def attach
38
+ %x{dtach -a /tmp/ohm.dtach}
39
+ end
40
+ end
27
41
  end
data/lib/ohm.rb CHANGED
@@ -610,7 +610,12 @@ module Ohm
610
610
  end
611
611
 
612
612
  def write
613
- attributes.each { |att| write_remote(att, send(att)) }
613
+ unless attributes.empty?
614
+ rems, adds = attributes.map { |a| [key(a), send(a)] }.partition { |t| t.last.nil? }
615
+
616
+ db.del(*rems.flatten.compact) unless rems.empty?
617
+ db.mset(adds.flatten) unless adds.empty?
618
+ end
614
619
  end
615
620
 
616
621
  private
@@ -694,12 +699,6 @@ module Ohm
694
699
  db.get(key(att)) unless new?
695
700
  end
696
701
 
697
- def write_remote(att, value)
698
- value.nil? ?
699
- db.del(key(att)) :
700
- db.set(key(att), value)
701
- end
702
-
703
702
  def read_locals(attrs)
704
703
  attrs.map do |att|
705
704
  send(att)
data/lib/ohm/redis.rb CHANGED
@@ -1,5 +1,10 @@
1
1
  # encoding: UTF-8
2
2
 
3
+ # Redis client based on RubyRedis, original work of Salvatore Sanfilippo
4
+ # http://github.com/antirez/redis/blob/4a327b4af9885d89b5860548f44569d1d2bde5ab/client-libraries/ruby_2/rubyredis.rb
5
+ #
6
+ # Some improvements where inspired by the Redis-rb library, including the testing suite.
7
+ # http://github.com/ezmobius/redis-rb/
3
8
  require 'socket'
4
9
 
5
10
  begin
@@ -22,25 +27,34 @@ module Ohm
22
27
  end
23
28
  end
24
29
 
25
- BulkCommands = {
26
- :set => true,
27
- :setnx => true,
28
- :rpush => true,
30
+ BULK_COMMANDS = {
31
+ :echo => true,
32
+ :getset => true,
29
33
  :lpush => true,
30
- :lset => true,
31
34
  :lrem => true,
35
+ :lset => true,
36
+ :rpoplpush => true,
37
+ :rpush => true,
32
38
  :sadd => true,
33
- :srem => true,
39
+ :set => true,
40
+ :setnx => true,
34
41
  :sismember => true,
35
- :echo => true,
36
- :getset => true,
37
- :smove => true
42
+ :smove => true,
43
+ :srem => true,
44
+ :zadd => true,
45
+ :zrem => true,
46
+ :zscore => true
38
47
  }
39
48
 
40
- ProcessorIdentity = lambda { |reply| reply }
41
- ProcessorConvertToBool = lambda { |reply| reply == 0 ? false : reply }
42
- ProcessorSplitKeys = lambda { |reply| reply.split(" ") }
43
- ProcessorInfo = lambda do |reply|
49
+ MULTI_BULK_COMMANDS = {
50
+ :mset => true,
51
+ :msetnx => true
52
+ }
53
+
54
+ PROCESSOR_IDENTITY = lambda { |reply| reply }
55
+ PROCESSOR_CONVERT_TO_BOOL = lambda { |reply| reply == 0 ? false : reply }
56
+ PROCESSOR_SPLIT_KEYS = lambda { |reply| reply.split(" ") }
57
+ PROCESSOR_INFO = lambda do |reply|
44
58
  info = Hash.new
45
59
  reply.each_line do |line|
46
60
  key, value = line.split(":", 2).map { |part| part.chomp }
@@ -49,30 +63,33 @@ module Ohm
49
63
  info
50
64
  end
51
65
 
52
- ReplyProcessor = {
53
- :exists => ProcessorConvertToBool,
54
- :sismember=> ProcessorConvertToBool,
55
- :sadd=> ProcessorConvertToBool,
56
- :srem=> ProcessorConvertToBool,
57
- :smove=> ProcessorConvertToBool,
58
- :move=> ProcessorConvertToBool,
59
- :setnx=> ProcessorConvertToBool,
60
- :del=> ProcessorConvertToBool,
61
- :renamenx=> ProcessorConvertToBool,
62
- :expire=> ProcessorConvertToBool,
63
- :keys => ProcessorSplitKeys,
64
- :info => ProcessorInfo
66
+ REPLY_PROCESSOR = {
67
+ :exists => PROCESSOR_CONVERT_TO_BOOL,
68
+ :sismember=> PROCESSOR_CONVERT_TO_BOOL,
69
+ :sadd=> PROCESSOR_CONVERT_TO_BOOL,
70
+ :srem=> PROCESSOR_CONVERT_TO_BOOL,
71
+ :smove=> PROCESSOR_CONVERT_TO_BOOL,
72
+ :zadd => PROCESSOR_CONVERT_TO_BOOL,
73
+ :zrem => PROCESSOR_CONVERT_TO_BOOL,
74
+ :move=> PROCESSOR_CONVERT_TO_BOOL,
75
+ :setnx=> PROCESSOR_CONVERT_TO_BOOL,
76
+ :del=> PROCESSOR_CONVERT_TO_BOOL,
77
+ :renamenx=> PROCESSOR_CONVERT_TO_BOOL,
78
+ :expire=> PROCESSOR_CONVERT_TO_BOOL,
79
+ :keys => PROCESSOR_SPLIT_KEYS,
80
+ :info => PROCESSOR_INFO
65
81
  }
66
82
 
67
- ReplyProcessor.send(:initialize) do |hash, key|
68
- hash[key] = ProcessorIdentity
83
+ REPLY_PROCESSOR.send(:initialize) do |hash, key|
84
+ hash[key] = PROCESSOR_IDENTITY
69
85
  end
70
86
 
71
- def initialize(opts={})
72
- @host = opts[:host] || '127.0.0.1'
73
- @port = opts[:port] || 6379
74
- @db = opts[:db] || 0
75
- @timeout = opts[:timeout] || 0
87
+ def initialize(options = {})
88
+ @host = options[:host] || '127.0.0.1'
89
+ @port = options[:port] || 6379
90
+ @db = options[:db] || 0
91
+ @timeout = options[:timeout] || 0
92
+ @password = options[:password]
76
93
  connect
77
94
  end
78
95
 
@@ -104,6 +121,7 @@ module Ohm
104
121
 
105
122
  def connect
106
123
  connect_to(@host, @port, @timeout == 0 ? nil : @timeout)
124
+ call_command([:auth, @password]) if @password
107
125
  call_command([:select, @db]) if @db != 0
108
126
  @sock
109
127
  end
@@ -172,26 +190,49 @@ module Ohm
172
190
  end
173
191
 
174
192
  def raw_call_command(argv)
175
- bulk = extract_bulk_argument(argv)
176
- @sock.write(argv.join(" ") + "\r\n")
177
- @sock.write(bulk + "\r\n") if bulk
193
+ bulk_command?(argv) ?
194
+ process_bulk_command(argv) :
195
+ multi_bulk_command?(argv) ?
196
+ process_multi_bulk_command(argv) :
197
+ process_command(argv)
178
198
  process_reply(argv[0])
179
199
  end
180
200
 
181
- def bulk_command?(argv)
182
- BulkCommands[argv[0]] and argv.length > 1
201
+ def process_command(argv)
202
+ @sock.write("#{argv.join(" ")}\r\n")
183
203
  end
184
204
 
185
- def extract_bulk_argument(argv)
186
- if bulk_command?(argv)
187
- bulk = argv[-1].to_s
188
- argv[-1] = bulk.respond_to?(:bytesize) ? bulk.bytesize : bulk.size
189
- bulk
205
+ def process_bulk_command(argv)
206
+ bulk = argv.pop.to_s
207
+ argv.push ssize(bulk)
208
+ @sock.write("#{argv.join(" ")}\r\n")
209
+ @sock.write("#{bulk}\r\n")
210
+ end
211
+
212
+ def process_multi_bulk_command(argv)
213
+ params = argv.pop.to_a.flatten
214
+ params.unshift(argv[0])
215
+
216
+ command = ["*#{params.size}"]
217
+ params.each do |param|
218
+ param = param.to_s
219
+ command << "$#{ssize(param)}"
220
+ command << param
190
221
  end
222
+
223
+ @sock.write(command.map { |cmd| "#{cmd}\r\n"}.join)
224
+ end
225
+
226
+ def bulk_command?(argv)
227
+ BULK_COMMANDS[argv[0]] and argv.length > 1
228
+ end
229
+
230
+ def multi_bulk_command?(argv)
231
+ MULTI_BULK_COMMANDS[argv[0]]
191
232
  end
192
233
 
193
234
  def process_reply(command)
194
- ReplyProcessor[command][read_reply]
235
+ REPLY_PROCESSOR[command][read_reply]
195
236
  end
196
237
 
197
238
  def read_reply
@@ -239,7 +280,7 @@ module Ohm
239
280
 
240
281
  def format_bulk_reply(line)
241
282
  bulklen = line.to_i
242
- return nil if bulklen == -1
283
+ return if bulklen == -1
243
284
  reply = @sock.read(bulklen)
244
285
  @sock.read(2) # Discard CRLF.
245
286
 
@@ -253,5 +294,9 @@ module Ohm
253
294
  line.to_i.times { reply << read_reply }
254
295
  reply
255
296
  end
297
+
298
+ def ssize(string)
299
+ string.respond_to?(:bytesize) ? string.bytesize : string.size
300
+ end
256
301
  end
257
302
  end
data/test/model_test.rb CHANGED
@@ -100,7 +100,7 @@ class TestRedis < Test::Unit::TestCase
100
100
 
101
101
  context "Finding an event" do
102
102
  setup do
103
- Ohm.redis.sadd("Event", 1)
103
+ Ohm.redis.sadd("Event:all", 1)
104
104
  Ohm.redis.set("Event:1:name", "Concert")
105
105
  end
106
106
 
@@ -171,7 +171,7 @@ class TestRedis < Test::Unit::TestCase
171
171
  end
172
172
 
173
173
  context "Saving a model" do
174
- should "create the model if it's new" do
174
+ should "create the model if it is new" do
175
175
  event = Event.new(:name => "Foo").save
176
176
  assert_equal "Foo", Event[event.id].name
177
177
  end
data/test/redis_test.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require File.join(File.dirname(__FILE__), "test_helper")
2
2
 
3
+ # This test suit is based on the Redis-rb spec,
4
+ # located at http://github.com/ezmobius/redis-rb/
3
5
  class Foo
4
6
  attr_accessor :bar
5
7
  def initialize(bar)
@@ -22,30 +24,43 @@ class RedisTest < Test::Unit::TestCase
22
24
  @r.flushdb
23
25
  end
24
26
 
25
- should "should be able to GET a key" do
27
+ should "be able to GET a key" do
26
28
  assert_equal "bar", @r.get("foo")
27
29
  end
28
30
 
29
- should "should be able to SET a key" do
31
+ should "be able to SET a key" do
30
32
  @r.set("foo", "nik")
31
33
  assert_equal "nik", @r.get("foo")
32
34
  end
33
35
 
34
- should "should be able to SETNX(setnx)" do
36
+ should "be able to SETNX(setnx)" do
35
37
  @r.set("foo", "nik")
36
38
  assert_equal "nik", @r.get("foo")
37
39
  @r.setnx("foo", "bar")
38
40
  assert_equal "nik", @r.get("foo")
39
41
  end
40
42
 
41
- should "should be able to INCR(increment) a key" do
43
+ should "be able to MSET keys" do
44
+ @r.mset(:foo => "foobar", :bar => 1000)
45
+ assert_equal ["foobar", "1000"], @r.mget("foo", "bar")
46
+ assert_equal ["foobar", "1000", nil], @r.mget("foo", "bar", "baz")
47
+ end
48
+
49
+ should "be able to MGET keys" do
50
+ @r.set("foo", 1000)
51
+ @r.set("bar", 2000)
52
+ assert_equal ["1000", "2000"], @r.mget("foo", "bar")
53
+ assert_equal ["1000", "2000", nil], @r.mget("foo", "bar", "baz")
54
+ end
55
+
56
+ should "be able to INCR(increment) a key" do
42
57
  @r.del("counter")
43
58
  assert_equal 1, @r.incr("counter")
44
59
  assert_equal 2, @r.incr("counter")
45
60
  assert_equal 3, @r.incr("counter")
46
61
  end
47
62
 
48
- should "should be able to DECR(decrement) a key" do
63
+ should "be able to DECR(decrement) a key" do
49
64
  @r.del("counter")
50
65
  assert_equal 1, @r.incr("counter")
51
66
  assert_equal 2, @r.incr("counter")
@@ -54,11 +69,11 @@ class RedisTest < Test::Unit::TestCase
54
69
  assert_equal 0, @r.decrby("counter", 2)
55
70
  end
56
71
 
57
- should "should be able to RANDKEY(return a random key)" do
72
+ should "be able to RANDKEY(return a random key)" do
58
73
  assert_not_nil @r.randomkey
59
74
  end
60
75
 
61
- should "should be able to RENAME a key" do
76
+ should "be able to RENAME a key" do
62
77
  @r.del "foo"
63
78
  @r.del "bar"
64
79
  @r.set("foo", "hi")
@@ -66,7 +81,7 @@ class RedisTest < Test::Unit::TestCase
66
81
  assert_equal "hi", @r.get("bar")
67
82
  end
68
83
 
69
- should "should be able to RENAMENX(rename unless the new key already exists) a key" do
84
+ should "be able to RENAMENX(rename unless the new key already exists) a key" do
70
85
  @r.del "foo"
71
86
  @r.del "bar"
72
87
  @r.set("foo", "hi")
@@ -77,14 +92,14 @@ class RedisTest < Test::Unit::TestCase
77
92
  assert_equal "ohai", @r.get("bar")
78
93
  end
79
94
 
80
- should "should be able to EXISTS(check if key exists)" do
95
+ should "be able to EXISTS(check if key exists)" do
81
96
  @r.set("foo", "nik")
82
97
  assert @r.exists("foo")
83
98
  @r.del "foo"
84
99
  assert_equal false, @r.exists("foo")
85
100
  end
86
101
 
87
- should "should be able to KEYS(glob for keys)" do
102
+ should "be able to KEYS(glob for keys)" do
88
103
  @r.keys("f*").each do |key|
89
104
  @r.del key
90
105
  end
@@ -94,14 +109,14 @@ class RedisTest < Test::Unit::TestCase
94
109
  assert_equal ["f","fo", "foo"], @r.keys("f*").sort
95
110
  end
96
111
 
97
- should "should be able to check the TYPE of a key" do
112
+ should "be able to check the TYPE of a key" do
98
113
  @r.set("foo", "nik")
99
114
  assert_equal "string", @r.type("foo")
100
115
  @r.del "foo"
101
116
  assert_equal "none", @r.type("foo")
102
117
  end
103
118
 
104
- should "should be able to push to the head of a list" do
119
+ should "be able to push to the head of a list" do
105
120
  @r.lpush "list", "hello"
106
121
  @r.lpush "list", 42
107
122
  assert_equal "list", @r.type("list")
@@ -110,14 +125,14 @@ class RedisTest < Test::Unit::TestCase
110
125
  @r.del("list")
111
126
  end
112
127
 
113
- should "should be able to push to the tail of a list" do
128
+ should "be able to push to the tail of a list" do
114
129
  @r.rpush "list", "hello"
115
130
  assert_equal "list", @r.type("list")
116
131
  assert_equal 1, @r.llen("list")
117
132
  @r.del("list")
118
133
  end
119
134
 
120
- should "should be able to pop the tail of a list" do
135
+ should "be able to pop the tail of a list" do
121
136
  @r.rpush "list", "hello"
122
137
  @r.rpush "list", "goodbye"
123
138
  assert_equal "list", @r.type("list")
@@ -126,7 +141,7 @@ class RedisTest < Test::Unit::TestCase
126
141
  @r.del("list")
127
142
  end
128
143
 
129
- should "should be able to pop the head of a list" do
144
+ should "be able to pop the head of a list" do
130
145
  @r.rpush "list", "hello"
131
146
  @r.rpush "list", "goodbye"
132
147
  assert_equal "list", @r.type("list")
@@ -135,7 +150,7 @@ class RedisTest < Test::Unit::TestCase
135
150
  @r.del("list")
136
151
  end
137
152
 
138
- should "should be able to get the length of a list" do
153
+ should "be able to get the length of a list" do
139
154
  @r.rpush "list", "hello"
140
155
  @r.rpush "list", "goodbye"
141
156
  assert_equal "list", @r.type("list")
@@ -143,7 +158,7 @@ class RedisTest < Test::Unit::TestCase
143
158
  @r.del("list")
144
159
  end
145
160
 
146
- should "should be able to get a range of values from a list" do
161
+ should "be able to get a range of values from a list" do
147
162
  @r.rpush "list", "hello"
148
163
  @r.rpush "list", "goodbye"
149
164
  @r.rpush "list", "1"
@@ -155,7 +170,7 @@ class RedisTest < Test::Unit::TestCase
155
170
  @r.del("list")
156
171
  end
157
172
 
158
- should "should be able to get all the values from a list" do
173
+ should "be able to get all the values from a list" do
159
174
  @r.rpush "list", "1"
160
175
  @r.rpush "list", "2"
161
176
  @r.rpush "list", "3"
@@ -165,7 +180,7 @@ class RedisTest < Test::Unit::TestCase
165
180
  @r.del("list")
166
181
  end
167
182
 
168
- should "should be able to trim a list" do
183
+ should "be able to trim a list" do
169
184
  @r.rpush "list", "hello"
170
185
  @r.rpush "list", "goodbye"
171
186
  @r.rpush "list", "1"
@@ -179,7 +194,7 @@ class RedisTest < Test::Unit::TestCase
179
194
  @r.del("list")
180
195
  end
181
196
 
182
- should "should be able to get a value by indexing into a list" do
197
+ should "be able to get a value by indexing into a list" do
183
198
  @r.rpush "list", "hello"
184
199
  @r.rpush "list", "goodbye"
185
200
  assert_equal "list", @r.type("list")
@@ -188,7 +203,7 @@ class RedisTest < Test::Unit::TestCase
188
203
  @r.del("list")
189
204
  end
190
205
 
191
- should "should be able to set a value by indexing into a list" do
206
+ should "be able to set a value by indexing into a list" do
192
207
  @r.rpush "list", "hello"
193
208
  @r.rpush "list", "hello"
194
209
  assert_equal "list", @r.type("list")
@@ -198,7 +213,7 @@ class RedisTest < Test::Unit::TestCase
198
213
  @r.del("list")
199
214
  end
200
215
 
201
- should "should be able to remove values from a list LREM" do
216
+ should "be able to remove values from a list LREM" do
202
217
  @r.rpush "list", "hello"
203
218
  @r.rpush "list", "goodbye"
204
219
  assert_equal "list", @r.type("list")
@@ -208,7 +223,23 @@ class RedisTest < Test::Unit::TestCase
208
223
  @r.del("list")
209
224
  end
210
225
 
211
- should "should be able add members to a set" do
226
+ should "be able to pop values from a list and push them onto a temp list with RPOPLPUSH" do
227
+ @r.rpush "list", 'one'
228
+ @r.rpush "list", 'two'
229
+ @r.rpush "list", 'three'
230
+ assert_equal "list", @r.type('list')
231
+ assert_equal 3, @r.llen('list')
232
+ assert_equal %w(one two three), @r.lrange('list',0,-1)
233
+ assert_equal [], @r.lrange('tmp',0,-1)
234
+ assert_equal "three", @r.rpoplpush('list', 'tmp')
235
+ assert_equal %w(three), @r.lrange('tmp',0,-1)
236
+ assert_equal "two", @r.rpoplpush('list', 'tmp')
237
+ assert_equal %w(two three), @r.lrange('tmp',0,-1)
238
+ assert_equal "one", @r.rpoplpush('list', 'tmp')
239
+ assert_equal %w(one two three), @r.lrange('tmp',0,-1)
240
+ end
241
+
242
+ should "be able add members to a set" do
212
243
  @r.sadd "set", "key1"
213
244
  @r.sadd "set", "key2"
214
245
  assert_equal "set", @r.type("set")
@@ -217,7 +248,7 @@ class RedisTest < Test::Unit::TestCase
217
248
  @r.del("set")
218
249
  end
219
250
 
220
- should "should be able delete members to a set" do
251
+ should "be able delete members to a set" do
221
252
  @r.sadd "set", "key1"
222
253
  @r.sadd "set", "key2"
223
254
  assert_equal "set", @r.type("set")
@@ -229,7 +260,7 @@ class RedisTest < Test::Unit::TestCase
229
260
  @r.del("set")
230
261
  end
231
262
 
232
- should "should be able count the members of a set" do
263
+ should "be able count the members of a set" do
233
264
  @r.sadd "set", "key1"
234
265
  @r.sadd "set", "key2"
235
266
  assert_equal "set", @r.type("set")
@@ -237,7 +268,7 @@ class RedisTest < Test::Unit::TestCase
237
268
  @r.del("set")
238
269
  end
239
270
 
240
- should "should be able test for set membership" do
271
+ should "be able test for set membership" do
241
272
  @r.sadd "set", "key1"
242
273
  @r.sadd "set", "key2"
243
274
  assert_equal "set", @r.type("set")
@@ -248,7 +279,7 @@ class RedisTest < Test::Unit::TestCase
248
279
  @r.del("set")
249
280
  end
250
281
 
251
- should "should be able to do set intersection" do
282
+ should "be able to do set intersection" do
252
283
  @r.sadd "set", "key1"
253
284
  @r.sadd "set", "key2"
254
285
  @r.sadd "set2", "key2"
@@ -256,7 +287,7 @@ class RedisTest < Test::Unit::TestCase
256
287
  @r.del("set")
257
288
  end
258
289
 
259
- should "should be able to do set intersection and store the results in a key" do
290
+ should "be able to do set intersection and store the results in a key" do
260
291
  @r.sadd "set", "key1"
261
292
  @r.sadd "set", "key2"
262
293
  @r.sadd "set2", "key2"
@@ -265,7 +296,7 @@ class RedisTest < Test::Unit::TestCase
265
296
  @r.del("set")
266
297
  end
267
298
 
268
- should "should be able to do crazy SORT queries" do
299
+ should "be able to do crazy SORT queries" do
269
300
  @r.set("dog_1", "louie")
270
301
  @r.rpush "dogs", 1
271
302
  @r.set("dog_2", "lucy")
@@ -278,13 +309,68 @@ class RedisTest < Test::Unit::TestCase
278
309
  assert_equal ["taj"], @r.sort("dogs", :get => "dog_*", :limit => [0,1], :order => "desc alpha")
279
310
  end
280
311
 
281
- should "should provide info" do
312
+ should "be able add members to a zset ZADD" do
313
+ @r.zadd 'zset', 1, 'set'
314
+ assert_equal %w(set), @r.zrange('zset', 0, 1)
315
+ assert_equal 1, @r.zcard('zset')
316
+ @r.del('zset')
317
+ end
318
+
319
+ should "be able count the members of a zset ZCARD" do
320
+ @r.zadd 'zset', 1, 'foo'
321
+ @r.zcard('zset')
322
+ @r.del('zset')
323
+ end
324
+
325
+
326
+ should "be able delete members of a zset ZREM" do
327
+ @r.zadd 'zset', 1, 'set'
328
+ assert_equal 1, @r.zcard('zset')
329
+ @r.zadd 'zset', 2, 'set2'
330
+ assert_equal 2, @r.zcard('zset')
331
+ @r.zrem 'zset', 'set'
332
+ assert_equal 1, @r.zcard('zset')
333
+ @r.del('zset')
334
+ end
335
+
336
+ should "be able to get a range of values from a zset ZRANGE" do
337
+ @r.zadd 'zset', 1, 'set'
338
+ @r.zadd 'zset', 2, 'set2'
339
+ @r.zadd 'zset', 3, 'set3'
340
+ assert_equal 3, @r.zcard('zset')
341
+ assert_equal %w(set set2 set3), @r.zrange('zset', 0, 3)
342
+ @r.del('set')
343
+ @r.del('set2')
344
+ @r.del('set3')
345
+ @r.del('zset')
346
+ end
347
+
348
+ should "be able to get a reverse range of values from a zset ZREVRANGE" do
349
+ @r.zadd 'zset', 1, 'set'
350
+ @r.zadd 'zset', 2, 'set2'
351
+ @r.zadd 'zset', 3, 'set3'
352
+ assert_equal 3, @r.zcard('zset')
353
+ assert_equal %w(set3 set2 set), @r.zrevrange('zset', 0, 3)
354
+ @r.del('zset')
355
+ end
356
+
357
+ should "be able to get a range by score of values from a zset ZRANGEBYSCORE" do
358
+ @r.zadd 'zset', 1, 'set'
359
+ @r.zadd 'zset', 2, 'set2'
360
+ @r.zadd 'zset', 3, 'set3'
361
+ @r.zadd 'zset', 4, 'set4'
362
+ assert_equal 4, @r.zcard('zset')
363
+ assert_equal %w(set2 set3), @r.zrangebyscore('zset', 2, 3)
364
+ @r.del('zset')
365
+ end
366
+
367
+ should "provide info" do
282
368
  [:last_save_time, :redis_version, :total_connections_received, :connected_clients, :total_commands_processed, :connected_slaves, :uptime_in_seconds, :used_memory, :uptime_in_days, :changes_since_last_save].each do |x|
283
369
  assert @r.info.keys.include?(x)
284
370
  end
285
371
  end
286
372
 
287
- should "should be able to flush the database" do
373
+ should "be able to flush the database" do
288
374
  @r.set("key1", "keyone")
289
375
  @r.set("key2", "keytwo")
290
376
  assert_equal ["foo", "key1", "key2"], @r.keys("*").sort #foo from before
@@ -292,20 +378,13 @@ class RedisTest < Test::Unit::TestCase
292
378
  assert_equal [], @r.keys("*")
293
379
  end
294
380
 
295
- should "should be able to provide the last save time" do
381
+ should "be able to provide the last save time" do
296
382
  savetime = @r.lastsave
297
383
  assert_equal Time, Time.at(savetime).class
298
384
  assert Time.at(savetime) <= Time.now
299
385
  end
300
386
 
301
- should "should be able to MGET keys" do
302
- @r.set("foo", 1000)
303
- @r.set("bar", 2000)
304
- assert_equal ["1000", "2000"], @r.mget("foo", "bar")
305
- assert_equal ["1000", "2000", nil], @r.mget("foo", "bar", "baz")
306
- end
307
-
308
- should "should bgsave" do
387
+ should "bgsave" do
309
388
  assert_nothing_raised do
310
389
  @r.bgsave
311
390
  end
data/test/test.conf CHANGED
@@ -1,12 +1,9 @@
1
- daemonize yes
2
1
  dir ./test/db
3
2
  pidfile ./redis.pid
4
3
  port 6381
5
4
  timeout 300
6
5
 
7
- save 900 1
8
- save 300 10
9
- save 60 10000
6
+ save 900 10000
10
7
 
11
8
  loglevel debug
12
9
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ohm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.27
4
+ version: 0.0.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michel Martens
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-11-19 00:00:00 -03:00
13
+ date: 2009-11-24 00:00:00 -03:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -43,8 +43,10 @@ files:
43
43
  - test/test_helper.rb
44
44
  - test/validations_test.rb
45
45
  - test/test.conf
46
- has_rdoc: false
46
+ has_rdoc: true
47
47
  homepage: http://github.com/soveran/ohm
48
+ licenses: []
49
+
48
50
  post_install_message:
49
51
  rdoc_options: []
50
52
 
@@ -65,9 +67,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
67
  requirements: []
66
68
 
67
69
  rubyforge_project: ohm
68
- rubygems_version: 1.3.1
70
+ rubygems_version: 1.3.5
69
71
  signing_key:
70
- specification_version: 2
72
+ specification_version: 3
71
73
  summary: Object-hash mapping library for Redis.
72
74
  test_files: []
73
75