class RateLimit::Redis

Public Class Methods

new(cache_handle) click to toggle source
# File lib/ratelimit/bucketbased.rb, line 167
def initialize(cache_handle)
        @cache = cache_handle
end

Public Instance Methods

get(name) click to toggle source

retrieves a named bucket

  • Args :

    • name -> the name of the bucket to be retrieved

  • Returns :

    • the bucket matching the name if found, nil otherwise

# File lib/ratelimit/bucketbased.rb, line 176
def get(name)
        value = @cache.get(name)
        return nil unless value
        row = value.split(/\|/)
        bucket = nil
        if row
                bucket = Bucket.new(row[0],*row[1,8].map{|x| x.to_f})
        end
        bucket
end
set(bucket) click to toggle source

saves a bucket into the storage

  • Args :

    • bucket -> the Bucket to set. The name field in the Bucket option will be used as a key.

  • Returns :

    • the bucket that is provided in the Args

# File lib/ratelimit/bucketbased.rb, line 192
def set(bucket)
        @cache.set(bucket.name,bucket.values.join("|"))
end
Also aliased as: update
update(bucket)
Alias for: set