-
Notifications
You must be signed in to change notification settings - Fork 336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hooking up to Redis? #102
Comments
By default, Rack::Attack will use whichever caching backend is configured as From the example configuration: ### Configure Cache ###
# If you don't want to use Rails.cache (Rack::Attack's default), then
# configure it here.
#
# Note: The store is only used for throttling (not blacklisting and
# whitelisting). It must implement .increment and .write like
# ActiveSupport::Cache::Store
# Rack::Attack.cache.store = ActiveSupport::Cache::MemoryStore.new This looks like a pretty good gem for handling the connection/configuration: https://github.com/redis-store/redis-rails |
Yeah, if you have If that's not clear, a PR improving the documentation is welcome. Thanks! 😎 |
@ktheory @zmillman Thanks, much appreciated. I've been using Rack::Attack for a few months now and the reason I'm now looking to change the cache store is because this gem eats up large amounts of space on my server via cache files it stores on the filesystem. The documentation really should make it more clear that when using this gem, you should be using something other than the default rails cache and why. |
here is an example, which helped me: https://gist.github.com/ktheory/5087320 not sure if that is the best way to include ist. or you could use the Redis.current = Redis.new(host: ENV['REDIS_HOST'], port: ENV['REDIS_PORT']) class Rack::Attack
Rack::Attack.cache.store = Rack::Attack::StoreProxy::RedisStoreProxy.new(Redis.current)
end |
Thank you @fluxsaas. You helped me with figuring out how to configure Rack::Attack to use Redis as its caching mechanism. # File: rack_attack.rb
class Rack::Attack
Rack::Attack.cache.store = ActiveSupport::Cache::RedisStore.new("redis://example.com:6666/0/cache", { expires_in: 480.minutes })
... ...
end |
@fluxsaas exactly what I need. Redis connection to RedisToGo on heroku app. Thanks! |
Those who faced same problem in Rails 5 might check
|
@saygun You have no idea how much i love you |
Is there a 2020 method for this or have the solutions remained the same? |
Hi @lordplagus02, Since Rack::Attack.cache.store = Redis.new(...) |
Does this library automatically set expirations on the redis objects. LIke for example, if we have a "period" of 5.minutes on some throttling. After 5 minutes that key is gone right? Or is there no purging mechanism? |
Would be nice to see an example in the REDME of how this can be configured to connect to Redis. Can someone provide me with a link which explains how to do that?
The text was updated successfully, but these errors were encountered: