Code Monkey home page Code Monkey logo

Comments (4)

ktheory avatar ktheory commented on May 18, 2024

You can set the rack attack key prefix like so:

Rack::Attack.cache.prefix = 'my_app'

Not sure why two different keys are getting created.

from rack-attack.

erem-ifg avatar erem-ifg commented on May 18, 2024

I cleared the cache before:

1) "my_app:allow2ban:ban:127.0.0.1"
2) "development/c5308:my_app:23508888:allow2ban:count:127.0.0.1"

I think it's because of the initializer:

Rack::Attack.cache.store = ActiveSupport::Cache.lookup_store(Rails.configuration.custom.cache_store_config)

Somehow it initializes too late and takes the namespace in consideration only now.

from rack-attack.

erem-ifg avatar erem-ifg commented on May 18, 2024

Here is some input:

When I replace:

self.setex(key, expires_in, value)

with:

self.set(key, value)
self.expire(key, expires_in)

This is what I get:

127.0.0.1:6379> keys '*'
1) "development/c5308:my_app:allow2ban:ban:127.0.0.1"
2) "development/c5308:my_app:23508906:allow2ban:count:127.0.0.1"

But the expiration time are not set:

127.0.0.1:6379> get "development/c5308:my_app:allow2ban:ban:127.0.0.1"
"\x04\bi\x06" (weird value here)
127.0.0.1:6379> ttl "development/c5308:my_app:allow2ban:ban:127.0.0.1"
(integer) -1
127.0.0.1:6379> get "development/c5308:my_app:23508909:allow2ban:count:127.0.0.1"
"20"
127.0.0.1:6379> ttl "development/c5308:my_app:23508909:allow2ban:count:127.0.0.1"
(integer) -1

from rack-attack.

erem-ifg avatar erem-ifg commented on May 18, 2024

Okay, redis-namespace gave me a hard time.
Here is what I did:

# Remove the namespace options
cache_store_config = :redis_store,
  "redis://#{Rails.configuration.custom.config_redis['url']}:#{Rails.configuration.custom.config_redis['port']}"
Rack::Attack.cache.store = ActiveSupport::Cache.lookup_store(cache_store_config)
# Add it back to rack-attack prefix
Rack::Attack.cache.prefix = Rails.configuration.custom.redis_namespace + ':rack:attack'

Thanks @mtparet @ktheory

from rack-attack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.