redis 0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/pipeline.rb +0 -2
- data/lib/redis.rb +25 -7
- data/spec/redis_spec.rb +113 -0
- data/tasks/redis.tasks.rb +5 -1
- metadata +2 -2
data/Rakefile
CHANGED
@@ -8,7 +8,7 @@ require 'tasks/redis.tasks'
|
|
8
8
|
|
9
9
|
GEM = 'redis'
|
10
10
|
GEM_NAME = 'redis'
|
11
|
-
GEM_VERSION = '0.1'
|
11
|
+
GEM_VERSION = '0.1.1'
|
12
12
|
AUTHORS = ['Ezra Zygmuntowicz', 'Taylor Weibley', 'Matthew Clark', 'Brian McKinney', 'Salvatore Sanfilippo', 'Luca Guidi']
|
13
13
|
EMAIL = "ez@engineyard.com"
|
14
14
|
HOMEPAGE = "http://github.com/ezmobius/redis-rb"
|
data/lib/pipeline.rb
CHANGED
data/lib/redis.rb
CHANGED
@@ -31,14 +31,18 @@ class Redis
|
|
31
31
|
"sadd" => true,
|
32
32
|
"srem" => true,
|
33
33
|
"sismember" => true,
|
34
|
+
"rpoplpush" => true,
|
34
35
|
"echo" => true,
|
35
36
|
"getset" => true,
|
36
|
-
"smove" => true
|
37
|
+
"smove" => true,
|
38
|
+
"zadd" => true,
|
39
|
+
"zrem" => true,
|
40
|
+
"zscore" => true
|
37
41
|
}
|
38
|
-
|
42
|
+
|
39
43
|
MULTI_BULK_COMMANDS = {
|
40
|
-
"mset"
|
41
|
-
"msetnx"
|
44
|
+
"mset" => true,
|
45
|
+
"msetnx" => true
|
42
46
|
}
|
43
47
|
|
44
48
|
BOOLEAN_PROCESSOR = lambda{|r| r == 1 }
|
@@ -49,6 +53,8 @@ class Redis
|
|
49
53
|
"sadd" => BOOLEAN_PROCESSOR,
|
50
54
|
"srem" => BOOLEAN_PROCESSOR,
|
51
55
|
"smove" => BOOLEAN_PROCESSOR,
|
56
|
+
"zadd" => BOOLEAN_PROCESSOR,
|
57
|
+
"zrem" => BOOLEAN_PROCESSOR,
|
52
58
|
"move" => BOOLEAN_PROCESSOR,
|
53
59
|
"setnx" => BOOLEAN_PROCESSOR,
|
54
60
|
"del" => BOOLEAN_PROCESSOR,
|
@@ -97,7 +103,14 @@ class Redis
|
|
97
103
|
"set_move" => "smove",
|
98
104
|
"set_unless_exists" => "setnx",
|
99
105
|
"rename_unless_exists" => "renamenx",
|
100
|
-
"type?" => "type"
|
106
|
+
"type?" => "type",
|
107
|
+
"zset_add" => "zadd",
|
108
|
+
"zset_count" => 'zcard',
|
109
|
+
"zset_range_by_score" => 'zrangebyscore',
|
110
|
+
"zset_reverse_range" => 'zrevrange',
|
111
|
+
"zset_range" => 'zrange',
|
112
|
+
"zset_delete" => 'zrem',
|
113
|
+
"zset_score" => 'zscore'
|
101
114
|
}
|
102
115
|
|
103
116
|
DISABLED_COMMANDS = {
|
@@ -155,8 +168,13 @@ class Redis
|
|
155
168
|
secs = Integer(timeout)
|
156
169
|
usecs = Integer((timeout - secs) * 1_000_000)
|
157
170
|
optval = [secs, usecs].pack("l_2")
|
158
|
-
|
159
|
-
|
171
|
+
begin
|
172
|
+
sock.setsockopt Socket::SOL_SOCKET, Socket::SO_RCVTIMEO, optval
|
173
|
+
sock.setsockopt Socket::SOL_SOCKET, Socket::SO_SNDTIMEO, optval
|
174
|
+
rescue Exception => ex
|
175
|
+
# Solaris, for one, does not like/support socket timeouts.
|
176
|
+
@logger.info "Unable to use raw socket timeouts: #{ex.class.name}: #{ex.message}" if @logger
|
177
|
+
end
|
160
178
|
end
|
161
179
|
sock
|
162
180
|
end
|
data/spec/redis_spec.rb
CHANGED
@@ -275,6 +275,22 @@ describe "redis" do
|
|
275
275
|
@r.lrem('list', 1, 'hello').should == 1
|
276
276
|
@r.lrange('list', 0, -1).should == ['goodbye']
|
277
277
|
end
|
278
|
+
|
279
|
+
it "should be able to pop values from a list and push them onto a temp list(RPOPLPUSH)" do
|
280
|
+
@r.rpush "list", 'one'
|
281
|
+
@r.rpush "list", 'two'
|
282
|
+
@r.rpush "list", 'three'
|
283
|
+
@r.type('list').should == "list"
|
284
|
+
@r.llen('list').should == 3
|
285
|
+
@r.lrange('list',0,-1).should == ['one', 'two', 'three']
|
286
|
+
@r.lrange('tmp',0,-1).should == []
|
287
|
+
@r.rpoplpush('list', 'tmp').should == 'three'
|
288
|
+
@r.lrange('tmp',0,-1).should == ['three']
|
289
|
+
@r.rpoplpush('list', 'tmp').should == 'two'
|
290
|
+
@r.lrange('tmp',0,-1).should == ['two', 'three']
|
291
|
+
@r.rpoplpush('list', 'tmp').should == 'one'
|
292
|
+
@r.lrange('tmp',0,-1).should == ['one','two','three']
|
293
|
+
end
|
278
294
|
#
|
279
295
|
it "should be able add members to a set (SADD)" do
|
280
296
|
@r.sadd "set", 'key1'
|
@@ -415,6 +431,103 @@ describe "redis" do
|
|
415
431
|
@r.sort('dogs', :get => ['dog:*:name', 'dog:*:breed'], :limit => [0,1], :order => 'desc alpha').should == ['taj', 'terrier']
|
416
432
|
end
|
417
433
|
#
|
434
|
+
it "should be able count the members of a zset" do
|
435
|
+
@r.set_add "set", 'key1'
|
436
|
+
@r.set_add "set", 'key2'
|
437
|
+
@r.zset_add 'zset', 1, 'set'
|
438
|
+
@r.zset_count('zset').should == 1
|
439
|
+
@r.delete('set')
|
440
|
+
@r.delete('zset')
|
441
|
+
end
|
442
|
+
#
|
443
|
+
it "should be able add members to a zset" do
|
444
|
+
@r.set_add "set", 'key1'
|
445
|
+
@r.set_add "set", 'key2'
|
446
|
+
@r.zset_add 'zset', 1, 'set'
|
447
|
+
@r.zset_range('zset', 0, 1).should == ['set']
|
448
|
+
@r.zset_count('zset').should == 1
|
449
|
+
@r.delete('set')
|
450
|
+
@r.delete('zset')
|
451
|
+
end
|
452
|
+
#
|
453
|
+
it "should be able delete members to a zset" do
|
454
|
+
@r.set_add "set", 'key1'
|
455
|
+
@r.set_add "set", 'key2'
|
456
|
+
@r.type?('set').should == "set"
|
457
|
+
@r.set_add "set2", 'key3'
|
458
|
+
@r.set_add "set2", 'key4'
|
459
|
+
@r.type?('set2').should == "set"
|
460
|
+
@r.zset_add 'zset', 1, 'set'
|
461
|
+
@r.zset_count('zset').should == 1
|
462
|
+
@r.zset_add 'zset', 2, 'set2'
|
463
|
+
@r.zset_count('zset').should == 2
|
464
|
+
@r.zset_delete 'zset', 'set'
|
465
|
+
@r.zset_count('zset').should == 1
|
466
|
+
@r.delete('set')
|
467
|
+
@r.delete('set2')
|
468
|
+
@r.delete('zset')
|
469
|
+
end
|
470
|
+
#
|
471
|
+
it "should be able to get a range of values from a zset" do
|
472
|
+
@r.set_add "set", 'key1'
|
473
|
+
@r.set_add "set", 'key2'
|
474
|
+
@r.set_add "set2", 'key3'
|
475
|
+
@r.set_add "set2", 'key4'
|
476
|
+
@r.set_add "set3", 'key1'
|
477
|
+
@r.type?('set').should == 'set'
|
478
|
+
@r.type?('set2').should == 'set'
|
479
|
+
@r.type?('set3').should == 'set'
|
480
|
+
@r.zset_add 'zset', 1, 'set'
|
481
|
+
@r.zset_add 'zset', 2, 'set2'
|
482
|
+
@r.zset_add 'zset', 3, 'set3'
|
483
|
+
@r.zset_count('zset').should == 3
|
484
|
+
@r.zset_range('zset', 0, 3).should == ['set', 'set2', 'set3']
|
485
|
+
@r.delete('set')
|
486
|
+
@r.delete('set2')
|
487
|
+
@r.delete('set3')
|
488
|
+
@r.delete('zset')
|
489
|
+
end
|
490
|
+
#
|
491
|
+
it "should be able to get a reverse range of values from a zset" do
|
492
|
+
@r.set_add "set", 'key1'
|
493
|
+
@r.set_add "set", 'key2'
|
494
|
+
@r.set_add "set2", 'key3'
|
495
|
+
@r.set_add "set2", 'key4'
|
496
|
+
@r.set_add "set3", 'key1'
|
497
|
+
@r.type?('set').should == 'set'
|
498
|
+
@r.type?('set2').should == 'set'
|
499
|
+
@r.type?('set3').should == 'set'
|
500
|
+
@r.zset_add 'zset', 1, 'set'
|
501
|
+
@r.zset_add 'zset', 2, 'set2'
|
502
|
+
@r.zset_add 'zset', 3, 'set3'
|
503
|
+
@r.zset_count('zset').should == 3
|
504
|
+
@r.zset_reverse_range('zset', 0, 3).should == ['set3', 'set2', 'set']
|
505
|
+
@r.delete('set')
|
506
|
+
@r.delete('set2')
|
507
|
+
@r.delete('set3')
|
508
|
+
@r.delete('zset')
|
509
|
+
end
|
510
|
+
#
|
511
|
+
it "should be able to get a range by score of values from a zset" do
|
512
|
+
@r.set_add "set", 'key1'
|
513
|
+
@r.set_add "set", 'key2'
|
514
|
+
@r.set_add "set2", 'key3'
|
515
|
+
@r.set_add "set2", 'key4'
|
516
|
+
@r.set_add "set3", 'key1'
|
517
|
+
@r.set_add "set4", 'key4'
|
518
|
+
@r.zset_add 'zset', 1, 'set'
|
519
|
+
@r.zset_add 'zset', 2, 'set2'
|
520
|
+
@r.zset_add 'zset', 3, 'set3'
|
521
|
+
@r.zset_add 'zset', 4, 'set4'
|
522
|
+
@r.zset_count('zset').should == 4
|
523
|
+
@r.zset_range_by_score('zset', 2, 3).should == ['set2', 'set3']
|
524
|
+
@r.delete('set')
|
525
|
+
@r.delete('set2')
|
526
|
+
@r.delete('set3')
|
527
|
+
@r.delete('set4')
|
528
|
+
@r.delete('zset')
|
529
|
+
end
|
530
|
+
|
418
531
|
it "should provide info (INFO)" do
|
419
532
|
[: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|
|
420
533
|
@r.info.keys.should include(x)
|
data/tasks/redis.tasks.rb
CHANGED
@@ -93,7 +93,11 @@ namespace :redis do
|
|
93
93
|
task :download do
|
94
94
|
sh 'rm -rf /tmp/redis/' if File.exists?("#{RedisRunner.redisdir}/.svn")
|
95
95
|
sh 'git clone git://github.com/antirez/redis.git /tmp/redis' unless File.exists?(RedisRunner.redisdir)
|
96
|
-
|
96
|
+
|
97
|
+
if File.exists?("#{RedisRunner.redisdir}/.git")
|
98
|
+
arguments = ENV['COMMIT'].nil? ? "pull" : "reset --hard #{ENV['COMMIT']}"
|
99
|
+
sh "cd #{RedisRunner.redisdir} && git #{arguments}"
|
100
|
+
end
|
97
101
|
end
|
98
102
|
|
99
103
|
desc "Open an IRb session"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ezra Zygmuntowicz
|
@@ -14,7 +14,7 @@ autorequire: redis
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2009-
|
17
|
+
date: 2009-12-03 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|