redis_gun 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in redis_gun.gemspec
4
+ gemspec
5
+
6
+ gem 'awesome_print', '~> 1.0.2'
7
+ gem 'pry', '~> 0.9.10'
8
+ gem 'redis', '~> 3.0.1'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Gerhard Lazu
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # RedisGun
2
+
3
+ For when you need many unique redis-server instances.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'redis_gun'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install redis_gun
18
+
19
+ ## Usage
20
+
21
+ See the **examples** directory.
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'awesome_print'
5
+ require 'pry'
6
+ require 'redis'
7
+ require 'redis/distributed'
8
+ require 'redis_gun'
9
+
10
+ def exemplify(description, object)
11
+ puts "\n::: #{description} ".ljust(70, ":::")
12
+ ap(object, indent: -2)
13
+ end
14
+
15
+ r = RedisGun::RedisServer.new
16
+ exemplify("Start 1 redis server", r)
17
+ r.stop
18
+
19
+ redii = 10.times.inject([]) do |result|
20
+ result << RedisGun::RedisServer.new
21
+ end
22
+ exemplify("Start 10 redis servers", redii)
23
+ exemplify("Stop all 10 redis servers", redii.map(&:stop))
data/lib/redis_gun.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "redis_gun/version"
2
+ require "redis_gun/redis_server"
3
+
4
+ module RedisGun
5
+ end
@@ -0,0 +1,67 @@
1
+ require 'securerandom'
2
+
3
+ module RedisGun
4
+ class RedisServer
5
+ attr_reader :config
6
+
7
+ def initialize(custom_config={})
8
+ @uuid = SecureRandom.uuid
9
+
10
+ @config = {
11
+ :daemonize => "yes",
12
+ :pidfile => "/tmp/redis-server.#{@uuid}.pid",
13
+ :port => 0,
14
+ :unixsocket => "/tmp/redis-server.#{@uuid}.sock",
15
+ :loglevel => "notice",
16
+ :logfile => "stdout",
17
+ :databases => 16,
18
+ }.merge(custom_config)
19
+
20
+ start
21
+ end
22
+
23
+ def inline_config
24
+ config.collect { |k, v|
25
+ "#{k} #{v}"
26
+ }.join("\n")
27
+ end
28
+
29
+ def start
30
+ %x{echo "#{inline_config}" | redis-server -}
31
+ pid
32
+ end
33
+
34
+ def stop_redis_instance
35
+ Process.kill("QUIT", pid) if pid?
36
+ end
37
+
38
+ def cleanup_files
39
+ File.delete(config[:pidfile])
40
+ File.delete(config[:unixsocket])
41
+ end
42
+
43
+ def running?
44
+ %x{redis-cli -s #{config[:unixsocket]} PING 2>&1}.include?("PONG")
45
+ end
46
+
47
+ def stop
48
+ stop_redis_instance and
49
+ cleanup_files and
50
+ true
51
+ end
52
+
53
+ def socket
54
+ "unix://#{config[:unixsocket]}"
55
+ end
56
+
57
+ def pid?
58
+ File.exists?(config[:pidfile])
59
+ end
60
+
61
+ def pid
62
+ if pid?
63
+ File.read(config[:pidfile]).chomp.to_i
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,3 @@
1
+ module RedisGun
2
+ VERSION = "0.1.0"
3
+ end
data/redis_gun.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'redis_gun/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "redis_gun"
8
+ gem.version = RedisGun::VERSION
9
+ gem.authors = ["Gerhard Lazu"]
10
+ gem.email = ["gerhard@lazu.co.uk"]
11
+ gem.description = %q{Starts many redis-server instances quickly}
12
+ gem.summary = %q{For when you need many unique redis-server instances}
13
+ gem.homepage = "https://github.com/cambridge-healthcare/redis_gun"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redis_gun
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Gerhard Lazu
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-16 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Starts many redis-server instances quickly
15
+ email:
16
+ - gerhard@lazu.co.uk
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - examples/default.rb
27
+ - lib/redis_gun.rb
28
+ - lib/redis_gun/redis_server.rb
29
+ - lib/redis_gun/version.rb
30
+ - redis_gun.gemspec
31
+ homepage: https://github.com/cambridge-healthcare/redis_gun
32
+ licenses: []
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubyforge_project:
51
+ rubygems_version: 1.8.23
52
+ signing_key:
53
+ specification_version: 3
54
+ summary: For when you need many unique redis-server instances
55
+ test_files: []
56
+ has_rdoc: