winescout-redis 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.markdown +31 -0
- data/Rakefile +58 -0
- data/lib/better_timeout.rb +191 -0
- data/lib/dist_redis.rb +111 -0
- data/lib/hash_ring.rb +127 -0
- data/lib/redis.rb +462 -0
- data/lib/server.rb +131 -0
- data/spec/redis_spec.rb +323 -0
- data/spec/spec_helper.rb +4 -0
- metadata +63 -0
data/spec/redis_spec.rb
ADDED
@@ -0,0 +1,323 @@
|
|
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.flush_db
|
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 be able to SETNX(set_unless_exists)" do
|
43
|
+
@r['foo'] = 'nik'
|
44
|
+
@r['foo'].should == 'nik'
|
45
|
+
@r.set_unless_exists 'foo', 'bar'
|
46
|
+
@r['foo'].should == 'nik'
|
47
|
+
end
|
48
|
+
#
|
49
|
+
it "should be able to INCR(increment) a key" do
|
50
|
+
@r.delete('counter')
|
51
|
+
@r.incr('counter').should == 1
|
52
|
+
@r.incr('counter').should == 2
|
53
|
+
@r.incr('counter').should == 3
|
54
|
+
end
|
55
|
+
#
|
56
|
+
it "should be able to DECR(decrement) a key" do
|
57
|
+
@r.delete('counter')
|
58
|
+
@r.incr('counter').should == 1
|
59
|
+
@r.incr('counter').should == 2
|
60
|
+
@r.incr('counter').should == 3
|
61
|
+
@r.decr('counter').should == 2
|
62
|
+
@r.decr('counter').should == 1
|
63
|
+
@r.decr('counter').should == 0
|
64
|
+
end
|
65
|
+
#
|
66
|
+
it "should be able to RANDKEY(return a random key)" do
|
67
|
+
@r.randkey.should_not be_nil
|
68
|
+
end
|
69
|
+
#
|
70
|
+
it "should be able to RENAME a key" do
|
71
|
+
@r.delete 'foo'
|
72
|
+
@r.delete 'bar'
|
73
|
+
@r['foo'] = 'hi'
|
74
|
+
@r.rename! 'foo', 'bar'
|
75
|
+
@r['bar'].should == 'hi'
|
76
|
+
end
|
77
|
+
#
|
78
|
+
it "should be able to RENAMENX(rename unless the new key already exists) a key" do
|
79
|
+
@r.delete 'foo'
|
80
|
+
@r.delete 'bar'
|
81
|
+
@r['foo'] = 'hi'
|
82
|
+
@r['bar'] = 'ohai'
|
83
|
+
lambda {@r.rename 'foo', 'bar'}.should raise_error(RedisRenameError)
|
84
|
+
@r['bar'].should == 'ohai'
|
85
|
+
end
|
86
|
+
#
|
87
|
+
it "should be able to EXISTS(check if key exists)" do
|
88
|
+
@r['foo'] = 'nik'
|
89
|
+
@r.key?('foo').should be_true
|
90
|
+
@r.delete 'foo'
|
91
|
+
@r.key?('foo').should be_false
|
92
|
+
end
|
93
|
+
#
|
94
|
+
it "should be able to KEYS(glob for keys)" do
|
95
|
+
@r.keys("f*").each do |key|
|
96
|
+
@r.delete key
|
97
|
+
end
|
98
|
+
@r['f'] = 'nik'
|
99
|
+
@r['fo'] = 'nak'
|
100
|
+
@r['foo'] = 'qux'
|
101
|
+
@r.keys("f*").sort.should == ['f','fo', 'foo'].sort
|
102
|
+
end
|
103
|
+
#
|
104
|
+
it "should be able to check the TYPE of a key" do
|
105
|
+
@r['foo'] = 'nik'
|
106
|
+
@r.type?('foo').should == "string"
|
107
|
+
@r.delete 'foo'
|
108
|
+
@r.type?('foo').should == "none"
|
109
|
+
end
|
110
|
+
#
|
111
|
+
it "should be able to push to the head of a list" do
|
112
|
+
@r.push_head "list", 'hello'
|
113
|
+
@r.push_head "list", 42
|
114
|
+
@r.type?('list').should == "list"
|
115
|
+
@r.list_length('list').should == 2
|
116
|
+
@r.pop_head('list').should == '42'
|
117
|
+
@r.delete('list')
|
118
|
+
end
|
119
|
+
#
|
120
|
+
it "should be able to push to the tail of a list" do
|
121
|
+
@r.push_tail "list", 'hello'
|
122
|
+
@r.type?('list').should == "list"
|
123
|
+
@r.list_length('list').should == 1
|
124
|
+
@r.delete('list')
|
125
|
+
end
|
126
|
+
#
|
127
|
+
it "should be able to pop the tail of a list" do
|
128
|
+
@r.push_tail "list", 'hello'
|
129
|
+
@r.push_tail "list", 'goodbye'
|
130
|
+
@r.type?('list').should == "list"
|
131
|
+
@r.list_length('list').should == 2
|
132
|
+
@r.pop_tail('list').should == 'goodbye'
|
133
|
+
@r.delete('list')
|
134
|
+
end
|
135
|
+
#
|
136
|
+
it "should be able to pop the head of a list" do
|
137
|
+
@r.push_tail "list", 'hello'
|
138
|
+
@r.push_tail "list", 'goodbye'
|
139
|
+
@r.type?('list').should == "list"
|
140
|
+
@r.list_length('list').should == 2
|
141
|
+
@r.pop_head('list').should == 'hello'
|
142
|
+
@r.delete('list')
|
143
|
+
end
|
144
|
+
#
|
145
|
+
it "should be able to get the length of a list" do
|
146
|
+
@r.push_tail "list", 'hello'
|
147
|
+
@r.push_tail "list", 'goodbye'
|
148
|
+
@r.type?('list').should == "list"
|
149
|
+
@r.list_length('list').should == 2
|
150
|
+
@r.delete('list')
|
151
|
+
end
|
152
|
+
#
|
153
|
+
it "should be able to get a range of values from a list" do
|
154
|
+
@r.push_tail "list", 'hello'
|
155
|
+
@r.push_tail "list", 'goodbye'
|
156
|
+
@r.push_tail "list", '1'
|
157
|
+
@r.push_tail "list", '2'
|
158
|
+
@r.push_tail "list", '3'
|
159
|
+
@r.type?('list').should == "list"
|
160
|
+
@r.list_length('list').should == 5
|
161
|
+
@r.list_range('list', 2, -1).should == ['1', '2', '3']
|
162
|
+
@r.delete('list')
|
163
|
+
end
|
164
|
+
#
|
165
|
+
it "should be able to trim a list" do
|
166
|
+
@r.push_tail "list", 'hello'
|
167
|
+
@r.push_tail "list", 'goodbye'
|
168
|
+
@r.push_tail "list", '1'
|
169
|
+
@r.push_tail "list", '2'
|
170
|
+
@r.push_tail "list", '3'
|
171
|
+
@r.type?('list').should == "list"
|
172
|
+
@r.list_length('list').should == 5
|
173
|
+
@r.list_trim 'list', 0, 1
|
174
|
+
@r.list_length('list').should == 2
|
175
|
+
@r.list_range('list', 0, -1).should == ['hello', 'goodbye']
|
176
|
+
@r.delete('list')
|
177
|
+
end
|
178
|
+
#
|
179
|
+
it "should be able to get a value by indexing into a list" do
|
180
|
+
@r.push_tail "list", 'hello'
|
181
|
+
@r.push_tail "list", 'goodbye'
|
182
|
+
@r.type?('list').should == "list"
|
183
|
+
@r.list_length('list').should == 2
|
184
|
+
@r.list_index('list', 1).should == 'goodbye'
|
185
|
+
@r.delete('list')
|
186
|
+
end
|
187
|
+
#
|
188
|
+
it "should be able to set a value by indexing into a list" do
|
189
|
+
@r.push_tail "list", 'hello'
|
190
|
+
@r.push_tail "list", 'hello'
|
191
|
+
@r.type?('list').should == "list"
|
192
|
+
@r.list_length('list').should == 2
|
193
|
+
@r.list_set('list', 1, 'goodbye').should be_true
|
194
|
+
@r.list_index('list', 1).should == 'goodbye'
|
195
|
+
@r.delete('list')
|
196
|
+
end
|
197
|
+
#
|
198
|
+
it "should be able to remove values from a list LREM" do
|
199
|
+
@r.push_tail "list", 'hello'
|
200
|
+
@r.push_tail "list", 'goodbye'
|
201
|
+
@r.type?('list').should == "list"
|
202
|
+
@r.list_length('list').should == 2
|
203
|
+
@r.list_rm('list', 1, 'hello').should == 1
|
204
|
+
@r.list_range('list', 0, -1).should == ['goodbye']
|
205
|
+
@r.delete('list')
|
206
|
+
end
|
207
|
+
#
|
208
|
+
it "should be able add members to a set" do
|
209
|
+
@r.set_add "set", 'key1'
|
210
|
+
@r.set_add "set", 'key2'
|
211
|
+
@r.type?('set').should == "set"
|
212
|
+
@r.set_count('set').should == 2
|
213
|
+
@r.set_members('set').sort.should == ['key1', 'key2'].sort
|
214
|
+
@r.delete('set')
|
215
|
+
end
|
216
|
+
#
|
217
|
+
it "should be able delete members to a set" do
|
218
|
+
@r.set_add "set", 'key1'
|
219
|
+
@r.set_add "set", 'key2'
|
220
|
+
@r.type?('set').should == "set"
|
221
|
+
@r.set_count('set').should == 2
|
222
|
+
@r.set_members('set').should == Set.new(['key1', 'key2'])
|
223
|
+
@r.set_delete('set', 'key1')
|
224
|
+
@r.set_count('set').should == 1
|
225
|
+
@r.set_members('set').should == Set.new(['key2'])
|
226
|
+
@r.delete('set')
|
227
|
+
end
|
228
|
+
#
|
229
|
+
it "should be able count the members of a set" do
|
230
|
+
@r.set_add "set", 'key1'
|
231
|
+
@r.set_add "set", 'key2'
|
232
|
+
@r.type?('set').should == "set"
|
233
|
+
@r.set_count('set').should == 2
|
234
|
+
@r.delete('set')
|
235
|
+
end
|
236
|
+
#
|
237
|
+
it "should be able test for set membership" do
|
238
|
+
@r.set_add "set", 'key1'
|
239
|
+
@r.set_add "set", 'key2'
|
240
|
+
@r.type?('set').should == "set"
|
241
|
+
@r.set_count('set').should == 2
|
242
|
+
@r.set_member?('set', 'key1').should be_true
|
243
|
+
@r.set_member?('set', 'key2').should be_true
|
244
|
+
@r.set_member?('set', 'notthere').should be_false
|
245
|
+
@r.delete('set')
|
246
|
+
end
|
247
|
+
#
|
248
|
+
it "should be able to do set intersection" do
|
249
|
+
@r.set_add "set", 'key1'
|
250
|
+
@r.set_add "set", 'key2'
|
251
|
+
@r.set_add "set2", 'key2'
|
252
|
+
@r.set_intersect('set', 'set2').should == Set.new(['key2'])
|
253
|
+
@r.delete('set')
|
254
|
+
end
|
255
|
+
#
|
256
|
+
it "should be able to do set intersection and store the results in a key" do
|
257
|
+
@r.set_add "set", 'key1'
|
258
|
+
@r.set_add "set", 'key2'
|
259
|
+
@r.set_add "set2", 'key2'
|
260
|
+
@r.set_inter_store('newone', 'set', 'set2')
|
261
|
+
@r.set_members('newone').should == Set.new(['key2'])
|
262
|
+
@r.delete('set')
|
263
|
+
end
|
264
|
+
#
|
265
|
+
it "should be able to do crazy SORT queries" do
|
266
|
+
@r['dog_1'] = 'louie'
|
267
|
+
@r.push_tail 'dogs', 1
|
268
|
+
@r['dog_2'] = 'lucy'
|
269
|
+
@r.push_tail 'dogs', 2
|
270
|
+
@r['dog_3'] = 'max'
|
271
|
+
@r.push_tail 'dogs', 3
|
272
|
+
@r['dog_4'] = 'taj'
|
273
|
+
@r.push_tail 'dogs', 4
|
274
|
+
@r.sort('dogs', :get => 'dog_*', :limit => [0,1]).should == ['louie']
|
275
|
+
@r.sort('dogs', :get => 'dog_*', :limit => [0,1], :order => 'desc alpha').should == ['taj']
|
276
|
+
end
|
277
|
+
#
|
278
|
+
it "should provide info" do
|
279
|
+
[: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|
|
280
|
+
@r.info.keys.should include(x)
|
281
|
+
end
|
282
|
+
end
|
283
|
+
#
|
284
|
+
it "should be able to flush the database" do
|
285
|
+
@r['key1'] = 'keyone'
|
286
|
+
@r['key2'] = 'keytwo'
|
287
|
+
@r.keys('*').sort.should == ['foo', 'key1', 'key2'] #foo from before
|
288
|
+
@r.flush_db
|
289
|
+
@r.keys('*').should == []
|
290
|
+
end
|
291
|
+
#
|
292
|
+
it "should be able to provide the last save time" do
|
293
|
+
savetime = @r.last_save
|
294
|
+
Time.at(savetime).class.should == Time
|
295
|
+
Time.at(savetime).should <= Time.now
|
296
|
+
end
|
297
|
+
|
298
|
+
it "should be able to MGET keys" do
|
299
|
+
@r['foo'] = 1000
|
300
|
+
@r['bar'] = 2000
|
301
|
+
@r.mget('foo', 'bar').should == ['1000', '2000']
|
302
|
+
@r.mget('foo', 'bar', 'baz').should == ['1000', '2000', nil]
|
303
|
+
end
|
304
|
+
|
305
|
+
it "should bgsave" do
|
306
|
+
lambda {@r.bgsave}.should_not raise_error(RedisError)
|
307
|
+
end
|
308
|
+
|
309
|
+
it "should handle multiple servers" do
|
310
|
+
require 'dist_redis'
|
311
|
+
@r = DistRedis.new('localhost:6379', '127.0.0.1:6379')
|
312
|
+
@r.select_db(15) # use database 15 for testing so we dont accidentally step on you real data
|
313
|
+
|
314
|
+
100.times do |idx|
|
315
|
+
@r[idx] = "foo#{idx}"
|
316
|
+
end
|
317
|
+
|
318
|
+
100.times do |idx|
|
319
|
+
@r[idx].should == "foo#{idx}"
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: winescout-redis
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ezra Zygmuntowicz
|
8
|
+
- Taylor Weibley
|
9
|
+
autorequire: redis
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-03-31 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: Ruby client library for redis key value storage server
|
18
|
+
email: ez@engineyard.com
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files:
|
24
|
+
- LICENSE
|
25
|
+
files:
|
26
|
+
- LICENSE
|
27
|
+
- README.markdown
|
28
|
+
- Rakefile
|
29
|
+
- lib/redis.rb
|
30
|
+
- lib/dist_redis.rb
|
31
|
+
- lib/hash_ring.rb
|
32
|
+
- lib/server.rb
|
33
|
+
- lib/better_timeout.rb
|
34
|
+
- spec/redis_spec.rb
|
35
|
+
- spec/spec_helper.rb
|
36
|
+
has_rdoc: true
|
37
|
+
homepage: http://github.com/ezmobius/redis-rb
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
48
|
+
version:
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
requirements: []
|
56
|
+
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 1.2.0
|
59
|
+
signing_key:
|
60
|
+
specification_version: 2
|
61
|
+
summary: Ruby client library for redis key value storage server
|
62
|
+
test_files: []
|
63
|
+
|