Sha256: 230655d1e0d62569b2866ef08f0182c5cf904825b86af2a3eebb1c0f9c7bd321

Contents?: true

Size: 588 Bytes

Versions: 4

Compression:

Stored size: 588 Bytes

Contents

require 'speed_gun/store/base'

class SpeedGun::Store::Redis
  DEFAULT_PREFIX = 'speed-gun-'
  DEFAULT_EXPIRES_IN_SECONDS = 60 * 60 * 24

  def initialize(options = {})
    @prefix = options[:prefix] || DEFAULT_PREFIX
    @client = options[:client] || default_redis(options)
    @expires = options[:expires] || DEFAULT_EXPIRES_IN_SECONDS
  end

  def [](id)
    @client.get("#{@prefix}#{id}")
  end

  def []=(id, val)
    @client.setex("#{@prefix}#{id}", val, @expires)
  end

  private

  def default_redis(args)
    require 'redis' unless defined? Redis
    Redis.new(args)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
speed_gun-0.0.4 lib/speed_gun/store/redis.rb
speed_gun-0.0.3 lib/speed_gun/store/redis.rb
speed_gun-0.0.2 lib/speed_gun/store/redis.rb
speed_gun-0.0.1 lib/speed_gun/store/redis.rb