redis_backend 0.0.1

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.
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .vimrc
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ vendor
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in redis_backend.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Cristian R. Arroyo
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.
@@ -0,0 +1,49 @@
1
+ # RedisBackend
2
+
3
+ On the vein of the simplest-possible yet-functional Gem you could possibly release, this is a convenient way to "wrap" your Redis calls on a block that will be gracefully ignored if there is no database connection established yet:
4
+
5
+ module Collectable
6
+ extend RedisBackend
7
+
8
+ def self.ready_to_collect?
9
+ available? # $redis global variable holds the Redis DB connection
10
+ end
11
+
12
+ def self.all(which)
13
+ backend do |redis|
14
+ redis.smembers(which)
15
+ end
16
+ end
17
+ end
18
+
19
+ All you need to do is set the environment variables `REDIS_SERVER` and `REDIS_AUTH` (optional) to the host and the password required to execute any command.
20
+
21
+ ## Installation
22
+
23
+ Add this line to your application's Gemfile:
24
+
25
+ gem 'redis_backend'
26
+
27
+ And then execute:
28
+
29
+ $ bundle
30
+
31
+ Or install it yourself as:
32
+
33
+ $ gem install redis_backend
34
+
35
+ ## Contributing
36
+
37
+ 1. Fork it
38
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
39
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
40
+ 4. Push to the branch (`git push origin my-new-feature`)
41
+ 5. Create new Pull Request
42
+
43
+ ## License
44
+
45
+ Released under the [MIT License](http://www.opensource.org/licenses/MIT).
46
+
47
+ ## Copyright
48
+
49
+ (c)2015 [Cristian R. Arroyo](mailto:cristian.arroyo@vivaserver.com)
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ # ref: http://rpheath.com/posts/394-get-the-most-out-of-test-unit
5
+ # ref: http://stackoverflow.com/a/8395163
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.verbose = false
8
+ t.pattern = 'spec/*_spec.rb'
9
+ end
10
+ Rake::Task['test'].comment = 'no hands!'
11
+ task :default => [:test]
@@ -0,0 +1,32 @@
1
+ require "redis_backend/version"
2
+ require 'rubygems'
3
+ require 'bundler/setup'
4
+ require 'redis'
5
+
6
+ if ENV['REDIS_SERVER']
7
+ begin
8
+ $redis = Redis.new(:host => ENV['REDIS_SERVER'])
9
+ $redis.auth(ENV['REDIS_AUTH']) if ENV['REDIS_AUTH']
10
+ rescue Redis::CannotConnectError, Redis::TimeoutError
11
+ # unsetted $redis will disable backend support
12
+ end
13
+ end
14
+
15
+ module RedisBackend
16
+ def available?
17
+ true if $redis
18
+ end
19
+
20
+ def backend
21
+ yield $redis if available?
22
+ rescue => e
23
+ case e
24
+ when Redis::CommandError
25
+ # TODO: reconnect?
26
+ when Redis::TimeoutError, Redis::CannotConnectError
27
+ # fallback to live request?
28
+ else
29
+ raise e
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module RedisBackend
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'redis_backend/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "redis_backend"
8
+ spec.version = RedisBackend::VERSION
9
+ spec.authors = ["Cristian R. Arroyo"]
10
+ spec.email = ["cristian.arroyo@vivaserver.com"]
11
+ spec.description = %q{Protect operations from Redis backend unavailability gracefully}
12
+ spec.summary = %q{Protect operations from Redis backend unavailability gracefully}
13
+ spec.homepage = "https://github.com/vivaserver/redis_backend"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency 'redis'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ end
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'redis_backend'
3
+
4
+ require 'minitest/autorun'
@@ -0,0 +1,17 @@
1
+ require_relative 'minitest_helper'
2
+
3
+ describe RedisBackend do
4
+ it 'exists' do
5
+ assert RedisBackend
6
+ end
7
+
8
+ if ENV['REDIS_SERVER']
9
+ it 'is available' do
10
+ assert $redis
11
+ end
12
+ else
13
+ it 'is not available' do
14
+ refute $redis
15
+ end
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redis_backend
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Cristian R. Arroyo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-06-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ prerelease: false
16
+ name: redis
17
+ type: :runtime
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ none: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ! '>='
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ none: false
30
+ - !ruby/object:Gem::Dependency
31
+ prerelease: false
32
+ name: bundler
33
+ type: :development
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: '1.3'
39
+ none: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: '1.3'
45
+ none: false
46
+ - !ruby/object:Gem::Dependency
47
+ prerelease: false
48
+ name: rake
49
+ type: :development
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ none: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ none: false
62
+ description: Protect operations from Redis backend unavailability gracefully
63
+ email:
64
+ - cristian.arroyo@vivaserver.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - lib/redis_backend.rb
75
+ - lib/redis_backend/version.rb
76
+ - redis_backend.gemspec
77
+ - spec/minitest_helper.rb
78
+ - spec/redis_backend_spec.rb
79
+ homepage: https://github.com/vivaserver/redis_backend
80
+ licenses:
81
+ - MIT
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ segments:
91
+ - 0
92
+ hash: -4356408551907309796
93
+ version: '0'
94
+ none: false
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ segments:
100
+ - 0
101
+ hash: -4356408551907309796
102
+ version: '0'
103
+ none: false
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 1.8.23.2
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: Protect operations from Redis backend unavailability gracefully
110
+ test_files:
111
+ - spec/minitest_helper.rb
112
+ - spec/redis_backend_spec.rb