ezmobius-redis 0.0.3.4

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.
@@ -0,0 +1,419 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ class Foo
4
+ attr_accessor :bar
5
+ def initialize(bar)
6
+ @bar = bar
7
+ end
8
+
9
+ def ==(other)
10
+ @bar == other.bar
11
+ end
12
+ end
13
+
14
+ describe "redis" do
15
+ before(:all) do
16
+ @r = Redis.new
17
+ @r.select_db(15) # use database 15 for testing so we dont accidentally step on you real data
18
+ end
19
+
20
+ before(:each) do
21
+ @r['foo'] = 'bar'
22
+ end
23
+
24
+ after(:each) do
25
+ @r.keys('*').each {|k| @r.delete k}
26
+ end
27
+
28
+ after(:all) do
29
+ @r.quit
30
+ end
31
+
32
+
33
+ it "should be able to GET a key" do
34
+ @r['foo'].should == 'bar'
35
+ end
36
+
37
+ it "should be able to SET a key" do
38
+ @r['foo'] = 'nik'
39
+ @r['foo'].should == 'nik'
40
+ end
41
+
42
+ it "should properly handle trailing newline characters" do
43
+ @r['foo'] = "bar\n"
44
+ @r['foo'].should == "bar\n"
45
+ end
46
+
47
+ it "should store and retrieve all possible characters at the beginning and the end of a string" do
48
+ (0..255).each do |char_idx|
49
+ string = "#{char_idx.chr}---#{char_idx.chr}"
50
+ @r['foo'] = string
51
+ @r['foo'].should == string
52
+ end
53
+ end
54
+
55
+ it "should be able to SET a key with an expiry" do
56
+ @r.set('foo', 'bar', 1)
57
+ @r['foo'].should == 'bar'
58
+ sleep 2
59
+ @r['foo'].should == nil
60
+ end
61
+
62
+ it "should be able to SETNX(set_unless_exists)" do
63
+ @r['foo'] = 'nik'
64
+ @r['foo'].should == 'nik'
65
+ @r.set_unless_exists 'foo', 'bar'
66
+ @r['foo'].should == 'nik'
67
+ end
68
+ #
69
+ it "should be able to INCR(increment) a key" do
70
+ @r.delete('counter')
71
+ @r.incr('counter').should == 1
72
+ @r.incr('counter').should == 2
73
+ @r.incr('counter').should == 3
74
+ end
75
+ #
76
+ it "should be able to DECR(decrement) a key" do
77
+ @r.delete('counter')
78
+ @r.incr('counter').should == 1
79
+ @r.incr('counter').should == 2
80
+ @r.incr('counter').should == 3
81
+ @r.decr('counter').should == 2
82
+ @r.decr('counter', 2).should == 0
83
+ end
84
+ #
85
+ it "should be able to RANDKEY(return a random key)" do
86
+ @r.randkey.should_not be_nil
87
+ end
88
+ #
89
+ it "should be able to RENAME a key" do
90
+ @r.delete 'foo'
91
+ @r.delete 'bar'
92
+ @r['foo'] = 'hi'
93
+ @r.rename! 'foo', 'bar'
94
+ @r['bar'].should == 'hi'
95
+ end
96
+ #
97
+ it "should be able to RENAMENX(rename unless the new key already exists) a key" do
98
+ @r.delete 'foo'
99
+ @r.delete 'bar'
100
+ @r['foo'] = 'hi'
101
+ @r['bar'] = 'ohai'
102
+ lambda {@r.rename 'foo', 'bar'}.should raise_error(RedisRenameError)
103
+ @r['bar'].should == 'ohai'
104
+ end
105
+ #
106
+ it "should be able to get DBSIZE of the database" do
107
+ @r.delete 'foo'
108
+ dbsize_without_foo = @r.dbsize
109
+ @r['foo'] = 0
110
+ dbsize_with_foo = @r.dbsize
111
+
112
+ dbsize_with_foo.should == dbsize_without_foo + 1
113
+ end
114
+ #
115
+ it "should be able to EXPIRE a key" do
116
+ @r['foo'] = 'bar'
117
+ @r.expire('foo', 1)
118
+ @r['foo'].should == "bar"
119
+ sleep 2
120
+ @r['foo'].should == nil
121
+ end
122
+ #
123
+ it "should be able to EXISTS(check if key exists)" do
124
+ @r['foo'] = 'nik'
125
+ @r.key?('foo').should be_true
126
+ @r.delete 'foo'
127
+ @r.key?('foo').should be_false
128
+ end
129
+ #
130
+ it "should be able to KEYS(glob for keys)" do
131
+ @r.keys("f*").each do |key|
132
+ @r.delete key
133
+ end
134
+ @r['f'] = 'nik'
135
+ @r['fo'] = 'nak'
136
+ @r['foo'] = 'qux'
137
+ @r.keys("f*").sort.should == ['f','fo', 'foo'].sort
138
+ end
139
+ #
140
+ it "should be able to check the TYPE of a key" do
141
+ @r['foo'] = 'nik'
142
+ @r.type?('foo').should == "string"
143
+ @r.delete 'foo'
144
+ @r.type?('foo').should == "none"
145
+ end
146
+ #
147
+ it "should be able to push to the head of a list" do
148
+ @r.push_head "list", 'hello'
149
+ @r.push_head "list", 42
150
+ @r.type?('list').should == "list"
151
+ @r.list_length('list').should == 2
152
+ @r.pop_head('list').should == '42'
153
+ @r.delete('list')
154
+ end
155
+ #
156
+ it "should be able to push to the tail of a list" do
157
+ @r.push_tail "list", 'hello'
158
+ @r.type?('list').should == "list"
159
+ @r.list_length('list').should == 1
160
+ @r.delete('list')
161
+ end
162
+ #
163
+ it "should be able to pop the tail of a list" do
164
+ @r.push_tail "list", 'hello'
165
+ @r.push_tail "list", 'goodbye'
166
+ @r.type?('list').should == "list"
167
+ @r.list_length('list').should == 2
168
+ @r.pop_tail('list').should == 'goodbye'
169
+ @r.delete('list')
170
+ end
171
+ #
172
+ it "should be able to pop the head of a list" do
173
+ @r.push_tail "list", 'hello'
174
+ @r.push_tail "list", 'goodbye'
175
+ @r.type?('list').should == "list"
176
+ @r.list_length('list').should == 2
177
+ @r.pop_head('list').should == 'hello'
178
+ @r.delete('list')
179
+ end
180
+ #
181
+ it "should be able to get the length of a list" do
182
+ @r.push_tail "list", 'hello'
183
+ @r.push_tail "list", 'goodbye'
184
+ @r.type?('list').should == "list"
185
+ @r.list_length('list').should == 2
186
+ @r.delete('list')
187
+ end
188
+ #
189
+ it "should be able to get a range of values from a list" do
190
+ @r.push_tail "list", 'hello'
191
+ @r.push_tail "list", 'goodbye'
192
+ @r.push_tail "list", '1'
193
+ @r.push_tail "list", '2'
194
+ @r.push_tail "list", '3'
195
+ @r.type?('list').should == "list"
196
+ @r.list_length('list').should == 5
197
+ @r.list_range('list', 2, -1).should == ['1', '2', '3']
198
+ @r.delete('list')
199
+ end
200
+ #
201
+ it "should be able to trim a list" do
202
+ @r.push_tail "list", 'hello'
203
+ @r.push_tail "list", 'goodbye'
204
+ @r.push_tail "list", '1'
205
+ @r.push_tail "list", '2'
206
+ @r.push_tail "list", '3'
207
+ @r.type?('list').should == "list"
208
+ @r.list_length('list').should == 5
209
+ @r.list_trim 'list', 0, 1
210
+ @r.list_length('list').should == 2
211
+ @r.list_range('list', 0, -1).should == ['hello', 'goodbye']
212
+ @r.delete('list')
213
+ end
214
+ #
215
+ it "should be able to get a value by indexing into a list" do
216
+ @r.push_tail "list", 'hello'
217
+ @r.push_tail "list", 'goodbye'
218
+ @r.type?('list').should == "list"
219
+ @r.list_length('list').should == 2
220
+ @r.list_index('list', 1).should == 'goodbye'
221
+ @r.delete('list')
222
+ end
223
+ #
224
+ it "should be able to set a value by indexing into a list" do
225
+ @r.push_tail "list", 'hello'
226
+ @r.push_tail "list", 'hello'
227
+ @r.type?('list').should == "list"
228
+ @r.list_length('list').should == 2
229
+ @r.list_set('list', 1, 'goodbye').should be_true
230
+ @r.list_index('list', 1).should == 'goodbye'
231
+ @r.delete('list')
232
+ end
233
+ #
234
+ it "should be able to remove values from a list LREM" do
235
+ @r.push_tail "list", 'hello'
236
+ @r.push_tail "list", 'goodbye'
237
+ @r.type?('list').should == "list"
238
+ @r.list_length('list').should == 2
239
+ @r.list_rm('list', 1, 'hello').should == 1
240
+ @r.list_range('list', 0, -1).should == ['goodbye']
241
+ @r.delete('list')
242
+ end
243
+ #
244
+ it "should be able add members to a set" do
245
+ @r.set_add "set", 'key1'
246
+ @r.set_add "set", 'key2'
247
+ @r.type?('set').should == "set"
248
+ @r.set_count('set').should == 2
249
+ @r.set_members('set').sort.should == ['key1', 'key2'].sort
250
+ @r.delete('set')
251
+ end
252
+ #
253
+ it "should be able delete members to a set" do
254
+ @r.set_add "set", 'key1'
255
+ @r.set_add "set", 'key2'
256
+ @r.type?('set').should == "set"
257
+ @r.set_count('set').should == 2
258
+ @r.set_members('set').should == Set.new(['key1', 'key2'])
259
+ @r.set_delete('set', 'key1')
260
+ @r.set_count('set').should == 1
261
+ @r.set_members('set').should == Set.new(['key2'])
262
+ @r.delete('set')
263
+ end
264
+ #
265
+ it "should be able count the members of a set" do
266
+ @r.set_add "set", 'key1'
267
+ @r.set_add "set", 'key2'
268
+ @r.type?('set').should == "set"
269
+ @r.set_count('set').should == 2
270
+ @r.delete('set')
271
+ end
272
+ #
273
+ it "should be able test for set membership" do
274
+ @r.set_add "set", 'key1'
275
+ @r.set_add "set", 'key2'
276
+ @r.type?('set').should == "set"
277
+ @r.set_count('set').should == 2
278
+ @r.set_member?('set', 'key1').should be_true
279
+ @r.set_member?('set', 'key2').should be_true
280
+ @r.set_member?('set', 'notthere').should be_false
281
+ @r.delete('set')
282
+ end
283
+ #
284
+ it "should be able to do set intersection" do
285
+ @r.set_add "set", 'key1'
286
+ @r.set_add "set", 'key2'
287
+ @r.set_add "set2", 'key2'
288
+ @r.set_intersect('set', 'set2').should == Set.new(['key2'])
289
+ @r.delete('set')
290
+ end
291
+ #
292
+ it "should be able to do set intersection and store the results in a key" do
293
+ @r.set_add "set", 'key1'
294
+ @r.set_add "set", 'key2'
295
+ @r.set_add "set2", 'key2'
296
+ @r.set_inter_store('newone', 'set', 'set2').should == 'OK'
297
+ @r.set_members('newone').should == Set.new(['key2'])
298
+ @r.delete('set')
299
+ end
300
+ #
301
+ it "should be able to do set union" do
302
+ @r.set_add "set", 'key1'
303
+ @r.set_add "set", 'key2'
304
+ @r.set_add "set2", 'key2'
305
+ @r.set_add "set2", 'key3'
306
+ @r.set_union('set', 'set2').should == Set.new(['key1','key2','key3'])
307
+ @r.delete('set')
308
+ end
309
+ #
310
+ it "should be able to do set union and store the results in a key" do
311
+ @r.set_add "set", 'key1'
312
+ @r.set_add "set", 'key2'
313
+ @r.set_add "set2", 'key2'
314
+ @r.set_add "set2", 'key3'
315
+ @r.set_union_store('newone', 'set', 'set2').should == 'OK'
316
+ @r.set_members('newone').should == Set.new(['key1','key2','key3'])
317
+ @r.delete('set')
318
+ end
319
+
320
+ # these don't seem to be implemented in redis head?
321
+ # it "should be able to do set difference" do
322
+ # @r.set_add "set", 'key1'
323
+ # @r.set_add "set", 'key2'
324
+ # @r.set_add "set2", 'key2'
325
+ # @r.set_add "set2", 'key3'
326
+ # @r.set_diff('set', 'set2').should == Set.new(['key1','key3'])
327
+ # @r.delete('set')
328
+ # end
329
+ # #
330
+ # it "should be able to do set difference and store the results in a key" do
331
+ # @r.set_add "set", 'key1'
332
+ # @r.set_add "set", 'key2'
333
+ # @r.set_add "set2", 'key2'
334
+ # @r.set_add "set2", 'key3'
335
+ # count = @r.set_diff_store('newone', 'set', 'set2')
336
+ # count.should == 3
337
+ # @r.set_members('newone').should == Set.new(['key1','key3'])
338
+ # @r.delete('set')
339
+ # end
340
+ #
341
+ it "should be able move elements from one set to another" do
342
+ @r.set_add 'set1', 'a'
343
+ @r.set_add 'set1', 'b'
344
+ @r.set_add 'set2', 'x'
345
+ @r.set_move('set1', 'set2', 'a').should == true
346
+ @r.set_member?('set2', 'a').should == true
347
+ @r.delete('set1')
348
+ end
349
+ #
350
+ it "should be able to do crazy SORT queries" do
351
+ @r['dog_1'] = 'louie'
352
+ @r.push_tail 'dogs', 1
353
+ @r['dog_2'] = 'lucy'
354
+ @r.push_tail 'dogs', 2
355
+ @r['dog_3'] = 'max'
356
+ @r.push_tail 'dogs', 3
357
+ @r['dog_4'] = 'taj'
358
+ @r.push_tail 'dogs', 4
359
+ @r.sort('dogs', :get => 'dog_*', :limit => [0,1]).should == ['louie']
360
+ @r.sort('dogs', :get => 'dog_*', :limit => [0,1], :order => 'desc alpha').should == ['taj']
361
+ end
362
+ #
363
+ it "should provide info" do
364
+ [: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|
365
+ @r.info.keys.should include(x)
366
+ end
367
+ end
368
+ #
369
+ it "should be able to flush the database" do
370
+ @r['key1'] = 'keyone'
371
+ @r['key2'] = 'keytwo'
372
+ @r.keys('*').sort.should == ['foo', 'key1', 'key2'] #foo from before
373
+ @r.flush_db
374
+ @r.keys('*').should == []
375
+ end
376
+ #
377
+ it "should be able to provide the last save time" do
378
+ savetime = @r.last_save
379
+ Time.at(savetime).class.should == Time
380
+ Time.at(savetime).should <= Time.now
381
+ end
382
+
383
+ it "should be able to MGET keys" do
384
+ @r['foo'] = 1000
385
+ @r['bar'] = 2000
386
+ @r.mget('foo', 'bar').should == ['1000', '2000']
387
+ @r.mget('foo', 'bar', 'baz').should == ['1000', '2000', nil]
388
+ end
389
+
390
+ it "should bgsave" do
391
+ lambda {@r.bgsave}.should_not raise_error(RedisError)
392
+ end
393
+
394
+ it "should handle multiple servers" do
395
+ require 'dist_redis'
396
+ @r = DistRedis.new('localhost:6379', '127.0.0.1:6379')
397
+ @r.select_db(15) # use database 15 for testing so we dont accidentally step on you real data
398
+
399
+ 100.times do |idx|
400
+ @r[idx] = "foo#{idx}"
401
+ end
402
+
403
+ 100.times do |idx|
404
+ @r[idx].should == "foo#{idx}"
405
+ end
406
+ end
407
+
408
+ it "should be able to pipeline writes" do
409
+ @r.pipelined do |pipeline|
410
+ pipeline.push_head "list", "hello"
411
+ pipeline.push_head "list", 42
412
+ end
413
+
414
+ @r.type?('list').should == "list"
415
+ @r.list_length('list').should == 2
416
+ @r.pop_head('list').should == '42'
417
+ @r.delete('list')
418
+ end
419
+ end
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ $TESTING=true
3
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
4
+ require 'redis'
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ezmobius-redis
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3.4
5
+ platform: ruby
6
+ authors:
7
+ - Ezra Zygmuntowicz
8
+ - Taylor Weibley
9
+ - Matthew Clark
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+
14
+ date: 2009-03-31 00:00:00 -07:00
15
+ default_executable:
16
+ dependencies: []
17
+
18
+ description: Ruby client library for redis key value storage server
19
+ email: ez@engineyard.com
20
+ executables: []
21
+
22
+ extensions: []
23
+
24
+ extra_rdoc_files:
25
+ - LICENSE
26
+ files:
27
+ - LICENSE
28
+ - README.markdown
29
+ - Rakefile
30
+ - lib/redis.rb
31
+ - lib/dist_redis.rb
32
+ - lib/hash_ring.rb
33
+ - lib/pipeline.rb
34
+ - lib/server.rb
35
+ - spec/redis_spec.rb
36
+ - spec/spec_helper.rb
37
+ has_rdoc: true
38
+ homepage: http://github.com/winescout/redis-rb
39
+ post_install_message:
40
+ rdoc_options: []
41
+
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ requirements: []
57
+
58
+ rubyforge_project:
59
+ rubygems_version: 1.2.0
60
+ signing_key:
61
+ specification_version: 2
62
+ summary: Ruby client library for redis key value storage server
63
+ test_files: []
64
+