redis-spawn 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -161,13 +161,49 @@ At present, there is no built in mechanism for cleaning up the data directory
161
161
  This allows you to prevent the server from automatically being started, e.g.
162
162
 
163
163
  ```ruby
164
- # Don't want to start striaght away
165
- my_server = Redis::SpawnServer(:start => false)
164
+ # Don't want to start straight away
165
+ my_server = Redis::SpawnServer.new(:start => false)
166
166
  # ...
167
167
  # Now we're ready to start
168
168
  my_server.start
169
169
  ```
170
170
 
171
+ ### Extensions to redis-rb
172
+
173
+ Three new methods are defined in the Redis class: Redis.spawn,
174
+ Redis.spawn_and_connect, and Redis#spawned_server_instance. Redis.spawn is
175
+ simply a convenience wrapper for Redis::SpawnServer.new:
176
+
177
+ ```ruby
178
+ my_server = Redis.spawn(opts)
179
+ ```
180
+
181
+ is the same as the slightly more verbose:
182
+
183
+ ```ruby
184
+ my_server = Redis::SpawnServer.new(opts)
185
+ ```
186
+
187
+ Redis.spawn_and_connect spawns a new server and returns a connection to it:
188
+
189
+ ```ruby
190
+ spawned_connection = Redis.spawn_and_connect
191
+ => #<Redis:0x00000002d5e470>
192
+ ```
193
+
194
+ The method takes the same option parameters as Redis::SpawnServer.new. One
195
+ question you might ask is since you're returned a Redis instance, what
196
+ happens to the Redis:SpawnServer instance? The answer is that it is stored
197
+ in the Redis instance, and you can get it through the
198
+ Redis#spawned_server_instance accessor:
199
+
200
+ ```ruby
201
+ spawned_connection.spawned_server_instance
202
+ => #<Redis::SpawnServer:0x00000002683290>
203
+ spawned_connection.spawned_server_instance.pid
204
+ => 10633
205
+ ````
206
+
171
207
  Contact and Contributing
172
208
  ------------------------
173
209
 
@@ -1,5 +1,5 @@
1
1
  class Redis
2
2
  class SpawnServer
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
data/lib/redis/spawn.rb CHANGED
@@ -125,10 +125,12 @@ class Redis
125
125
  self.pid
126
126
  end
127
127
 
128
+ # Check whether the server is stated by checking if a value is assigned to @pid
128
129
  def started?
129
130
  self.pid ? true : false
130
131
  end
131
132
 
133
+ # Shutdown the spawned redis-server if it is running
132
134
  def shutdown
133
135
  if self.started?
134
136
  self.shutdown!
@@ -137,6 +139,7 @@ class Redis
137
139
  end
138
140
  end
139
141
 
142
+ # Forcibly shutdown the spawned redis-server. Used internally by #shutdown.
140
143
  def shutdown!
141
144
  Process.kill("TERM", self.pid)
142
145
  rescue Errno::ESRCH
@@ -205,9 +208,42 @@ class Redis
205
208
  end
206
209
  end
207
210
 
211
+ # Shortcut for getting name of the configured unix socket file
208
212
  def socket
209
213
  self.server_opts[:unixsocket]
210
214
  end
211
215
 
212
216
  end
217
+
218
+ # Convenience wrapper for Redis::SpawnServer.new
219
+ #
220
+ # @param supplied_opts: options for this server including any configuration overrides
221
+ #
222
+ # @return [Redis::SpawnServer] instance corresponding to the spawned server
223
+ def self.spawn(supplied_opts = {})
224
+ SpawnServer.new(supplied_opts)
225
+ end
226
+
227
+ # Spawn a new redis-server with supplied options and connect to it. Has the
228
+ # side-effect of setting instance variable @_redis_spawnserver_instance with
229
+ # the spawned server instance
230
+ #
231
+ # @param supplied_opts: options for this server including any configuration overrides
232
+ #
233
+ # @return [Redis] a redis-rb connection to the newly spawned redis-server
234
+ def self.spawn_and_connect(supplied_opts = {})
235
+ redis_spawnserver_instance = SpawnServer.new(supplied_opts)
236
+ redis_instance = self.connect(:path => redis_spawnserver_instance.socket)
237
+ redis_instance.instance_variable_set(:@_redis_spawnserver_instance, redis_spawnserver_instance)
238
+ redis_instance
239
+ end
240
+
241
+ # Accessor for the spawned server instance created by Redis.spawn_and_connect
242
+ def spawned_server_instance
243
+ if self.instance_variables.include?(:@_redis_spawnserver_instance)
244
+ @_redis_spawnserver_instance
245
+ else
246
+ nil
247
+ end
248
+ end
213
249
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Phil Stewart
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-10-29 00:00:00 +01:00
17
+ date: 2011-11-08 00:00:00 +00:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency