em-redis 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,6 @@
1
+ == 0.2.2 / 2009-12-29
2
+ * reselect database after reconnecting
3
+
1
4
  == 0.2.1 / 2009-12-15
2
5
  * updated gem dependencies
3
6
 
@@ -17,5 +20,3 @@
17
20
 
18
21
  * initial release
19
22
  * compatible with Redis 0.093
20
-
21
-
@@ -13,13 +13,12 @@ parallelization without threads.
13
13
 
14
14
  == FEATURES/PROBLEMS:
15
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 and AUTH
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
18
 
19
19
  == SYNOPSIS:
20
20
 
21
- * Like any Deferrable eventmachine-based protocol implementation, using EM-Redis involves making calls and passing blocks that serve as callbacks when
22
- the call returns.
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.
23
22
 
24
23
  require 'em-redis'
25
24
 
@@ -34,11 +33,11 @@ the call returns.
34
33
  end
35
34
  end
36
35
 
37
- * To run live tests on a Redis server (currently compatible with 1.02)
38
-
36
+ To run live tests on a Redis server (currently compatible with 1.3)
37
+
39
38
  rake redis:live_test
40
39
 
41
- * To run a test of the underlying protocol implemention
40
+ To run a test of the underlying protocol implemention
42
41
 
43
42
  rake redis:offline_test
44
43
 
@@ -51,7 +50,7 @@ currently in the form of bacon specs. I'll port them to RSpec at some point.
51
50
 
52
51
  == INSTALL:
53
52
 
54
- * sudo gem install em-redis
53
+ sudo gem install em-redis
55
54
 
56
55
  == LICENSE:
57
56
 
data/Rakefile CHANGED
@@ -15,8 +15,8 @@ task :default => ['redis:live_test', 'redis:offline_test']
15
15
 
16
16
  Bones {
17
17
  name 'em-redis'
18
- authors 'Jonathan Broad'
19
- email 'jonathan@relativepath.org'
18
+ authors ['Jonathan Broad', 'Eugene Pimenov']
19
+ email 'libc@me.com'
20
20
  url ''
21
21
  version EMRedis::VERSION
22
22
 
@@ -2,7 +2,7 @@
2
2
  module EMRedis
3
3
 
4
4
  # :stopdoc:
5
- VERSION = '0.2.1'
5
+ VERSION = '0.2.2'
6
6
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
7
7
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
8
8
  # :startdoc:
@@ -154,10 +154,6 @@ module EventMachine
154
154
  "sync" => true
155
155
  }
156
156
 
157
- def [](key)
158
- self.get(key)
159
- end
160
-
161
157
  def []=(key,value)
162
158
  set(key,value)
163
159
  end
@@ -187,6 +183,16 @@ module EventMachine
187
183
  call_command(decrement ? ["decrby",key,decrement] : ["decr",key], &blk)
188
184
  end
189
185
 
186
+ def select(db, &blk)
187
+ @current_database = db
188
+ call_command(['select', db], &blk)
189
+ end
190
+
191
+ def auth(password, &blk)
192
+ @current_password = password
193
+ call_command(['auth', password], &blk)
194
+ end
195
+
190
196
  # Similar to memcache.rb's #get_multi, returns a hash mapping
191
197
  # keys to values.
192
198
  def mapped_mget(*keys)
@@ -389,7 +395,11 @@ module EventMachine
389
395
  def unbind
390
396
  puts "*** unbinding" if $debug
391
397
  if @connected or @reconnecting
392
- EM.add_timer(1){ reconnect @host, @port }
398
+ EM.add_timer(1) do
399
+ reconnect @host, @port
400
+ auth @current_password if @current_password
401
+ select @current_database if @current_database
402
+ end
393
403
  @connected = false
394
404
  @reconnecting = true
395
405
  @deferred_status = nil
@@ -97,12 +97,11 @@ EM.describe EM::Protocols::Redis, "connected to an empty db" do
97
97
 
98
98
  should "be able to save db in the background" do
99
99
  @c.bgsave do |r|
100
- r.should == "OK"
100
+ r.should == "Background saving started"
101
101
  done
102
102
  end
103
103
  end
104
104
 
105
-
106
105
  end
107
106
 
108
107
  EM.describe EM::Protocols::Redis, "connected to a db containing some simple string-valued keys" do
@@ -122,6 +121,13 @@ EM.describe EM::Protocols::Redis, "connected to a db containing some simple stri
122
121
  end
123
122
  end
124
123
 
124
+ should "be able to fetch the values of multiple keys in a hash" do
125
+ @c.mapped_mget "a", "x" do |r|
126
+ r.should == {"a" => "b", "x" => "y"}
127
+ done
128
+ end
129
+ end
130
+
125
131
  should "be able to fetch all the keys" do
126
132
  @c.keys "*" do |r|
127
133
  r.sort.should == ["a", "x"]
@@ -421,3 +427,26 @@ EM.describe EM::Protocols::Redis, "connected to a db containing three linked lis
421
427
  end
422
428
  end
423
429
  end
430
+
431
+ EM.describe EM::Protocols::Redis, "when reconnecting" do
432
+ before do
433
+ @c = EM::Protocols::Redis.connect
434
+ @c.select "14"
435
+ @c.flushdb
436
+ end
437
+
438
+ should "select previously selected datase" do
439
+ #simulate disconnect
440
+ @c.set('foo', 'a') { @c.close_connection_after_writing }
441
+
442
+ EM.add_timer(2) do
443
+ @c.get('foo') do |r|
444
+ r.should == 'a'
445
+ @c.get('non_existing') do |r|
446
+ r.should == nil
447
+ done
448
+ end
449
+ end
450
+ end
451
+ end
452
+ end
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Broad
8
+ - Eugene Pimenov
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
12
 
12
- date: 2009-12-15 00:00:00 +03:00
13
+ date: 2009-12-29 00:00:00 +03:00
13
14
  default_executable:
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
@@ -60,7 +61,7 @@ description: |-
60
61
  Event Machine's event loop. It implements an EM-based client protocol, which
61
62
  leverages the non-blocking nature of the EM interface to achieve significant
62
63
  parallelization without threads.
63
- email: jonathan@relativepath.org
64
+ email: libc@me.com
64
65
  executables: []
65
66
 
66
67
  extensions: []
@@ -75,7 +76,6 @@ files:
75
76
  - Manifest.txt
76
77
  - README.rdoc
77
78
  - Rakefile
78
- - em-redis.gemspec
79
79
  - lib/em-redis.rb
80
80
  - lib/em-redis/redis_protocol.rb
81
81
  - spec/live_redis_protocol_spec.rb
@@ -1,47 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- Gem::Specification.new do |s|
4
- s.name = %q{em-redis}
5
- s.version = "0.2"
6
-
7
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Jonathan Broad"]
9
- s.date = %q{2009-12-15}
10
- s.description = %q{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.
11
- 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).
12
-
13
- This library is only useful when used as part of an application that relies on
14
- Event Machine's event loop. It implements an EM-based client protocol, which
15
- leverages the non-blocking nature of the EM interface to achieve significant
16
- parallelization without threads.}
17
- s.email = %q{jonathan@relativepath.org}
18
- s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc"]
19
- s.files = [".gitignore", "History.txt", "Manifest.txt", "README.rdoc", "Rakefile", "em-redis.gemspec", "lib/em-redis.rb", "lib/em-redis/redis_protocol.rb", "spec/live_redis_protocol_spec.rb", "spec/redis_protocol_spec.rb", "spec/test_helper.rb", "tasks/em-redis.rake"]
20
- s.rdoc_options = ["--main", "README.rdoc"]
21
- s.require_paths = ["lib"]
22
- s.rubyforge_project = %q{em-redis}
23
- s.rubygems_version = %q{1.3.5}
24
- s.summary = %q{An EventMachine[http://rubyeventmachine}
25
-
26
- if s.respond_to? :specification_version then
27
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
28
- s.specification_version = 3
29
-
30
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
31
- s.add_runtime_dependency(%q<eventmachine>, [">= 0.12.10"])
32
- s.add_development_dependency(%q<bacon>, [">= 1.1.0"])
33
- s.add_development_dependency(%q<em-spec>, [">= 0.2.0"])
34
- s.add_development_dependency(%q<bones>, [">= 3.2.0"])
35
- else
36
- s.add_dependency(%q<eventmachine>, [">= 0.12.10"])
37
- s.add_dependency(%q<bacon>, [">= 1.1.0"])
38
- s.add_dependency(%q<em-spec>, [">= 0.2.0"])
39
- s.add_dependency(%q<bones>, [">= 3.2.0"])
40
- end
41
- else
42
- s.add_dependency(%q<eventmachine>, [">= 0.12.10"])
43
- s.add_dependency(%q<bacon>, [">= 1.1.0"])
44
- s.add_dependency(%q<em-spec>, [">= 0.2.0"])
45
- s.add_dependency(%q<bones>, [">= 3.2.0"])
46
- end
47
- end