redis-cluster-activesupport 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 41a552daa168903056def19dfee44dbb70ced2b1
4
+ data.tar.gz: f62493d655a4e333afd44a6b83558a416bc83eb3
5
+ SHA512:
6
+ metadata.gz: 7a93ea6b63fd8193ec17d85870b8bed1d3fa90dc6b32b2ba237d86b47e5de477900c467b769a5bd496898406c6f2c53a8daea9d649b4ff891e0929db016394ac
7
+ data.tar.gz: a15320ac7087fbecd4f3390e6cec06925d8dc582e3269a174f5b9dd58a4b9b3581d1c4c93c5cec5ec267952b3ea156665f63d500943e9be7f8254d539bebca63
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.4
4
+ - 2.3
5
+ sudo: false
6
+ cache: bundler
7
+ notifications:
8
+ email:
9
+ on_success: never
10
+ on_failure: always
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in redis-cluster-activesupport.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Garrett Thornburg
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,71 @@
1
+ # Redis cluster stores for ActiveSupport [![Build Status](https://travis-ci.org/film42/redis-cluster-activesupport.svg?branch=master)](https://travis-ci.org/film42/redis-cluster-activesupport)
2
+
3
+ This gem is an extension to [redis-activesupport](https://github.com/redis-store/redis-activesupport) that adds support
4
+ for a few features required to use `redis-store` with redis cluster. Right now there isn't an official redis cluster
5
+ client in ruby, so it's become common to use a redis cluster proxy like [corvus](https://github.com/eleme/corvus). When
6
+ switching there are a few things you can't do with redis cluster that you can do with a single redis server. Most of
7
+ them revolve around issuing commands with multiple keys. In redis cluster, your keys are partitioned and live on
8
+ different physical servers, operations like `KEYS` are not possible. Corvus will break apart `MSET` and `MGET` into
9
+ individual `GET` and `SET` commands automatically, but in general, it's not a good idea to use them.
10
+
11
+ ## Usage
12
+
13
+ This gem is a small extension to `redis-activesupport`, so refer to their documentation for most configuration. Instead
14
+ of specifying `:redis_store` you must now specify `:redis_cluster_store` to load this extension.
15
+
16
+ ```ruby
17
+ module MyProject
18
+ class Application < Rails::Application
19
+ config.cache_store = :redis_cluster_store, options
20
+ end
21
+ end
22
+ ```
23
+
24
+ Additionally, there's a new configuration option: `:ignored_command_errors`. This is useful if you're using a redis
25
+ cluster proxy like corvus who will raise a `Redis::CommandError` with a message indicating the cluster is offline or
26
+ experiencing a partial outage. This extension allows you to whitelist certain `ignored_command_errors` that would
27
+ normally be raised by `redis-activesupport`. By default this gem whitelists the following errors:
28
+
29
+ ```ruby
30
+ DEFAULT_IGNORED_COMMAND_ERRORS = ["ERR Proxy error"]
31
+ ```
32
+
33
+ If you need additional errors added to the whitelist, you can do this through your own configuration or open a pull
34
+ request to add it to the default whitelist. NOTE: this list is turned into a `Set` to keep lookups fast, so feel free to
35
+ make this list as big as you need. Example:
36
+
37
+ ```ruby
38
+ module MyProject
39
+ class Application < Rails::Application
40
+ config.cache_store = :redis_cluster_store, {:ignored_command_errors => ["Uh oh", "Please, stop", "Fire emoji"]}
41
+ end
42
+ end
43
+ ```
44
+
45
+ With this change, your cache store will now silently fail once again so a redis cluster won't knock your rails apps
46
+ offline.
47
+
48
+
49
+ ## Installation
50
+
51
+ Add this line to your application's Gemfile:
52
+
53
+ ```ruby
54
+ gem "redis-cluster-activesupport"
55
+ ```
56
+
57
+ And then execute:
58
+
59
+ $ bundle
60
+
61
+ Or install it yourself as:
62
+
63
+ $ gem install redis-cluster-activesupport
64
+
65
+ ## Contributing
66
+
67
+ Bug reports and pull requests are welcome on GitHub at https://github.com/film42/redis-cluster-activesupport.
68
+
69
+ ## License
70
+
71
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "redis/activesupport/cluster"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,49 @@
1
+ require "redis-activesupport"
2
+ require "set"
3
+
4
+ module ActiveSupport
5
+ module Cache
6
+ class RedisClusterStore < RedisStore
7
+ attr_reader :ignored_command_errors
8
+
9
+ DEFAULT_IGNORED_COMMAND_ERRORS = ["ERR Proxy error"].freeze
10
+
11
+ def initialize(*)
12
+ super
13
+ @ignored_command_errors = ::Set.new(@options.fetch(:ignored_command_errors, DEFAULT_IGNORED_COMMAND_ERRORS))
14
+ end
15
+
16
+ def delete_entry(key, options)
17
+ super
18
+ rescue Redis::CommandError => error
19
+ raise unless ignored_command_errors.include?(error.message)
20
+ raise if raise_errors?
21
+ false
22
+ end
23
+
24
+ def delete_matched(matcher, options = nil)
25
+ fail ::NotImplementedError, "Deleting keys with a matcher is not supported with redis cluster"
26
+ end
27
+
28
+ def fetch_multi(*names)
29
+ fail ::NotImplementedError, "The default implementation uses MULTI which isn't supported. This can be changed to use MSET and work."
30
+ end
31
+
32
+ def read_entry(key, options)
33
+ super
34
+ rescue Redis::CommandError => error
35
+ raise unless ignored_command_errors.include?(error.message)
36
+ raise if raise_errors?
37
+ nil
38
+ end
39
+
40
+ def write_entry(key, entry, options)
41
+ super
42
+ rescue Redis::CommandError => error
43
+ raise unless ignored_command_errors.include?(error.message)
44
+ raise if raise_errors?
45
+ false
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1 @@
1
+ require "active_support/cache/redis_cluster_store"
@@ -0,0 +1,27 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "redis-cluster-activesupport"
6
+ spec.version = "0.1.0"
7
+ spec.authors = ["Garrett Thornburg"]
8
+ spec.email = ["film42@gmail.com"]
9
+
10
+ spec.summary = "Extension to redis-activesupport for working with redis cluster"
11
+ spec.description = "Extension to redis-activesupport for working with redis cluster"
12
+ spec.homepage = "https://github.com/film42/redis-cluster-activesupport"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "redis-activesupport"
23
+ spec.add_development_dependency "pry"
24
+ spec.add_development_dependency "bundler", "~> 1.15"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redis-cluster-activesupport
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Garrett Thornburg
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: redis-activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.15'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.15'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: Extension to redis-activesupport for working with redis cluster
84
+ email:
85
+ - film42@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/active_support/cache/redis_cluster_store.rb
100
+ - lib/redis/cluster/activesupport.rb
101
+ - redis-cluster-activesupport.gemspec
102
+ homepage: https://github.com/film42/redis-cluster-activesupport
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.5.2
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Extension to redis-activesupport for working with redis cluster
126
+ test_files: []