em-redis 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/em-redis.rb +2 -47
- data/lib/em-redis/redis_protocol.rb +15 -55
- data/lib/em-redis/version.rb +3 -0
- metadata +27 -55
- data/.gitignore +0 -2
- data/README.rdoc +0 -85
- data/Rakefile +0 -41
- data/spec/live_redis_protocol_spec.rb +0 -446
- data/spec/redis_commands_spec.rb +0 -761
- data/spec/redis_protocol_spec.rb +0 -149
- data/spec/test_helper.rb +0 -25
data/lib/em-redis.rb
CHANGED
@@ -1,47 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
# :stopdoc:
|
5
|
-
VERSION = '0.2.3'
|
6
|
-
LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
|
7
|
-
PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
|
8
|
-
# :startdoc:
|
9
|
-
|
10
|
-
# Returns the version string for the library.
|
11
|
-
#
|
12
|
-
def self.version
|
13
|
-
VERSION
|
14
|
-
end
|
15
|
-
|
16
|
-
# Returns the library path for the module. If any arguments are given,
|
17
|
-
# they will be joined to the end of the libray path using
|
18
|
-
# <tt>File.join</tt>.
|
19
|
-
#
|
20
|
-
def self.libpath( *args )
|
21
|
-
args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
|
22
|
-
end
|
23
|
-
|
24
|
-
# Returns the lpath for the module. If any arguments are given,
|
25
|
-
# they will be joined to the end of the path using
|
26
|
-
# <tt>File.join</tt>.
|
27
|
-
#
|
28
|
-
def self.path( *args )
|
29
|
-
args.empty? ? PATH : ::File.join(PATH, args.flatten)
|
30
|
-
end
|
31
|
-
|
32
|
-
# Utility method used to require all files ending in .rb that lie in the
|
33
|
-
# directory below this file that has the same name as the filename passed
|
34
|
-
# in. Optionally, a specific _directory_ name can be passed in such that
|
35
|
-
# the _filename_ does not have to be equivalent to the directory.
|
36
|
-
#
|
37
|
-
def self.require_all_libs_relative_to( fname, dir = nil )
|
38
|
-
dir ||= ::File.basename(fname, '.*')
|
39
|
-
search_me = ::File.expand_path(
|
40
|
-
::File.join(::File.dirname(fname), dir, '**', '*.rb'))
|
41
|
-
|
42
|
-
Dir.glob(search_me).sort.each {|rb| require rb}
|
43
|
-
end
|
44
|
-
|
45
|
-
end # module EMRedis
|
46
|
-
|
47
|
-
EMRedis.require_all_libs_relative_to(__FILE__)
|
1
|
+
require File.expand_path('../em-redis/version', __FILE__)
|
2
|
+
require File.expand_path('../em-redis/redis_protocol', __FILE__)
|
@@ -18,36 +18,6 @@ module EventMachine
|
|
18
18
|
ASTERISK = "*".freeze
|
19
19
|
DELIM = "\r\n".freeze
|
20
20
|
|
21
|
-
BULK_COMMANDS = {
|
22
|
-
"set" => true,
|
23
|
-
"setnx" => true,
|
24
|
-
"rpush" => true,
|
25
|
-
"lpush" => true,
|
26
|
-
"lset" => true,
|
27
|
-
"lrem" => true,
|
28
|
-
"sadd" => true,
|
29
|
-
"srem" => true,
|
30
|
-
"sismember" => true,
|
31
|
-
"echo" => true,
|
32
|
-
"getset" => true,
|
33
|
-
"smove" => true,
|
34
|
-
"zadd" => true,
|
35
|
-
"zincrby" => true,
|
36
|
-
"zrem" => true,
|
37
|
-
"zscore" => true,
|
38
|
-
"hget" => true,
|
39
|
-
"hdel" => true,
|
40
|
-
"hexists" => true
|
41
|
-
}
|
42
|
-
|
43
|
-
MULTI_BULK_COMMANDS = {
|
44
|
-
"mset" => true,
|
45
|
-
"msetnx" => true,
|
46
|
-
"hset" => true,
|
47
|
-
# these aliases aren't in redis gem
|
48
|
-
"multi_get" => true
|
49
|
-
}
|
50
|
-
|
51
21
|
BOOLEAN_PROCESSOR = lambda{|r| r == 1 }
|
52
22
|
|
53
23
|
REPLY_PROCESSOR = {
|
@@ -186,11 +156,11 @@ module EventMachine
|
|
186
156
|
def sort(key, options={}, &blk)
|
187
157
|
cmd = ["SORT"]
|
188
158
|
cmd << key
|
189
|
-
cmd << "BY
|
190
|
-
cmd <<
|
191
|
-
cmd <<
|
192
|
-
cmd << "LIMIT
|
193
|
-
call_command(cmd, &blk)
|
159
|
+
cmd << ["BY", options[:by]] if options[:by]
|
160
|
+
cmd << [options[:get]].flatten.map { |key| ["GET", key] } if options[:get]
|
161
|
+
cmd << options[:order].split(/\s+/) if options[:order]
|
162
|
+
cmd << ["LIMIT", options[:limit]] if options[:limit]
|
163
|
+
call_command(cmd.flatten, &blk)
|
194
164
|
end
|
195
165
|
|
196
166
|
def incr(key, increment = nil, &blk)
|
@@ -296,26 +266,16 @@ module EventMachine
|
|
296
266
|
argv = argv.dup
|
297
267
|
|
298
268
|
argv[0] = argv[0].to_s.downcase
|
299
|
-
if
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
command = ""
|
310
|
-
bulk = nil
|
311
|
-
argv[0] = ALIASES[argv[0]] if ALIASES[argv[0]]
|
312
|
-
raise "#{argv[0]} command is disabled" if DISABLED_COMMANDS[argv[0]]
|
313
|
-
if BULK_COMMANDS[argv[0]] and argv.length > 1
|
314
|
-
bulk = argv[-1].to_s
|
315
|
-
argv[-1] = get_size(bulk)
|
316
|
-
end
|
317
|
-
command << "#{argv.join(' ')}\r\n"
|
318
|
-
command << "#{bulk}\r\n" if bulk
|
269
|
+
argv[0] = ALIASES[argv[0]] if ALIASES[argv[0]]
|
270
|
+
raise "#{argv[0]} command is disabled" if DISABLED_COMMANDS[argv[0]]
|
271
|
+
|
272
|
+
command = ""
|
273
|
+
command << "*#{argv.size}\r\n"
|
274
|
+
argv.each do |a|
|
275
|
+
a = a.to_s
|
276
|
+
command << "$#{get_size(a)}\r\n"
|
277
|
+
command << a
|
278
|
+
command << "\r\n"
|
319
279
|
end
|
320
280
|
|
321
281
|
@logger.debug { "*** sending: #{command}" } if @logger
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: em-redis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 19
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
|
-
- 2
|
8
8
|
- 3
|
9
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Jonathan Broad
|
@@ -15,113 +16,84 @@ autorequire:
|
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date: 2010-
|
19
|
+
date: 2010-11-23 00:00:00 +03:00
|
19
20
|
default_executable:
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|
22
23
|
name: eventmachine
|
23
24
|
prerelease: false
|
24
25
|
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
25
27
|
requirements:
|
26
28
|
- - ">="
|
27
29
|
- !ruby/object:Gem::Version
|
30
|
+
hash: 3
|
28
31
|
segments:
|
29
32
|
- 0
|
30
|
-
|
31
|
-
- 10
|
32
|
-
version: 0.12.10
|
33
|
+
version: "0"
|
33
34
|
type: :runtime
|
34
35
|
version_requirements: *id001
|
35
36
|
- !ruby/object:Gem::Dependency
|
36
|
-
name:
|
37
|
+
name: bundler
|
37
38
|
prerelease: false
|
38
39
|
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
39
41
|
requirements:
|
40
|
-
- -
|
42
|
+
- - ~>
|
41
43
|
- !ruby/object:Gem::Version
|
44
|
+
hash: 15424249
|
42
45
|
segments:
|
43
46
|
- 1
|
44
|
-
- 1
|
45
47
|
- 0
|
46
|
-
|
48
|
+
- rc
|
49
|
+
- 6
|
50
|
+
version: 1.0.rc.6
|
47
51
|
type: :development
|
48
52
|
version_requirements: *id002
|
49
|
-
- !ruby/object:Gem::Dependency
|
50
|
-
name: em-spec
|
51
|
-
prerelease: false
|
52
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
-
requirements:
|
54
|
-
- - ">="
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
segments:
|
57
|
-
- 0
|
58
|
-
- 2
|
59
|
-
- 1
|
60
|
-
version: 0.2.1
|
61
|
-
type: :development
|
62
|
-
version_requirements: *id003
|
63
|
-
- !ruby/object:Gem::Dependency
|
64
|
-
name: bones
|
65
|
-
prerelease: false
|
66
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
-
requirements:
|
68
|
-
- - ">="
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
segments:
|
71
|
-
- 3
|
72
|
-
- 2
|
73
|
-
- 1
|
74
|
-
version: 3.2.1
|
75
|
-
type: :development
|
76
|
-
version_requirements: *id004
|
77
53
|
description: An eventmachine-based implementation of the Redis protocol
|
78
54
|
email: libc@me.com
|
79
55
|
executables: []
|
80
56
|
|
81
57
|
extensions: []
|
82
58
|
|
83
|
-
extra_rdoc_files:
|
84
|
-
|
85
|
-
- README.rdoc
|
59
|
+
extra_rdoc_files: []
|
60
|
+
|
86
61
|
files:
|
87
|
-
- .gitignore
|
88
|
-
- History.txt
|
89
|
-
- README.rdoc
|
90
|
-
- Rakefile
|
91
|
-
- lib/em-redis.rb
|
92
62
|
- lib/em-redis/redis_protocol.rb
|
93
|
-
-
|
94
|
-
-
|
95
|
-
-
|
96
|
-
- spec/test_helper.rb
|
63
|
+
- lib/em-redis/version.rb
|
64
|
+
- lib/em-redis.rb
|
65
|
+
- History.txt
|
97
66
|
has_rdoc: true
|
98
67
|
homepage: http://github.com/libc/em-redis
|
99
68
|
licenses: []
|
100
69
|
|
101
70
|
post_install_message:
|
102
|
-
rdoc_options:
|
103
|
-
|
104
|
-
- README.rdoc
|
71
|
+
rdoc_options: []
|
72
|
+
|
105
73
|
require_paths:
|
106
74
|
- lib
|
107
75
|
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
108
77
|
requirements:
|
109
78
|
- - ">="
|
110
79
|
- !ruby/object:Gem::Version
|
80
|
+
hash: 3
|
111
81
|
segments:
|
112
82
|
- 0
|
113
83
|
version: "0"
|
114
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
115
86
|
requirements:
|
116
87
|
- - ">="
|
117
88
|
- !ruby/object:Gem::Version
|
89
|
+
hash: 3
|
118
90
|
segments:
|
119
91
|
- 0
|
120
92
|
version: "0"
|
121
93
|
requirements: []
|
122
94
|
|
123
|
-
rubyforge_project:
|
124
|
-
rubygems_version: 1.3.
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 1.3.7
|
125
97
|
signing_key:
|
126
98
|
specification_version: 3
|
127
99
|
summary: An eventmachine-based implementation of the Redis protocol
|
data/.gitignore
DELETED
data/README.rdoc
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
== EM-REDIS
|
2
|
-
|
3
|
-
== DESCRIPTION:
|
4
|
-
|
5
|
-
An EventMachine[http://rubyeventmachine.com/] based library for interacting with the very cool Redis[http://code.google.com/p/redis/] data store by Salvatore 'antirez' Sanfilippo.
|
6
|
-
Modeled after eventmachine's implementation of the memcached protocol, and influenced by Ezra Zygmuntowicz's {redis-rb}[http://github.com/ezmobius/redis-rb/tree/master] library (distributed as part of Redis).
|
7
|
-
|
8
|
-
This library is only useful when used as part of an application that relies on
|
9
|
-
Event Machine's event loop. It implements an EM-based client protocol, which
|
10
|
-
leverages the non-blocking nature of the EM interface to achieve significant
|
11
|
-
parallelization without threads.
|
12
|
-
|
13
|
-
|
14
|
-
== FEATURES/PROBLEMS:
|
15
|
-
|
16
|
-
Implements most Redis commands (see {the list of available commands here}[http://code.google.com/p/redis/wiki/CommandReference] with the notable
|
17
|
-
exception of MONITOR.
|
18
|
-
|
19
|
-
== SYNOPSIS:
|
20
|
-
|
21
|
-
Like any Deferrable eventmachine-based protocol implementation, using EM-Redis involves making calls and passing blocks that serve as callbacks when the call returns.
|
22
|
-
|
23
|
-
require 'em-redis'
|
24
|
-
|
25
|
-
EM.run do
|
26
|
-
redis = EM::Protocols::Redis.connect
|
27
|
-
redis.errback do |code|
|
28
|
-
puts "Error code: #{code}"
|
29
|
-
end
|
30
|
-
redis.set "a", "foo" do |response|
|
31
|
-
redis.get "a" do |response|
|
32
|
-
puts response
|
33
|
-
end
|
34
|
-
end
|
35
|
-
# We get pipelining for free
|
36
|
-
redis.set("b", "bar")
|
37
|
-
redis.get("a") do |response|
|
38
|
-
puts response # will be foo
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
To run tests on a Redis server (currently compatible with 1.3)
|
43
|
-
|
44
|
-
rake
|
45
|
-
|
46
|
-
Because the EM::Protocol::Memcached code used Bacon for testing, test code is
|
47
|
-
currently in the form of bacon specs.
|
48
|
-
|
49
|
-
== REQUIREMENTS:
|
50
|
-
|
51
|
-
* Redis (download[http://code.google.com/p/redis/downloads/list])
|
52
|
-
|
53
|
-
== INSTALL:
|
54
|
-
|
55
|
-
sudo gem install em-redis
|
56
|
-
|
57
|
-
== LICENSE:
|
58
|
-
|
59
|
-
(The MIT License)
|
60
|
-
|
61
|
-
Copyright (c) 2008, 2009
|
62
|
-
|
63
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
64
|
-
a copy of this software and associated documentation files (the
|
65
|
-
'Software'), to deal in the Software without restriction, including
|
66
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
67
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
68
|
-
permit persons to whom the Software is furnished to do so, subject to
|
69
|
-
the following conditions:
|
70
|
-
|
71
|
-
The above copyright notice and this permission notice shall be
|
72
|
-
included in all copies or substantial portions of the Software.
|
73
|
-
|
74
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
75
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
76
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
77
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
78
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
79
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
80
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
81
|
-
|
82
|
-
== CREDIT
|
83
|
-
|
84
|
-
by Jonathan Broad (http://www.relativepath.org)
|
85
|
-
|
data/Rakefile
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
# Look in the tasks/setup.rb file for the various options that can be
|
2
|
-
# configured in this Rakefile. The .rake files in the tasks directory
|
3
|
-
# are where the options are used.
|
4
|
-
|
5
|
-
begin
|
6
|
-
require 'bones'
|
7
|
-
rescue LoadError
|
8
|
-
abort '### Please install the "bones" gem ###'
|
9
|
-
end
|
10
|
-
|
11
|
-
ensure_in_path 'lib'
|
12
|
-
require 'em-redis'
|
13
|
-
|
14
|
-
task :default => ['redis:test']
|
15
|
-
|
16
|
-
Bones {
|
17
|
-
name 'em-redis'
|
18
|
-
authors ['Jonathan Broad', 'Eugene Pimenov']
|
19
|
-
email 'libc@me.com'
|
20
|
-
url 'http://github.com/libc/em-redis'
|
21
|
-
summary 'An eventmachine-based implementation of the Redis protocol'
|
22
|
-
description summary
|
23
|
-
version EMRedis::VERSION
|
24
|
-
|
25
|
-
readme_file 'README.rdoc'
|
26
|
-
ignore_file '.gitignore'
|
27
|
-
|
28
|
-
depend_on 'eventmachine', '>=0.12.10'
|
29
|
-
|
30
|
-
depend_on "bacon", :development => true
|
31
|
-
depend_on "em-spec", :development => true
|
32
|
-
}
|
33
|
-
|
34
|
-
namespace :redis do
|
35
|
-
desc "Test em-redis against a live Redis"
|
36
|
-
task :test do
|
37
|
-
sh "bacon spec/live_redis_protocol_spec.rb spec/redis_commands_spec.rb spec/redis_protocol_spec.rb"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
# EOF
|
@@ -1,446 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + "/test_helper.rb")
|
2
|
-
|
3
|
-
EM.describe EM::Protocols::Redis, "connected to an empty db" do
|
4
|
-
|
5
|
-
before do
|
6
|
-
@c = EM::Protocols::Redis.connect :db => 14
|
7
|
-
@c.flushdb
|
8
|
-
end
|
9
|
-
|
10
|
-
should "be able to set a string value" do
|
11
|
-
@c.set("foo", "bar") do |r|
|
12
|
-
r.should == "OK"
|
13
|
-
done
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
should "be able to increment the value of a string" do
|
18
|
-
@c.incr "foo" do |r|
|
19
|
-
r.should == 1
|
20
|
-
@c.incr "foo" do |r|
|
21
|
-
r.should == 2
|
22
|
-
done
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
should "be able to increment the value of a string by an amount" do
|
28
|
-
@c.incrby "foo", 10 do |r|
|
29
|
-
r.should == 10
|
30
|
-
done
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
should "be able to decrement the value of a string" do
|
35
|
-
@c.incr "foo" do |r|
|
36
|
-
r.should == 1
|
37
|
-
@c.decr "foo" do |r|
|
38
|
-
r.should == 0
|
39
|
-
done
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
should "be able to decrement the value of a string by an amount" do
|
45
|
-
@c.incrby "foo", 20 do |r|
|
46
|
-
r.should == 20
|
47
|
-
@c.decrby "foo", 10 do |r|
|
48
|
-
r.should == 10
|
49
|
-
done
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
should "be able to 'lpush' to a nonexistent list" do
|
55
|
-
@c.lpush("foo", "bar") do |r|
|
56
|
-
r.should == 1
|
57
|
-
done
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
should "be able to 'rpush' to a nonexistent list" do
|
62
|
-
@c.rpush("foo", "bar") do |r|
|
63
|
-
r.should == 1
|
64
|
-
done
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
|
69
|
-
should "be able to get the size of the database" do
|
70
|
-
@c.dbsize do |r|
|
71
|
-
r.should == 0
|
72
|
-
done
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
should "be able to add a member to a nonexistent set" do
|
77
|
-
@c.sadd("set_foo", "bar") do |r|
|
78
|
-
r.should == true
|
79
|
-
done
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
should "be able to get info about the db as a hash" do
|
84
|
-
@c.info do |r|
|
85
|
-
r.should.key? :redis_version
|
86
|
-
done
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
should "be able to save db" do
|
91
|
-
@c.save do |r|
|
92
|
-
r.should == "OK"
|
93
|
-
done
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
should "be able to save db in the background" do
|
98
|
-
@c.bgsave do |r|
|
99
|
-
r.should == "Background saving started"
|
100
|
-
done
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
end
|
105
|
-
|
106
|
-
EM.describe EM::Protocols::Redis, "connected to a db containing some simple string-valued keys" do
|
107
|
-
|
108
|
-
before do
|
109
|
-
@c = EM::Protocols::Redis.connect :db => 14
|
110
|
-
@c.flushdb
|
111
|
-
@c.set "a", "b"
|
112
|
-
@c.set "x", "y"
|
113
|
-
end
|
114
|
-
|
115
|
-
should "be able to fetch the values of multiple keys" do
|
116
|
-
@c.mget "a", "x" do |r|
|
117
|
-
r.should == ["b", "y"]
|
118
|
-
done
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
should "be able to fetch the values of multiple keys in a hash" do
|
123
|
-
@c.mapped_mget "a", "x" do |r|
|
124
|
-
r.should == {"a" => "b", "x" => "y"}
|
125
|
-
done
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
should "be able to fetch all the keys" do
|
130
|
-
@c.keys "*" do |r|
|
131
|
-
r.sort.should == ["a", "x"]
|
132
|
-
done
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
should "be able to set a value if a key doesn't exist" do
|
137
|
-
@c.setnx "a", "foo" do |r|
|
138
|
-
r.should == false
|
139
|
-
@c.setnx "zzz", "foo" do |r|
|
140
|
-
r.should == true
|
141
|
-
done
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
should "be able to test for the existence of a key" do
|
147
|
-
@c.exists "a" do |r|
|
148
|
-
r.should == true
|
149
|
-
@c.exists "zzz" do |r|
|
150
|
-
r.should == false
|
151
|
-
done
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
should "be able to delete a key" do
|
157
|
-
@c.del "a" do |r|
|
158
|
-
r.should == true
|
159
|
-
@c.exists "a" do |r|
|
160
|
-
r.should == false
|
161
|
-
@c.del "a" do |r|
|
162
|
-
r.should == false
|
163
|
-
done
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
should "be able to detect the type of a key, existing or not" do
|
170
|
-
@c.type "a" do |r|
|
171
|
-
r.should == "string"
|
172
|
-
@c.type "zzz" do |r|
|
173
|
-
r.should == "none"
|
174
|
-
done
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
should "be able to rename a key" do
|
180
|
-
@c.rename "a", "x" do |r|
|
181
|
-
@c.get "x" do |r|
|
182
|
-
r.should == "b"
|
183
|
-
done
|
184
|
-
end
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
should "be able to rename a key unless it exists" do
|
189
|
-
@c.renamenx "a", "x" do |r|
|
190
|
-
r.should == false
|
191
|
-
@c.renamenx "a", "zzz" do |r|
|
192
|
-
r.should == true
|
193
|
-
@c.get "zzz" do |r|
|
194
|
-
r.should == "b"
|
195
|
-
done
|
196
|
-
end
|
197
|
-
end
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
|
202
|
-
end
|
203
|
-
|
204
|
-
EM.describe EM::Protocols::Redis, "connected to a db containing a list" do
|
205
|
-
|
206
|
-
before do
|
207
|
-
@c = EM::Protocols::Redis.connect :db => 14
|
208
|
-
@c.flushdb
|
209
|
-
@c.lpush "foo", "c"
|
210
|
-
@c.lpush "foo", "b"
|
211
|
-
@c.lpush "foo", "a"
|
212
|
-
end
|
213
|
-
|
214
|
-
should "be able to 'lset' a list member and 'lindex' to retrieve it" do
|
215
|
-
@c.lset("foo", 1, "bar") do |r|
|
216
|
-
@c.lindex("foo", 1) do |r|
|
217
|
-
r.should == "bar"
|
218
|
-
done
|
219
|
-
end
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
should "be able to 'rpush' onto the tail of the list" do
|
224
|
-
@c.rpush "foo", "d" do |r|
|
225
|
-
r.should == 4
|
226
|
-
@c.rpop "foo" do |r|
|
227
|
-
r.should == "d"
|
228
|
-
done
|
229
|
-
end
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
should "be able to 'lpush' onto the head of the list" do
|
234
|
-
@c.lpush "foo", "d" do |r|
|
235
|
-
r.should == 4
|
236
|
-
@c.lpop "foo" do |r|
|
237
|
-
r.should == "d"
|
238
|
-
done
|
239
|
-
end
|
240
|
-
end
|
241
|
-
end
|
242
|
-
|
243
|
-
should "be able to 'rpop' off the tail of the list" do
|
244
|
-
@c.rpop("foo") do |r|
|
245
|
-
r.should == "c"
|
246
|
-
done
|
247
|
-
end
|
248
|
-
end
|
249
|
-
|
250
|
-
should "be able to 'lpop' off the tail of the list" do
|
251
|
-
@c.lpop("foo") do |r|
|
252
|
-
r.should == "a"
|
253
|
-
done
|
254
|
-
end
|
255
|
-
end
|
256
|
-
|
257
|
-
should "be able to get a range of values from a list" do
|
258
|
-
@c.lrange("foo", 0, 1) do |r|
|
259
|
-
r.should == ["a", "b"]
|
260
|
-
done
|
261
|
-
end
|
262
|
-
end
|
263
|
-
|
264
|
-
should "be able to 'ltrim' a list" do
|
265
|
-
@c.ltrim("foo", 0, 1) do |r|
|
266
|
-
r.should == "OK"
|
267
|
-
@c.llen("foo") do |r|
|
268
|
-
r.should == 2
|
269
|
-
done
|
270
|
-
end
|
271
|
-
end
|
272
|
-
end
|
273
|
-
|
274
|
-
should "be able to 'rem' a list element" do
|
275
|
-
@c.lrem("foo", 0, "a") do |r|
|
276
|
-
r.should == 1
|
277
|
-
@c.llen("foo") do |r|
|
278
|
-
r.should == 2
|
279
|
-
done
|
280
|
-
end
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
|
-
should "be able to detect the type of a list" do
|
285
|
-
@c.type "foo" do |r|
|
286
|
-
r.should == "list"
|
287
|
-
done
|
288
|
-
end
|
289
|
-
end
|
290
|
-
|
291
|
-
end
|
292
|
-
|
293
|
-
EM.describe EM::Protocols::Redis, "connected to a db containing two sets" do
|
294
|
-
before do
|
295
|
-
@c = EM::Protocols::Redis.connect :db => 14
|
296
|
-
@c.flushdb
|
297
|
-
@c.sadd "foo", "a"
|
298
|
-
@c.sadd "foo", "b"
|
299
|
-
@c.sadd "foo", "c"
|
300
|
-
@c.sadd "bar", "c"
|
301
|
-
@c.sadd "bar", "d"
|
302
|
-
@c.sadd "bar", "e"
|
303
|
-
end
|
304
|
-
|
305
|
-
should "be able to find a set's cardinality" do
|
306
|
-
@c.scard("foo") do |r|
|
307
|
-
r.should == 3
|
308
|
-
done
|
309
|
-
end
|
310
|
-
end
|
311
|
-
|
312
|
-
should "be able to add a new member to a set unless it is a duplicate" do
|
313
|
-
@c.sadd("foo", "d") do |r|
|
314
|
-
r.should == true # success
|
315
|
-
@c.sadd("foo", "a") do |r|
|
316
|
-
r.should == false # failure
|
317
|
-
@c.scard("foo") do |r|
|
318
|
-
r.should == 4
|
319
|
-
done
|
320
|
-
end
|
321
|
-
end
|
322
|
-
end
|
323
|
-
end
|
324
|
-
|
325
|
-
should "be able to remove a set member if it exists" do
|
326
|
-
@c.srem("foo", "a") do |r|
|
327
|
-
r.should == true
|
328
|
-
@c.srem("foo", "z") do |r|
|
329
|
-
r.should == false
|
330
|
-
@c.scard("foo") do |r|
|
331
|
-
r.should == 2
|
332
|
-
done
|
333
|
-
end
|
334
|
-
end
|
335
|
-
end
|
336
|
-
end
|
337
|
-
|
338
|
-
should "be able to retrieve a set's members" do
|
339
|
-
@c.smembers("foo") do |r|
|
340
|
-
r.sort.should == ["a", "b", "c"]
|
341
|
-
done
|
342
|
-
end
|
343
|
-
end
|
344
|
-
|
345
|
-
should "be able to detect set membership" do
|
346
|
-
@c.sismember("foo", "a") do |r|
|
347
|
-
r.should == true
|
348
|
-
@c.sismember("foo", "z") do |r|
|
349
|
-
r.should == false
|
350
|
-
done
|
351
|
-
end
|
352
|
-
end
|
353
|
-
end
|
354
|
-
|
355
|
-
should "be able to find the sets' intersection" do
|
356
|
-
@c.sinter("foo", "bar") do |r|
|
357
|
-
r.should == ["c"]
|
358
|
-
done
|
359
|
-
end
|
360
|
-
end
|
361
|
-
|
362
|
-
should "be able to find and store the sets' intersection" do
|
363
|
-
@c.sinterstore("baz", "foo", "bar") do |r|
|
364
|
-
r.should == 1
|
365
|
-
@c.smembers("baz") do |r|
|
366
|
-
r.should == ["c"]
|
367
|
-
done
|
368
|
-
end
|
369
|
-
end
|
370
|
-
end
|
371
|
-
|
372
|
-
should "be able to find the sets' union" do
|
373
|
-
@c.sunion("foo", "bar") do |r|
|
374
|
-
r.sort.should == ["a","b","c","d","e"]
|
375
|
-
done
|
376
|
-
end
|
377
|
-
end
|
378
|
-
|
379
|
-
should "be able to find and store the sets' union" do
|
380
|
-
@c.sunionstore("baz", "foo", "bar") do |r|
|
381
|
-
r.should == 5
|
382
|
-
@c.smembers("baz") do |r|
|
383
|
-
r.sort.should == ["a","b","c","d","e"]
|
384
|
-
done
|
385
|
-
end
|
386
|
-
end
|
387
|
-
end
|
388
|
-
|
389
|
-
should "be able to detect the type of a set" do
|
390
|
-
@c.type "foo" do |r|
|
391
|
-
r.should == "set"
|
392
|
-
done
|
393
|
-
end
|
394
|
-
end
|
395
|
-
|
396
|
-
end
|
397
|
-
|
398
|
-
|
399
|
-
EM.describe EM::Protocols::Redis, "connected to a db containing three linked lists" do
|
400
|
-
before do
|
401
|
-
@c = EM::Protocols::Redis.connect :db => 14
|
402
|
-
@c.flushdb
|
403
|
-
@c.rpush "foo", "a"
|
404
|
-
@c.rpush "foo", "b"
|
405
|
-
@c.set "a_sort", "2"
|
406
|
-
@c.set "b_sort", "1"
|
407
|
-
@c.set "a_data", "foo"
|
408
|
-
@c.set "b_data", "bar"
|
409
|
-
end
|
410
|
-
|
411
|
-
should "be able to collate a sorted set of data" do
|
412
|
-
@c.sort("foo", :by => "*_sort", :get => "*_data") do |r|
|
413
|
-
r.should == ["bar", "foo"]
|
414
|
-
done
|
415
|
-
end
|
416
|
-
end
|
417
|
-
|
418
|
-
should "be able to get keys selectively" do
|
419
|
-
@c.keys "a_*" do |r|
|
420
|
-
r.should == ["a_sort", "a_data"].sort
|
421
|
-
done
|
422
|
-
end
|
423
|
-
end
|
424
|
-
end
|
425
|
-
|
426
|
-
EM.describe EM::Protocols::Redis, "when reconnecting" do
|
427
|
-
before do
|
428
|
-
@c = EM::Protocols::Redis.connect :db => 14
|
429
|
-
@c.flushdb
|
430
|
-
end
|
431
|
-
|
432
|
-
should "select previously selected datase" do
|
433
|
-
#simulate disconnect
|
434
|
-
@c.set('foo', 'a') { @c.close_connection_after_writing }
|
435
|
-
|
436
|
-
EM.add_timer(2) do
|
437
|
-
@c.get('foo') do |r|
|
438
|
-
r.should == 'a'
|
439
|
-
@c.get('non_existing') do |r|
|
440
|
-
r.should == nil
|
441
|
-
done
|
442
|
-
end
|
443
|
-
end
|
444
|
-
end
|
445
|
-
end
|
446
|
-
end
|