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
@@ -0,0 +1,180 @@
|
|
1
|
+
!RBIX
|
2
|
+
6235178746665710376
|
3
|
+
x
|
4
|
+
M
|
5
|
+
1
|
6
|
+
n
|
7
|
+
n
|
8
|
+
x
|
9
|
+
10
|
10
|
+
__script__
|
11
|
+
i
|
12
|
+
54
|
13
|
+
5
|
14
|
+
45
|
15
|
+
0
|
16
|
+
1
|
17
|
+
7
|
18
|
+
2
|
19
|
+
64
|
20
|
+
45
|
21
|
+
0
|
22
|
+
3
|
23
|
+
65
|
24
|
+
49
|
25
|
+
4
|
26
|
+
0
|
27
|
+
49
|
28
|
+
5
|
29
|
+
1
|
30
|
+
49
|
31
|
+
6
|
32
|
+
2
|
33
|
+
47
|
34
|
+
49
|
35
|
+
7
|
36
|
+
1
|
37
|
+
15
|
38
|
+
99
|
39
|
+
7
|
40
|
+
8
|
41
|
+
1
|
42
|
+
65
|
43
|
+
49
|
44
|
+
9
|
45
|
+
3
|
46
|
+
13
|
47
|
+
99
|
48
|
+
12
|
49
|
+
7
|
50
|
+
10
|
51
|
+
12
|
52
|
+
7
|
53
|
+
11
|
54
|
+
12
|
55
|
+
65
|
56
|
+
12
|
57
|
+
49
|
58
|
+
12
|
59
|
+
4
|
60
|
+
15
|
61
|
+
49
|
62
|
+
10
|
63
|
+
0
|
64
|
+
15
|
65
|
+
2
|
66
|
+
11
|
67
|
+
I
|
68
|
+
6
|
69
|
+
I
|
70
|
+
0
|
71
|
+
I
|
72
|
+
0
|
73
|
+
I
|
74
|
+
0
|
75
|
+
n
|
76
|
+
p
|
77
|
+
13
|
78
|
+
x
|
79
|
+
4
|
80
|
+
File
|
81
|
+
n
|
82
|
+
s
|
83
|
+
8
|
84
|
+
../redis
|
85
|
+
n
|
86
|
+
x
|
87
|
+
11
|
88
|
+
active_path
|
89
|
+
x
|
90
|
+
7
|
91
|
+
dirname
|
92
|
+
x
|
93
|
+
11
|
94
|
+
expand_path
|
95
|
+
x
|
96
|
+
7
|
97
|
+
require
|
98
|
+
x
|
99
|
+
5
|
100
|
+
Redis
|
101
|
+
x
|
102
|
+
10
|
103
|
+
open_class
|
104
|
+
x
|
105
|
+
14
|
106
|
+
__class_init__
|
107
|
+
M
|
108
|
+
1
|
109
|
+
n
|
110
|
+
n
|
111
|
+
x
|
112
|
+
5
|
113
|
+
Redis
|
114
|
+
i
|
115
|
+
12
|
116
|
+
5
|
117
|
+
66
|
118
|
+
65
|
119
|
+
7
|
120
|
+
0
|
121
|
+
7
|
122
|
+
1
|
123
|
+
64
|
124
|
+
49
|
125
|
+
2
|
126
|
+
2
|
127
|
+
11
|
128
|
+
I
|
129
|
+
3
|
130
|
+
I
|
131
|
+
0
|
132
|
+
I
|
133
|
+
0
|
134
|
+
I
|
135
|
+
0
|
136
|
+
n
|
137
|
+
p
|
138
|
+
3
|
139
|
+
x
|
140
|
+
7
|
141
|
+
VERSION
|
142
|
+
s
|
143
|
+
9
|
144
|
+
0.0.1.dev
|
145
|
+
x
|
146
|
+
9
|
147
|
+
const_set
|
148
|
+
p
|
149
|
+
3
|
150
|
+
I
|
151
|
+
2
|
152
|
+
I
|
153
|
+
5
|
154
|
+
I
|
155
|
+
c
|
156
|
+
x
|
157
|
+
53
|
158
|
+
/Users/dturnbull/ruby/ruby-redis/lib/redis/version.rb
|
159
|
+
p
|
160
|
+
0
|
161
|
+
x
|
162
|
+
13
|
163
|
+
attach_method
|
164
|
+
p
|
165
|
+
5
|
166
|
+
I
|
167
|
+
0
|
168
|
+
I
|
169
|
+
1
|
170
|
+
I
|
171
|
+
19
|
172
|
+
I
|
173
|
+
3
|
174
|
+
I
|
175
|
+
36
|
176
|
+
x
|
177
|
+
53
|
178
|
+
/Users/dturnbull/ruby/ruby-redis/lib/redis/version.rb
|
179
|
+
p
|
180
|
+
0
|
data/lib/redis/zsets.rb
ADDED
@@ -0,0 +1,281 @@
|
|
1
|
+
require File.expand_path '../redis', File.dirname(__FILE__)
|
2
|
+
|
3
|
+
class Redis
|
4
|
+
|
5
|
+
#WARN Time complexity may not match C version in this module yet.
|
6
|
+
#TODO Should add and delete manipulate @keys instead of clearing?
|
7
|
+
|
8
|
+
class ZSet
|
9
|
+
include Enumerable
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@hash = Hash.new
|
13
|
+
@keys = nil
|
14
|
+
@keys_reverse = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def add(o, s = 0.0)
|
18
|
+
@hash[o] = s
|
19
|
+
@keys = nil
|
20
|
+
@keys_reverse = nil
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete(o)
|
25
|
+
@keys = nil
|
26
|
+
@keys_reverse = nil
|
27
|
+
@hash.delete(o)
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
def include?(o)
|
32
|
+
@hash.include?(o)
|
33
|
+
end
|
34
|
+
|
35
|
+
def score(o)
|
36
|
+
@hash[o]
|
37
|
+
end
|
38
|
+
|
39
|
+
def size
|
40
|
+
@hash.size
|
41
|
+
end
|
42
|
+
|
43
|
+
def empty?
|
44
|
+
@hash.empty?
|
45
|
+
end
|
46
|
+
|
47
|
+
def each
|
48
|
+
block_given? or return enum_for(__method__)
|
49
|
+
to_a.each { |o| yield(o) }
|
50
|
+
self
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_a
|
54
|
+
unless @keys
|
55
|
+
(@keys = @hash.to_a).sort! do |a, b|
|
56
|
+
a.reverse <=> b.reverse
|
57
|
+
end
|
58
|
+
end
|
59
|
+
@keys
|
60
|
+
end
|
61
|
+
|
62
|
+
def to_a_reverse
|
63
|
+
unless @keys_reverse
|
64
|
+
@keys_reverse = to_a.reverse
|
65
|
+
end
|
66
|
+
@keys_reverse
|
67
|
+
end
|
68
|
+
|
69
|
+
def range reverse, start ,stop, conversions, withscores = false
|
70
|
+
start = conversions.redis_i start
|
71
|
+
stop = conversions.redis_i stop
|
72
|
+
array = reverse ? to_a_reverse : to_a
|
73
|
+
start = 0 if start < -size
|
74
|
+
return array[start..stop].flatten(1) if withscores
|
75
|
+
(array[start..stop]||[]).collect{|i|i.first}
|
76
|
+
end
|
77
|
+
|
78
|
+
def range_by_score reverse, min, max, conversions, *args
|
79
|
+
withscores = offset = count = nil
|
80
|
+
until args.empty?
|
81
|
+
case args.shift.upcase
|
82
|
+
when 'LIMIT'
|
83
|
+
offset = args.shift.to_i
|
84
|
+
count = args.shift.to_i
|
85
|
+
when 'WITHSCORES'
|
86
|
+
withscores = true
|
87
|
+
else
|
88
|
+
raise 'bad arguments'
|
89
|
+
end
|
90
|
+
end
|
91
|
+
result = []
|
92
|
+
min_exclusive = false
|
93
|
+
if min[0..0] == '('
|
94
|
+
min_exclusive = true
|
95
|
+
min = min[1..-1]
|
96
|
+
end
|
97
|
+
min = conversions.redis_f min
|
98
|
+
max_exclusive = false
|
99
|
+
if max[0..0] == '('
|
100
|
+
max_exclusive = true
|
101
|
+
max = max[1..-1]
|
102
|
+
end
|
103
|
+
max = conversions.redis_f max
|
104
|
+
if reverse
|
105
|
+
x = min; min = max; max = x
|
106
|
+
end
|
107
|
+
(reverse ? to_a_reverse : to_a).each do |member, score|
|
108
|
+
next if min > score or (min_exclusive and min >= score)
|
109
|
+
next if max < score or (max_exclusive and max <= score)
|
110
|
+
if offset
|
111
|
+
offset -= 1
|
112
|
+
next unless offset < 0
|
113
|
+
offset = nil
|
114
|
+
end
|
115
|
+
result << member
|
116
|
+
result << score if withscores
|
117
|
+
if count
|
118
|
+
count -= 1
|
119
|
+
break if count == 0
|
120
|
+
end
|
121
|
+
end
|
122
|
+
result
|
123
|
+
end
|
124
|
+
|
125
|
+
def self.aggregate database, is_and, destination, numkeys, conversions, *args
|
126
|
+
numkeys = numkeys.to_i
|
127
|
+
aggregate = 'SUM'
|
128
|
+
keys = []
|
129
|
+
keys << args.shift while (numkeys -= 1) >= 0
|
130
|
+
weights = Array.new keys.size, 1
|
131
|
+
until args.empty?
|
132
|
+
case args.shift.upcase
|
133
|
+
when 'WEIGHTS'
|
134
|
+
weights = []
|
135
|
+
keys.size.times {weights << conversions.redis_f(args.shift, 'weight value is not a double')}
|
136
|
+
when 'AGGREGATE'
|
137
|
+
aggregate = args.shift.upcase
|
138
|
+
else
|
139
|
+
raise 'bad arguments'
|
140
|
+
end
|
141
|
+
end
|
142
|
+
results = []
|
143
|
+
keys.zip(weights) do |key, weight|
|
144
|
+
inner_result = ZSet.new
|
145
|
+
record = database[key] || ZSet.new
|
146
|
+
record.each do |member, score|
|
147
|
+
inner_result.add member, (score||1) * weight
|
148
|
+
end
|
149
|
+
results << inner_result
|
150
|
+
end
|
151
|
+
result = results.reduce do |memo, result|
|
152
|
+
n = is_and ? new : memo
|
153
|
+
result.each do |member, score|
|
154
|
+
next if is_and and !memo.include?(member)
|
155
|
+
test = [score, memo.score(member)].compact
|
156
|
+
text << 0 if test.empty?
|
157
|
+
case aggregate
|
158
|
+
when 'SUM'
|
159
|
+
score = test.reduce :+
|
160
|
+
when 'MIN'
|
161
|
+
score = test.min
|
162
|
+
when 'MAX'
|
163
|
+
score = test.max
|
164
|
+
else
|
165
|
+
raise 'bad arguments'
|
166
|
+
end
|
167
|
+
n.add member, score
|
168
|
+
end
|
169
|
+
n
|
170
|
+
end
|
171
|
+
database[destination] = result unless result.empty?
|
172
|
+
result.size
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
module ZSets
|
178
|
+
|
179
|
+
def redis_ZADD key, score, member
|
180
|
+
record = (@database[key] ||= ZSet.new)
|
181
|
+
result = !record.include?(member)
|
182
|
+
record.add member, redis_f(score)
|
183
|
+
result
|
184
|
+
end
|
185
|
+
|
186
|
+
def redis_ZINCRBY key, increment, member
|
187
|
+
record = (@database[key] ||= ZSet.new)
|
188
|
+
increment = redis_f increment
|
189
|
+
if record.include?(member)
|
190
|
+
score = record.score(member) + increment
|
191
|
+
else
|
192
|
+
score = increment
|
193
|
+
end
|
194
|
+
raise 'NaN' if score.nan?
|
195
|
+
record.add member, score
|
196
|
+
score
|
197
|
+
end
|
198
|
+
|
199
|
+
def redis_ZRANK key, member
|
200
|
+
record = (@database[key] || ZSet.new).to_a
|
201
|
+
record.index {|i| i[0]==member}
|
202
|
+
end
|
203
|
+
|
204
|
+
def redis_ZREM key, member
|
205
|
+
record = @database[key] || []
|
206
|
+
return false unless record.include? member
|
207
|
+
record.delete member
|
208
|
+
@database.delete key if record.empty?
|
209
|
+
return true
|
210
|
+
end
|
211
|
+
|
212
|
+
def redis_ZSCORE key, member
|
213
|
+
(@database[key] || ZSet.new).score member
|
214
|
+
end
|
215
|
+
|
216
|
+
def redis_ZREVRANK key, member
|
217
|
+
record = (@database[key] || ZSet.new).to_a_reverse
|
218
|
+
record.index {|i| i[0]==member}
|
219
|
+
end
|
220
|
+
|
221
|
+
def redis_ZCARD key
|
222
|
+
(@database[key] || []).size
|
223
|
+
end
|
224
|
+
|
225
|
+
def redis_ZREMRANGEBYSCORE key, min, max
|
226
|
+
record = @database[key] || ZSet.new
|
227
|
+
range = record.range_by_score(false, min, max, self)
|
228
|
+
range.each do |member, score|
|
229
|
+
record.delete member
|
230
|
+
end
|
231
|
+
range.size
|
232
|
+
end
|
233
|
+
|
234
|
+
def redis_ZCOUNT key, min, max
|
235
|
+
record = @database[key] || ZSet.new
|
236
|
+
record.range_by_score(false, min, max, self).size
|
237
|
+
end
|
238
|
+
|
239
|
+
def redis_ZREVRANGEBYSCORE key, min, max, *args
|
240
|
+
record = @database[key] || ZSet.new
|
241
|
+
record.range_by_score true, min, max, self, *args
|
242
|
+
end
|
243
|
+
|
244
|
+
def redis_ZRANGEBYSCORE key, min, max, *args
|
245
|
+
record = @database[key] || ZSet.new
|
246
|
+
record.range_by_score false, min, max, self, *args
|
247
|
+
end
|
248
|
+
|
249
|
+
def redis_ZRANGE key, start ,stop, withscores = false
|
250
|
+
record = @database[key] || ZSet.new
|
251
|
+
start = redis_i start
|
252
|
+
stop = redis_i stop
|
253
|
+
record.range false, start, stop, self, withscores
|
254
|
+
end
|
255
|
+
|
256
|
+
def redis_ZREVRANGE key, start ,stop, withscores = false
|
257
|
+
record = @database[key] || ZSet.new
|
258
|
+
start = redis_i start
|
259
|
+
stop = redis_i stop
|
260
|
+
record.range true, start, stop, self, withscores
|
261
|
+
end
|
262
|
+
|
263
|
+
def redis_ZREMRANGEBYRANK key, start, stop
|
264
|
+
record = @database[key] || ZSet.new
|
265
|
+
range = record.range false, start, stop, self
|
266
|
+
range.each do |member, score|
|
267
|
+
record.delete member
|
268
|
+
end
|
269
|
+
range.size
|
270
|
+
end
|
271
|
+
|
272
|
+
def redis_ZUNIONSTORE destination, numkeys, *args
|
273
|
+
ZSet.aggregate @database, false, destination, numkeys, self, *args
|
274
|
+
end
|
275
|
+
|
276
|
+
def redis_ZINTERSTORE destination, numkeys, *args
|
277
|
+
ZSet.aggregate @database, true, destination, numkeys, self, *args
|
278
|
+
end
|
279
|
+
|
280
|
+
end
|
281
|
+
end
|