pooled_redis 0.0.1 → 0.1.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.
- checksums.yaml +4 -4
- data/README.md +37 -0
- data/lib/pooled_redis.rb +25 -2
- data/lib/pooled_redis/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c1008020f33e7fb0c5ee8f942f1faa53e08bcae
|
4
|
+
data.tar.gz: 6baa77f39c12fef7c17e6537fee979a52f938435
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ddf41949911ae044d4a716de9b69c849730b04310c0f7f42241328b4092415734d0f9a5e3064d7b26722d890c44ac82d5965aa0cb311b2dbfd3c783c0cb9982
|
7
|
+
data.tar.gz: efbedc61537f7215cfa0643f2884c9ac4e3b20d116cff9579b4f461de9057fa6a818a29c76ed1103d2bf3f3a3dc13a55dd6966b2e6824df8edb1300fd747fb2e
|
data/README.md
CHANGED
@@ -30,12 +30,49 @@ production:
|
|
30
30
|
```
|
31
31
|
|
32
32
|
- You can also provide `pool` & `timeout` values for ConnectionPool.
|
33
|
+
- Use `debug: true` to set redis logger to `Rails.logger`.
|
33
34
|
- Use `Rails.redis_pool` & `Rails.redis` method.
|
34
35
|
|
35
36
|
PooledRedis uses ConnectionPool for pooling connections.
|
36
37
|
`.redis` returns proxy object that checkouts connection for every method call.
|
37
38
|
So you may want to avoid it for bulk operations.
|
38
39
|
|
40
|
+
### Rails.cache configuration & Redis::Store support
|
41
|
+
PooledRedis provides configuration of `Rails.cache` via `database.yml`.
|
42
|
+
To enable this add following to your `config/application.rb` (inside `Application` class):
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
PooledRedis.setup_rails_cache(self)
|
46
|
+
```
|
47
|
+
|
48
|
+
And cache sections to `database.yml`:
|
49
|
+
|
50
|
+
```yml
|
51
|
+
development:
|
52
|
+
cache:
|
53
|
+
adapter: redis_store
|
54
|
+
db: 3
|
55
|
+
expires_in: 3600
|
56
|
+
|
57
|
+
production:
|
58
|
+
cache:
|
59
|
+
adapter: redis_store
|
60
|
+
url: 'redis://mycachemaster'
|
61
|
+
sentinels:
|
62
|
+
- host: host
|
63
|
+
- host: other
|
64
|
+
|
65
|
+
# You can also use other adapters:
|
66
|
+
test:
|
67
|
+
cache:
|
68
|
+
adapter: null_store
|
69
|
+
```
|
70
|
+
|
71
|
+
You need to add `gem 'redis-activesupport'` to your Gemfile.
|
72
|
+
It supports only new version of `Redis::Store` with support of ConnectionPool
|
73
|
+
(currently it's only available in master:
|
74
|
+
`gem 'redis-activesupport', '~> 4.0.0', github: 'redis-store/redis-activesupport', ref: 'd09ae04'`).
|
75
|
+
|
39
76
|
### Custom modules or without rails
|
40
77
|
|
41
78
|
- Extend or include `PooledRedis` module.
|
data/lib/pooled_redis.rb
CHANGED
@@ -30,8 +30,7 @@ module PooledRedis
|
|
30
30
|
def redis_config
|
31
31
|
@redis_config = begin
|
32
32
|
config = ActiveRecord::Base.connection_config[:redis].with_indifferent_access
|
33
|
-
config[:
|
34
|
-
config[:logger] = Rails.logger if Rails.env.development?
|
33
|
+
config[:logger] = Rails.logger if config.delete(:debug)
|
35
34
|
config
|
36
35
|
end
|
37
36
|
end
|
@@ -50,6 +49,30 @@ module PooledRedis
|
|
50
49
|
def redis
|
51
50
|
@redis ||= redis_pool.simple_connection
|
52
51
|
end
|
52
|
+
|
53
|
+
class << self
|
54
|
+
def setup_rails_cache(app)
|
55
|
+
# We need to use initializer to be able to access
|
56
|
+
# Rails.configuration.database_configuration.
|
57
|
+
app.initializer :configure_cache, before: :initialize_cache, group: :all do
|
58
|
+
cache_config = Rails.configuration.
|
59
|
+
database_configuration[Rails.env]['cache'].try!(:with_indifferent_access)
|
60
|
+
adapter = cache_config.try!(:delete, :adapter).try!(:to_sym)
|
61
|
+
next unless adapter
|
62
|
+
if adapter == :redis_store
|
63
|
+
# Workaround to support `:db` option:
|
64
|
+
pool_config ||= {
|
65
|
+
pool: cache_config.delete(:pool) || 5,
|
66
|
+
timeout: cache_config.delete(:timeout) || 5,
|
67
|
+
}
|
68
|
+
cache_config = {
|
69
|
+
pool: ConnectionPool.new(pool_config) { Redis::Store.new(cache_config) }
|
70
|
+
}
|
71
|
+
end
|
72
|
+
app.config.cache_store = adapter, cache_config
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
53
76
|
end
|
54
77
|
|
55
78
|
# Use Rails module methods to access redis client.
|
data/lib/pooled_redis/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pooled_redis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Melentiev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|