ruby-redis 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +9 -0
- data/README +90 -0
- data/bin/ruby-redis +12 -0
- data/bin/ruby-redis.compiled.rbc +243 -0
- data/lib/redis/bin.rb +74 -0
- data/lib/redis/bin.rbc +1325 -0
- data/lib/redis/buftok.rbc +2658 -0
- data/lib/redis/config.rb +46 -0
- data/lib/redis/config.rbc +1009 -0
- data/lib/redis/connection.rb +69 -0
- data/lib/redis/connection.rbc +1354 -0
- data/lib/redis/database.rb +109 -0
- data/lib/redis/database.rbc +2275 -0
- data/lib/redis/hashes.rb +72 -0
- data/lib/redis/hashes.rbc +1843 -0
- data/lib/redis/hiredis.rbc +658 -0
- data/lib/redis/keys.rb +165 -0
- data/lib/redis/keys.rbc +3386 -0
- data/lib/redis/lists.rb +227 -0
- data/lib/redis/lists.rbc +5241 -0
- data/lib/redis/logger.rb +81 -0
- data/lib/redis/logger.rbc +2106 -0
- data/lib/redis/protocol.rb +170 -0
- data/lib/redis/protocol.rbc +3735 -0
- data/lib/redis/pubsub.rb +153 -0
- data/lib/redis/pubsub.rbc +3447 -0
- data/lib/redis/reader.rb +164 -0
- data/lib/redis/reader.rbc +2769 -0
- data/lib/redis/send.rbc +1268 -0
- data/lib/redis/sender.rb +49 -0
- data/lib/redis/sender.rbc +1057 -0
- data/lib/redis/server.rb +62 -0
- data/lib/redis/server.rbc +1177 -0
- data/lib/redis/sets.rb +105 -0
- data/lib/redis/sets.rbc +2800 -0
- data/lib/redis/strict.rb +67 -0
- data/lib/redis/strict.rbc +1419 -0
- data/lib/redis/strings.rb +144 -0
- data/lib/redis/strings.rbc +3338 -0
- data/lib/redis/synchrony.rb +58 -0
- data/lib/redis/synchrony.rbc +1397 -0
- data/lib/redis/version.rb +7 -0
- data/lib/redis/version.rbc +180 -0
- data/lib/redis/zsets.rb +281 -0
- data/lib/redis/zsets.rbc +6596 -0
- data/lib/redis.rb +215 -0
- data/lib/redis.rbc +4391 -0
- metadata +117 -0
data/lib/redis/sets.rb
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
require File.expand_path '../redis', File.dirname(__FILE__)
|
2
|
+
require 'set'
|
3
|
+
|
4
|
+
class Redis
|
5
|
+
module Sets
|
6
|
+
|
7
|
+
def redis_SADD key, member
|
8
|
+
record = (@database[key] ||= Set.new)
|
9
|
+
redis_t Set, record
|
10
|
+
return false if record.include? member
|
11
|
+
record.add member
|
12
|
+
true
|
13
|
+
end
|
14
|
+
|
15
|
+
def redis_SREM key, member
|
16
|
+
record = @database[key] || []
|
17
|
+
return false unless record.include? member
|
18
|
+
record.delete member
|
19
|
+
@database.delete key if record.empty?
|
20
|
+
return true
|
21
|
+
end
|
22
|
+
|
23
|
+
# Type checks are only to make tests pass
|
24
|
+
def redis_SMOVE source, destination, member
|
25
|
+
source_record = @database[source] || Set.new
|
26
|
+
dest_record = @database[destination]
|
27
|
+
redis_t Set, source_record
|
28
|
+
redis_t NilClass, Set, dest_record
|
29
|
+
return false unless source_record.include? member
|
30
|
+
(@database[destination] ||= Set.new).add member
|
31
|
+
source_record.delete member
|
32
|
+
@database.delete source if source_record.empty?
|
33
|
+
return true
|
34
|
+
end
|
35
|
+
|
36
|
+
def redis_SCARD key
|
37
|
+
(@database[key] || []).size
|
38
|
+
end
|
39
|
+
|
40
|
+
def redis_SISMEMBER key, member
|
41
|
+
(@database[key] || []).include? member
|
42
|
+
end
|
43
|
+
|
44
|
+
def redis_SMEMBERS key
|
45
|
+
(@database[key] || []).to_a
|
46
|
+
end
|
47
|
+
|
48
|
+
def redis_SINTER *keys
|
49
|
+
keys.each { |key| redis_t NilClass, Array, Set, @database[key] }
|
50
|
+
keys.reduce(nil) do |memo, key|
|
51
|
+
memo ? memo & (@database[key]||[]) : (@database[key]||Set.new)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def redis_SINTERSTORE destination, *keys
|
56
|
+
record = redis_SINTER *keys
|
57
|
+
if record.empty?
|
58
|
+
@database.delete destination
|
59
|
+
else
|
60
|
+
@database[destination] = record
|
61
|
+
end
|
62
|
+
record.size
|
63
|
+
end
|
64
|
+
|
65
|
+
def redis_SUNION *keys
|
66
|
+
keys.each { |key| redis_t NilClass, Array, Set, @database[key] }
|
67
|
+
keys.reduce(Set.new) { |memo, key| memo | (@database[key]||[]) }
|
68
|
+
end
|
69
|
+
|
70
|
+
def redis_SUNIONSTORE destination, *keys
|
71
|
+
record = redis_SUNION *keys
|
72
|
+
if record.empty?
|
73
|
+
@database.delete destination
|
74
|
+
else
|
75
|
+
@database[destination] = record
|
76
|
+
end
|
77
|
+
record.size
|
78
|
+
end
|
79
|
+
|
80
|
+
def redis_SDIFF *keys
|
81
|
+
keys.reduce(nil) { |memo, key| memo ? memo - (@database[key]||[]) : (@database[key]||Set.new) }
|
82
|
+
end
|
83
|
+
|
84
|
+
def redis_SDIFFSTORE destination, *keys
|
85
|
+
(@database[destination] = redis_SDIFF *keys).size
|
86
|
+
end
|
87
|
+
|
88
|
+
def redis_SPOP key
|
89
|
+
set = @database[key]
|
90
|
+
return nil unless set
|
91
|
+
rec = rand set.size
|
92
|
+
result = set.to_a[rec]
|
93
|
+
set.delete result
|
94
|
+
@database.delete key if set.empty?
|
95
|
+
result
|
96
|
+
end
|
97
|
+
|
98
|
+
def redis_SRANDMEMBER key
|
99
|
+
set = (@database[key] || [])
|
100
|
+
return nil if set.empty?
|
101
|
+
set.to_a[rand set.size]
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
end
|