redis-rb-global-config 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7f3a59e52b445fd9b97acc9d3edc71847fb5e1369860d1326d317592841d568f
4
+ data.tar.gz: 31145a4744087d53023073631470a584efc82a734ac4755fa535ff7c1737281e
5
+ SHA512:
6
+ metadata.gz: 50e23875b7c1c778164958bd1a18b0c30895b0415de3491b1b956978290510fa7ab78f80a530da17c2c27286a28057b8982c45a88470a8127e53cb6abd91e430
7
+ data.tar.gz: 23e6388bf8a6d7e9af721a68c8e92014029c2018814e3e5cab21ddc8f6a056654b181f2161112d0a9ca6adfd2ffc56243b06a81428847a3eba3e8c4e4249d21e
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format progress
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ inherit_gem:
2
+ rubocop-rails_config:
3
+ - config/rails.yml
4
+
5
+ Style/ClassAndModuleChildren:
6
+ EnforcedStyle: nested
7
+
8
+ Lint/Debugger:
9
+ Enabled: true
10
+
11
+ Style/StringLiterals:
12
+ Enabled: true
13
+ EnforcedStyle: single_quotes
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 sebi
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.
data/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # redis-rb-global-config ๐ŸŒŸ
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/redis-rb-global-config.svg)](https://badge.fury.io/rb/redis-rb-global-config)
4
+
5
+ Simplify your Redis configuration management across your Ruby applications! ๐Ÿš€
6
+
7
+ ## ๐ŸŽฏ Purpose
8
+
9
+ RedisRbGlobalConfig allows you to set default configurations for Redis connections across your Ruby application. This is particularly useful when you're using Redis for multiple purposes in a Rails application, such as:
10
+
11
+ - ๐Ÿš‚ Rails sessions
12
+ - ๐Ÿ—„๏ธ Caching on a separate database
13
+ - ๐Ÿงต Sidekiq for background jobs
14
+ - ๐Ÿ“ก ActionCable/AnyCable for real-time features
15
+
16
+ It also makes it easy to ensure all Redis connections use the high-performance Hiredis driver for improved speed! ๐Ÿ’จ
17
+
18
+ ## ๐Ÿ› ๏ธ Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ ```ruby
23
+ gem 'redis-rb-global-config'
24
+ ```
25
+
26
+ And then execute:
27
+
28
+ ```
29
+ $ bundle install
30
+ ```
31
+
32
+ Or install it yourself as:
33
+
34
+ ```
35
+ $ gem install redis-rb-global-config
36
+ ```
37
+
38
+ ## ๐Ÿš€ Usage
39
+
40
+ Here's how you can use RedisRbGlobalConfig in your application:
41
+
42
+ ```ruby
43
+ require 'redis-rb-global-config'
44
+
45
+ # Set global configuration
46
+ Redis.default_configuration = {
47
+ host: ENV['REDIS_HOST'] || 'localhost',
48
+ port: ENV['REDIS_PORT'] || 6379,
49
+ db: 0,
50
+ driver: :hiredis # Use the high-performance Hiredis driver
51
+ }
52
+
53
+ # Create Redis instances with specific configurations
54
+ redis_cache = Redis.new(db: 1)
55
+ redis_sessions = Redis.new(db: 2)
56
+ redis_sidekiq = Redis.new(db: 3)
57
+
58
+ # The global configuration is merged with the specific options
59
+ ```
60
+
61
+ ### ๐Ÿ”ง Rails Configuration Example
62
+
63
+ In your `config/initializers/redis.rb`:
64
+
65
+ ```ruby
66
+ require 'redis-rb-global-config'
67
+
68
+ Redis.default_configuration = {
69
+ host: ENV['REDIS_HOST'] || 'localhost',
70
+ port: ENV['REDIS_PORT'] || 6379,
71
+ driver: :hiredis
72
+ }
73
+
74
+ # Cache Store
75
+ Rails.application.config.cache_store = :redis_cache_store, { db: 1 }
76
+
77
+ # Action Cable
78
+ Rails.application.config.action_cable.backend = :redis
79
+ Rails.application.config.action_cable.url = "redis://localhost:6379/2"
80
+
81
+ # Sessions
82
+ Rails.application.config.session_store :redis_store,
83
+ servers: [{ db: 3 }],
84
+ expire_after: 90.minutes
85
+
86
+ # Sidekiq
87
+ Sidekiq.configure_server do |config|
88
+ config.redis = { db: 4 }
89
+ end
90
+
91
+ Sidekiq.configure_client do |config|
92
+ config.redis = { db: 4 }
93
+ end
94
+ ```
95
+
96
+ This setup ensures that all Redis connections use the same host and port, and all benefit from the Hiredis driver, while still allowing you to use different databases for different purposes.
97
+
98
+ ## ๐Ÿงช Development
99
+
100
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
101
+
102
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
103
+
104
+ ## ๐Ÿค Contributing
105
+
106
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sebyx07/redis-rb-global-config. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](CODE_OF_CONDUCT.md).
107
+
108
+ ## ๐Ÿ“œ License
109
+
110
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
111
+
112
+ ## ๐ŸŒˆ Code of Conduct
113
+
114
+ Everyone interacting in the RedisRbGlobalConfig project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RedisRbGlobalConfig
4
+ VERSION = '1.0.0'
5
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'redis'
4
+ require_relative './redis-rb-global-config/version'
5
+
6
+ module RedisRbGlobalConfig
7
+ def self.prepended(base)
8
+ class << base
9
+ attr_accessor :default_configuration
10
+ end
11
+ end
12
+
13
+ def initialize(options = {})
14
+ options = __configure_options(options)
15
+ super(options)
16
+ end
17
+
18
+ private
19
+ def __configure_options(options)
20
+ default_configuration = self.class.default_configuration
21
+ return options unless default_configuration
22
+
23
+ h_deep_merge(default_configuration, options)
24
+ end
25
+
26
+ def h_deep_merge(hash1, hash2)
27
+ result = hash1.dup
28
+ hash2.each do |key, value|
29
+ result[key] = if value.is_a?(Hash) && result[key].is_a?(Hash)
30
+ h_deep_merge(result[key], value)
31
+ else
32
+ value
33
+ end
34
+ end
35
+ result
36
+ end
37
+ end
38
+
39
+ Redis.prepend(RedisRbGlobalConfig)
@@ -0,0 +1,10 @@
1
+ module Redis
2
+ module Rb
3
+ module Global
4
+ module Config
5
+ VERSION: String
6
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
7
+ end
8
+ end
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redis-rb-global-config
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - sebi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-08-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: redis
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ description: RedisRbGlobalConfig allows you to set default configurations for Redis
28
+ connections across your Ruby application.
29
+ email:
30
+ - gore.sebyx@yahoo.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".rspec"
36
+ - ".rubocop.yml"
37
+ - LICENSE.txt
38
+ - README.md
39
+ - Rakefile
40
+ - lib/redis-rb-global-config.rb
41
+ - lib/redis-rb-global-config/version.rb
42
+ - sig/redis/rb/global/config.rbs
43
+ homepage: https://github.com/sebyx07/redis-rb-global-config
44
+ licenses:
45
+ - MIT
46
+ metadata:
47
+ allowed_push_host: https://rubygems.org
48
+ homepage_uri: https://github.com/sebyx07/redis-rb-global-config
49
+ source_code_uri: https://github.com/sebyx07/redis-rb-global-config
50
+ changelog_uri: https://github.com/sebyx07/redis-rb-global-config/blob/main/CHANGELOG.md
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 3.0.0
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubygems_version: 3.5.11
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: A gem to provide global configuration for the redis-rb gem
70
+ test_files: []