lunar 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/examples/ohm.rb +23 -0
- data/lib/lunar.rb +12 -0
- data/lib/lunar/doc.rb +13 -0
- data/lib/lunar/index.rb +70 -0
- data/lib/lunar/scoring.rb +11 -0
- data/test/helper.rb +13 -0
- data/test/test_lunar.rb +4 -0
- data/test/test_lunar_document.rb +20 -0
- data/test/test_lunar_index.rb +174 -0
- data/test/test_lunar_scoring.rb +26 -0
- data/vendor/nest/nest.rb +7 -0
- data/vendor/redis/.gitignore +9 -0
- data/vendor/redis/LICENSE +20 -0
- data/vendor/redis/README.markdown +120 -0
- data/vendor/redis/Rakefile +75 -0
- data/vendor/redis/benchmarking/logging.rb +62 -0
- data/vendor/redis/benchmarking/pipeline.rb +44 -0
- data/vendor/redis/benchmarking/speed.rb +21 -0
- data/vendor/redis/benchmarking/suite.rb +24 -0
- data/vendor/redis/benchmarking/worker.rb +71 -0
- data/vendor/redis/bin/distredis +33 -0
- data/vendor/redis/examples/basic.rb +15 -0
- data/vendor/redis/examples/dist_redis.rb +43 -0
- data/vendor/redis/examples/incr-decr.rb +17 -0
- data/vendor/redis/examples/list.rb +26 -0
- data/vendor/redis/examples/pubsub.rb +25 -0
- data/vendor/redis/examples/sets.rb +36 -0
- data/vendor/redis/lib/edis.rb +3 -0
- data/vendor/redis/lib/redis.rb +496 -0
- data/vendor/redis/lib/redis/client.rb +265 -0
- data/vendor/redis/lib/redis/dist_redis.rb +118 -0
- data/vendor/redis/lib/redis/distributed.rb +460 -0
- data/vendor/redis/lib/redis/hash_ring.rb +131 -0
- data/vendor/redis/lib/redis/pipeline.rb +13 -0
- data/vendor/redis/lib/redis/raketasks.rb +1 -0
- data/vendor/redis/lib/redis/subscribe.rb +79 -0
- data/vendor/redis/profile.rb +22 -0
- data/vendor/redis/tasks/redis.tasks.rb +140 -0
- data/vendor/redis/test/db/.gitignore +1 -0
- data/vendor/redis/test/distributed_test.rb +1131 -0
- data/vendor/redis/test/redis_test.rb +1134 -0
- data/vendor/redis/test/test.conf +8 -0
- data/vendor/redis/test/test_helper.rb +113 -0
- metadata +127 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
class RedisCluster
|
4
|
+
|
5
|
+
def initialize(opts={})
|
6
|
+
opts = {:port => 6379, :host => 'localhost', :basedir => "#{Dir.pwd}/rdsrv" }.merge(opts)
|
7
|
+
FileUtils.mkdir_p opts[:basedir]
|
8
|
+
opts[:size].times do |i|
|
9
|
+
port = opts[:port] + i
|
10
|
+
FileUtils.mkdir_p "#{opts[:basedir]}/#{port}"
|
11
|
+
File.open("#{opts[:basedir]}/#{port}.conf", 'w'){|f| f.write(make_config(port, "#{opts[:basedir]}/#{port}", "#{opts[:basedir]}/#{port}.log"))}
|
12
|
+
system(%Q{#{File.join(File.expand_path(File.dirname(__FILE__)), "../redis/redis-server #{opts[:basedir]}/#{port}.conf &" )}})
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def make_config(port=6379, data=port, logfile='stdout', loglevel='debug')
|
17
|
+
config = %Q{
|
18
|
+
timeout 300
|
19
|
+
save 900 1
|
20
|
+
save 300 10
|
21
|
+
save 60 10000
|
22
|
+
dir #{data}
|
23
|
+
loglevel #{loglevel}
|
24
|
+
logfile #{logfile}
|
25
|
+
databases 16
|
26
|
+
port #{port}
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
RedisCluster.new :size => 4
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "redis"
|
2
|
+
require "redis/distributed"
|
3
|
+
|
4
|
+
r = Redis::Distributed.new %w[redis://localhost:6379 redis://localhost:6380 redis://localhost:6381 redis://localhost:6382]
|
5
|
+
|
6
|
+
r.flushdb
|
7
|
+
|
8
|
+
r['urmom'] = 'urmom'
|
9
|
+
r['urdad'] = 'urdad'
|
10
|
+
r['urmom1'] = 'urmom1'
|
11
|
+
r['urdad1'] = 'urdad1'
|
12
|
+
r['urmom2'] = 'urmom2'
|
13
|
+
r['urdad2'] = 'urdad2'
|
14
|
+
r['urmom3'] = 'urmom3'
|
15
|
+
r['urdad3'] = 'urdad3'
|
16
|
+
p r['urmom']
|
17
|
+
p r['urdad']
|
18
|
+
p r['urmom1']
|
19
|
+
p r['urdad1']
|
20
|
+
p r['urmom2']
|
21
|
+
p r['urdad2']
|
22
|
+
p r['urmom3']
|
23
|
+
p r['urdad3']
|
24
|
+
|
25
|
+
r.rpush 'listor', 'foo1'
|
26
|
+
r.rpush 'listor', 'foo2'
|
27
|
+
r.rpush 'listor', 'foo3'
|
28
|
+
r.rpush 'listor', 'foo4'
|
29
|
+
r.rpush 'listor', 'foo5'
|
30
|
+
|
31
|
+
p r.rpop('listor')
|
32
|
+
p r.rpop('listor')
|
33
|
+
p r.rpop('listor')
|
34
|
+
p r.rpop('listor')
|
35
|
+
p r.rpop('listor')
|
36
|
+
|
37
|
+
puts "key distribution:"
|
38
|
+
|
39
|
+
r.ring.nodes.each do |node|
|
40
|
+
p [node.client, node.keys("*")]
|
41
|
+
end
|
42
|
+
r.flushdb
|
43
|
+
p r.keys('*')
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'redis'
|
3
|
+
|
4
|
+
r = Redis.new
|
5
|
+
|
6
|
+
r.del 'logs'
|
7
|
+
|
8
|
+
puts
|
9
|
+
|
10
|
+
p "pushing log messages into a LIST"
|
11
|
+
r.rpush 'logs', 'some log message'
|
12
|
+
r.rpush 'logs', 'another log message'
|
13
|
+
r.rpush 'logs', 'yet another log message'
|
14
|
+
r.rpush 'logs', 'also another log message'
|
15
|
+
|
16
|
+
puts
|
17
|
+
p 'contents of logs LIST'
|
18
|
+
|
19
|
+
p r.lrange('logs', 0, -1)
|
20
|
+
|
21
|
+
puts
|
22
|
+
p 'Trim logs LIST to last 2 elements(easy circular buffer)'
|
23
|
+
|
24
|
+
r.ltrim('logs', -2, -1)
|
25
|
+
|
26
|
+
p r.lrange('logs', 0, -1)
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'redis'
|
3
|
+
|
4
|
+
puts "To play with this example use redis-cli from another terminal, like this:"
|
5
|
+
puts " ./redis-cli publish one hello"
|
6
|
+
puts "Finally force the example to exit sending the 'exit' message with"
|
7
|
+
puts " ./redis-cli publish two exit"
|
8
|
+
puts ""
|
9
|
+
|
10
|
+
@redis = Redis.new(:timeout => 0)
|
11
|
+
|
12
|
+
@redis.subscribe('one','two') do |on|
|
13
|
+
on.subscribe {|klass, num_subs| puts "Subscribed to #{klass} (#{num_subs} subscriptions)" }
|
14
|
+
on.message do |klass, msg|
|
15
|
+
puts "#{klass} received: #{msg}"
|
16
|
+
if msg == 'exit'
|
17
|
+
@redis.unsubscribe
|
18
|
+
end
|
19
|
+
end
|
20
|
+
on.unsubscribe {|klass, num_subs| puts "Unsubscribed to #{klass} (#{num_subs} subscriptions)" }
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'redis'
|
3
|
+
|
4
|
+
r = Redis.new
|
5
|
+
|
6
|
+
r.del 'foo-tags'
|
7
|
+
r.del 'bar-tags'
|
8
|
+
|
9
|
+
puts
|
10
|
+
p "create a set of tags on foo-tags"
|
11
|
+
|
12
|
+
r.sadd 'foo-tags', 'one'
|
13
|
+
r.sadd 'foo-tags', 'two'
|
14
|
+
r.sadd 'foo-tags', 'three'
|
15
|
+
|
16
|
+
puts
|
17
|
+
p "create a set of tags on bar-tags"
|
18
|
+
|
19
|
+
r.sadd 'bar-tags', 'three'
|
20
|
+
r.sadd 'bar-tags', 'four'
|
21
|
+
r.sadd 'bar-tags', 'five'
|
22
|
+
|
23
|
+
puts
|
24
|
+
p 'foo-tags'
|
25
|
+
|
26
|
+
p r.smembers('foo-tags')
|
27
|
+
|
28
|
+
puts
|
29
|
+
p 'bar-tags'
|
30
|
+
|
31
|
+
p r.smembers('bar-tags')
|
32
|
+
|
33
|
+
puts
|
34
|
+
p 'intersection of foo-tags and bar-tags'
|
35
|
+
|
36
|
+
p r.sinter('foo-tags', 'bar-tags')
|
@@ -0,0 +1,496 @@
|
|
1
|
+
require 'socket'
|
2
|
+
|
3
|
+
class Redis
|
4
|
+
VERSION = "2.0.0.rc2"
|
5
|
+
|
6
|
+
class ProtocolError < RuntimeError
|
7
|
+
def initialize(reply_type)
|
8
|
+
super("Protocol error, got '#{reply_type}' as initial reply byte")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.deprecate(message, trace = caller[0])
|
13
|
+
$stderr.puts "\n#{message} (in #{trace})"
|
14
|
+
end
|
15
|
+
|
16
|
+
attr :client
|
17
|
+
|
18
|
+
def self.connect(options = {})
|
19
|
+
require "uri"
|
20
|
+
|
21
|
+
url = URI(options.delete(:url) || ENV["REDIS_URL"] || "redis://127.0.0.1:6379/0")
|
22
|
+
|
23
|
+
options[:host] = url.host
|
24
|
+
options[:port] = url.port
|
25
|
+
options[:password] = url.password
|
26
|
+
options[:db] = url.path[1..-1].to_i
|
27
|
+
|
28
|
+
new(options)
|
29
|
+
end
|
30
|
+
|
31
|
+
def initialize(options = {})
|
32
|
+
@client = Client.new(options)
|
33
|
+
end
|
34
|
+
|
35
|
+
def select(db)
|
36
|
+
@client.db = db
|
37
|
+
@client.call(:select, db)
|
38
|
+
end
|
39
|
+
|
40
|
+
def info
|
41
|
+
Hash[*@client.call(:info).split(/:|\r\n/)]
|
42
|
+
end
|
43
|
+
|
44
|
+
def flushdb
|
45
|
+
@client.call(:flushdb)
|
46
|
+
end
|
47
|
+
|
48
|
+
def save
|
49
|
+
@client.call(:save)
|
50
|
+
end
|
51
|
+
|
52
|
+
def bgsave
|
53
|
+
@client.call(:bgsave)
|
54
|
+
end
|
55
|
+
|
56
|
+
def get(key)
|
57
|
+
@client.call(:get, key)
|
58
|
+
end
|
59
|
+
|
60
|
+
def getset(key, value)
|
61
|
+
@client.call(:getset, key, value)
|
62
|
+
end
|
63
|
+
|
64
|
+
def mget(*keys)
|
65
|
+
@client.call(:mget, *keys)
|
66
|
+
end
|
67
|
+
|
68
|
+
def hgetall(key)
|
69
|
+
Hash[*@client.call(:hgetall, key)]
|
70
|
+
end
|
71
|
+
|
72
|
+
def hget(key, field)
|
73
|
+
@client.call(:hget, key, field)
|
74
|
+
end
|
75
|
+
|
76
|
+
def hdel(key, field)
|
77
|
+
@client.call(:hdel, key, field)
|
78
|
+
end
|
79
|
+
|
80
|
+
def hkeys(key)
|
81
|
+
@client.call(:hkeys, key)
|
82
|
+
end
|
83
|
+
|
84
|
+
def keys(pattern = "*")
|
85
|
+
@client.call(:keys, pattern)
|
86
|
+
end
|
87
|
+
|
88
|
+
def randomkey
|
89
|
+
@client.call(:randomkey)
|
90
|
+
end
|
91
|
+
|
92
|
+
def echo(value)
|
93
|
+
@client.call(:echo, value)
|
94
|
+
end
|
95
|
+
|
96
|
+
def ping
|
97
|
+
@client.call(:ping)
|
98
|
+
end
|
99
|
+
|
100
|
+
def lastsave
|
101
|
+
@client.call(:lastsave)
|
102
|
+
end
|
103
|
+
|
104
|
+
def dbsize
|
105
|
+
@client.call(:dbsize)
|
106
|
+
end
|
107
|
+
|
108
|
+
def exists(key)
|
109
|
+
_bool @client.call(:exists, key)
|
110
|
+
end
|
111
|
+
|
112
|
+
def llen(key)
|
113
|
+
@client.call(:llen, key)
|
114
|
+
end
|
115
|
+
|
116
|
+
def lrange(key, start, stop)
|
117
|
+
@client.call(:lrange, key, start, stop)
|
118
|
+
end
|
119
|
+
|
120
|
+
def ltrim(key, start, stop)
|
121
|
+
@client.call(:ltrim, key, start, stop)
|
122
|
+
end
|
123
|
+
|
124
|
+
def lindex(key, index)
|
125
|
+
@client.call(:lindex, key, index)
|
126
|
+
end
|
127
|
+
|
128
|
+
def lset(key, index, value)
|
129
|
+
@client.call(:lset, key, index, value)
|
130
|
+
end
|
131
|
+
|
132
|
+
def lrem(key, count, value)
|
133
|
+
@client.call(:lrem, key, count, value)
|
134
|
+
end
|
135
|
+
|
136
|
+
def rpush(key, value)
|
137
|
+
@client.call(:rpush, key, value)
|
138
|
+
end
|
139
|
+
|
140
|
+
def lpush(key, value)
|
141
|
+
@client.call(:lpush, key, value)
|
142
|
+
end
|
143
|
+
|
144
|
+
def rpop(key)
|
145
|
+
@client.call(:rpop, key)
|
146
|
+
end
|
147
|
+
|
148
|
+
def blpop(key, timeout)
|
149
|
+
@client.call_without_timeout(:blpop, key, timeout)
|
150
|
+
end
|
151
|
+
|
152
|
+
def brpop(key, timeout)
|
153
|
+
@client.call_without_timeout(:brpop, key, timeout)
|
154
|
+
end
|
155
|
+
|
156
|
+
def rpoplpush(source, destination)
|
157
|
+
@client.call(:rpoplpush, source, destination)
|
158
|
+
end
|
159
|
+
|
160
|
+
def lpop(key)
|
161
|
+
@client.call(:lpop, key)
|
162
|
+
end
|
163
|
+
|
164
|
+
def smembers(key)
|
165
|
+
@client.call(:smembers, key)
|
166
|
+
end
|
167
|
+
|
168
|
+
def sismember(key, member)
|
169
|
+
_bool @client.call(:sismember, key, member)
|
170
|
+
end
|
171
|
+
|
172
|
+
def sadd(key, value)
|
173
|
+
_bool @client.call(:sadd, key, value)
|
174
|
+
end
|
175
|
+
|
176
|
+
def srem(key, value)
|
177
|
+
_bool @client.call(:srem, key, value)
|
178
|
+
end
|
179
|
+
|
180
|
+
def smove(source, destination, member)
|
181
|
+
_bool @client.call(:smove, source, destination, member)
|
182
|
+
end
|
183
|
+
|
184
|
+
def spop(key)
|
185
|
+
@client.call(:spop, key)
|
186
|
+
end
|
187
|
+
|
188
|
+
def scard(key)
|
189
|
+
@client.call(:scard, key)
|
190
|
+
end
|
191
|
+
|
192
|
+
def sinter(*keys)
|
193
|
+
@client.call(:sinter, *keys)
|
194
|
+
end
|
195
|
+
|
196
|
+
def sinterstore(destination, *keys)
|
197
|
+
@client.call(:sinterstore, destination, *keys)
|
198
|
+
end
|
199
|
+
|
200
|
+
def sunion(*keys)
|
201
|
+
@client.call(:sunion, *keys)
|
202
|
+
end
|
203
|
+
|
204
|
+
def sunionstore(destination, *keys)
|
205
|
+
@client.call(:sunionstore, destination, *keys)
|
206
|
+
end
|
207
|
+
|
208
|
+
def sdiff(*keys)
|
209
|
+
@client.call(:sdiff, *keys)
|
210
|
+
end
|
211
|
+
|
212
|
+
def sdiffstore(destination, *keys)
|
213
|
+
@client.call(:sdiffstore, destination, *keys)
|
214
|
+
end
|
215
|
+
|
216
|
+
def srandmember(key)
|
217
|
+
@client.call(:srandmember, key)
|
218
|
+
end
|
219
|
+
|
220
|
+
def zadd(key, score, member)
|
221
|
+
_bool @client.call(:zadd, key, score, member)
|
222
|
+
end
|
223
|
+
|
224
|
+
def zincrby(key, increment, member)
|
225
|
+
@client.call(:zincrby, key, increment, member)
|
226
|
+
end
|
227
|
+
|
228
|
+
def zcard(key)
|
229
|
+
@client.call(:zcard, key)
|
230
|
+
end
|
231
|
+
|
232
|
+
def zrange(key, start, stop, with_scores = false)
|
233
|
+
if with_scores
|
234
|
+
@client.call(:zrange, key, start, stop, "WITHSCORES")
|
235
|
+
else
|
236
|
+
@client.call(:zrange, key, start, stop)
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
def zrangebyscore(key, min, max)
|
241
|
+
@client.call(:zrangebyscore, key, min, max)
|
242
|
+
end
|
243
|
+
|
244
|
+
def zrevrange(key, start, stop, with_scores = false)
|
245
|
+
if with_scores
|
246
|
+
@client.call(:zrevrange, key, start, stop, "WITHSCORES")
|
247
|
+
else
|
248
|
+
@client.call(:zrevrange, key, start, stop)
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
def zscore(key, member)
|
253
|
+
@client.call(:zscore, key, member)
|
254
|
+
end
|
255
|
+
|
256
|
+
def zrem(key, member)
|
257
|
+
_bool @client.call(:zrem, key, member)
|
258
|
+
end
|
259
|
+
|
260
|
+
def move(key, db)
|
261
|
+
_bool @client.call(:move, key, db)
|
262
|
+
end
|
263
|
+
|
264
|
+
def setnx(key, value)
|
265
|
+
_bool @client.call(:setnx, key, value)
|
266
|
+
end
|
267
|
+
|
268
|
+
def del(*keys)
|
269
|
+
_bool @client.call(:del, *keys)
|
270
|
+
end
|
271
|
+
|
272
|
+
def rename(old_name, new_name)
|
273
|
+
@client.call(:rename, old_name, new_name)
|
274
|
+
end
|
275
|
+
|
276
|
+
def renamenx(old_name, new_name)
|
277
|
+
_bool @client.call(:renamenx, old_name, new_name)
|
278
|
+
end
|
279
|
+
|
280
|
+
def expire(key, seconds)
|
281
|
+
_bool @client.call(:expire, key, seconds)
|
282
|
+
end
|
283
|
+
|
284
|
+
def ttl(key)
|
285
|
+
@client.call(:ttl, key)
|
286
|
+
end
|
287
|
+
|
288
|
+
def expireat(key, unix_time)
|
289
|
+
_bool @client.call(:expireat, key, unix_time)
|
290
|
+
end
|
291
|
+
|
292
|
+
def hset(key, field, value)
|
293
|
+
_bool @client.call(:hset, key, field, value)
|
294
|
+
end
|
295
|
+
|
296
|
+
def hmset(key, *attrs)
|
297
|
+
@client.call(:hmset, key, *attrs)
|
298
|
+
end
|
299
|
+
|
300
|
+
def hlen(key)
|
301
|
+
@client.call(:hlen, key)
|
302
|
+
end
|
303
|
+
|
304
|
+
def hvals(key)
|
305
|
+
@client.call(:hvals, key)
|
306
|
+
end
|
307
|
+
|
308
|
+
def discard
|
309
|
+
@client.call(:discard)
|
310
|
+
end
|
311
|
+
|
312
|
+
def hexists(key, field)
|
313
|
+
_bool @client.call(:hexists, key, field)
|
314
|
+
end
|
315
|
+
|
316
|
+
def monitor
|
317
|
+
raise NotImplementedError
|
318
|
+
end
|
319
|
+
|
320
|
+
def [](key)
|
321
|
+
get(key)
|
322
|
+
end
|
323
|
+
|
324
|
+
def []=(key,value)
|
325
|
+
set(key, value)
|
326
|
+
end
|
327
|
+
|
328
|
+
def set(key, value)
|
329
|
+
@client.call(:set, key, value)
|
330
|
+
end
|
331
|
+
|
332
|
+
def setex(key, ttl, value)
|
333
|
+
@client.call(:setex, key, ttl, value)
|
334
|
+
end
|
335
|
+
|
336
|
+
def mset(*args)
|
337
|
+
@client.call(:mset, *args)
|
338
|
+
end
|
339
|
+
|
340
|
+
def mapped_mset(hash)
|
341
|
+
mset(*hash.to_a.flatten)
|
342
|
+
end
|
343
|
+
|
344
|
+
def msetnx(*args)
|
345
|
+
@client.call(:msetnx, *args)
|
346
|
+
end
|
347
|
+
|
348
|
+
def mapped_msetnx(hash)
|
349
|
+
msetnx(*hash.to_a.flatten)
|
350
|
+
end
|
351
|
+
|
352
|
+
def mapped_mget(*keys)
|
353
|
+
result = {}
|
354
|
+
mget(*keys).each do |value|
|
355
|
+
key = keys.shift
|
356
|
+
result.merge!(key => value) unless value.nil?
|
357
|
+
end
|
358
|
+
result
|
359
|
+
end
|
360
|
+
|
361
|
+
def sort(key, options = {})
|
362
|
+
cmd = []
|
363
|
+
cmd << "SORT"
|
364
|
+
cmd << key
|
365
|
+
cmd += ["BY", options[:by]] if options[:by]
|
366
|
+
|
367
|
+
Array(options[:get]).each do |k|
|
368
|
+
cmd += ["GET", k]
|
369
|
+
end if options[:get]
|
370
|
+
|
371
|
+
cmd += options[:order].split(" ") if options[:order]
|
372
|
+
cmd += ["LIMIT", *options[:limit]] if options[:limit]
|
373
|
+
cmd += ["STORE", options[:store]] if options[:store]
|
374
|
+
|
375
|
+
@client.call(*cmd)
|
376
|
+
end
|
377
|
+
|
378
|
+
def incr(key)
|
379
|
+
@client.call(:incr, key)
|
380
|
+
end
|
381
|
+
|
382
|
+
def incrby(key, increment)
|
383
|
+
@client.call(:incrby, key, increment)
|
384
|
+
end
|
385
|
+
|
386
|
+
def decr(key)
|
387
|
+
@client.call(:decr, key)
|
388
|
+
end
|
389
|
+
|
390
|
+
def decrby(key, decrement)
|
391
|
+
@client.call(:decrby, key, decrement)
|
392
|
+
end
|
393
|
+
|
394
|
+
def type(key)
|
395
|
+
@client.call(:type, key)
|
396
|
+
end
|
397
|
+
|
398
|
+
def quit
|
399
|
+
@client.call(:quit)
|
400
|
+
rescue Errno::ECONNRESET
|
401
|
+
end
|
402
|
+
|
403
|
+
def pipelined
|
404
|
+
original, @client = @client, Pipeline.new
|
405
|
+
yield
|
406
|
+
original.call_pipelined(@client.commands) unless @client.commands.empty?
|
407
|
+
ensure
|
408
|
+
@client = original
|
409
|
+
end
|
410
|
+
|
411
|
+
def exec
|
412
|
+
@client.call(:exec)
|
413
|
+
end
|
414
|
+
|
415
|
+
def multi(&block)
|
416
|
+
result = @client.call :multi
|
417
|
+
|
418
|
+
return result unless block_given?
|
419
|
+
|
420
|
+
begin
|
421
|
+
yield(self)
|
422
|
+
exec
|
423
|
+
rescue Exception => e
|
424
|
+
discard
|
425
|
+
raise e
|
426
|
+
end
|
427
|
+
end
|
428
|
+
|
429
|
+
def publish(channel, message)
|
430
|
+
@client.call(:publish, channel, message)
|
431
|
+
end
|
432
|
+
|
433
|
+
def subscribed?
|
434
|
+
@client.kind_of? SubscribedClient
|
435
|
+
end
|
436
|
+
|
437
|
+
def unsubscribe(*channels)
|
438
|
+
raise RuntimeError, "Can't unsubscribe if not subscribed." unless subscribed?
|
439
|
+
@client.unsubscribe(*channels)
|
440
|
+
end
|
441
|
+
|
442
|
+
def punsubscribe(*channels)
|
443
|
+
raise RuntimeError, "Can't unsubscribe if not subscribed." unless subscribed?
|
444
|
+
@client.punsubscribe(*channels)
|
445
|
+
end
|
446
|
+
|
447
|
+
def subscribe(*channels, &block)
|
448
|
+
subscription(:subscribe, channels, block)
|
449
|
+
end
|
450
|
+
|
451
|
+
def psubscribe(*channels, &block)
|
452
|
+
subscription(:psubscribe, channels, block)
|
453
|
+
end
|
454
|
+
|
455
|
+
def id
|
456
|
+
@client.id
|
457
|
+
end
|
458
|
+
|
459
|
+
def method_missing(command, *args)
|
460
|
+
@client.call(command, *args)
|
461
|
+
end
|
462
|
+
|
463
|
+
private
|
464
|
+
|
465
|
+
def _bool(value)
|
466
|
+
value == 1
|
467
|
+
end
|
468
|
+
|
469
|
+
def subscription(method, channels, block)
|
470
|
+
return @client.call(method, *channels) if subscribed?
|
471
|
+
|
472
|
+
begin
|
473
|
+
original, @client = @client, SubscribedClient.new(@client)
|
474
|
+
@client.send(method, *channels, &block)
|
475
|
+
ensure
|
476
|
+
@client = original
|
477
|
+
end
|
478
|
+
end
|
479
|
+
|
480
|
+
end
|
481
|
+
|
482
|
+
begin
|
483
|
+
if RUBY_VERSION >= '1.9'
|
484
|
+
require 'timeout'
|
485
|
+
Redis::Timer = Timeout
|
486
|
+
else
|
487
|
+
require 'system_timer'
|
488
|
+
Redis::Timer = SystemTimer
|
489
|
+
end
|
490
|
+
rescue LoadError
|
491
|
+
Redis::Timer = nil
|
492
|
+
end
|
493
|
+
|
494
|
+
require 'redis/client'
|
495
|
+
require 'redis/pipeline'
|
496
|
+
require 'redis/subscribe'
|