Class: Ihasa::Bucket::Implementation
- Inherits:
-
Object
- Object
- Ihasa::Bucket::Implementation
- Includes:
- Singleton
- Defined in:
- lib/ihasa/bucket/implementation.rb
Overview
For redis server whith version >= 3.2
Instance Method Summary collapse
Instance Method Details
#accept?(bucket) ⇒ Boolean
19 20 21 |
# File 'lib/ihasa/bucket/implementation.rb', line 19 def accept?(bucket) bucket.redis.evalsha(Lua::TOKEN_BUCKET_HASH, bucket.keys) end |
#save(bucket) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/ihasa/bucket/implementation.rb', line 8 def save(bucket) sha = bucket.redis.script(:load, Lua::TOKEN_BUCKET_ALGORITHM) if sha != Lua::TOKEN_BUCKET_HASH raise "SHA1 mismatch: expected #{Lua::TOKEN_BUCKET_HASH}, got #{sha}" end bucket.redis.eval( Lua.configuration(bucket.rate, bucket.burst), bucket.keys ) end |