Sha256: cbe467c64c4309b09aa043d6f0eac0357558597d05fba9c69a9700c96ec6af6b
Contents?: true
Size: 868 Bytes
Versions: 5
Compression:
Stored size: 868 Bytes
Contents
require 'redis' require 'redis/namespace' module Githu3 module Cache class Redis attr_reader :config, :store DEFAULTS = { :host => 'localhost', :port => 6379, :namespace => :githu3, :expire => 120 } unless defined?(DEFAULTS) def initialize opts={} @config = DEFAULTS.merge(opts || {}) redis = ::Redis.new :host => @config[:host], :port => @config[:port] @store = ::Redis::Namespace.new(@config[:namespace].to_sym, :redis => redis) end def get k val = @store[k.to_s] val = Marshal.load val unless val.nil? val end def set k, val, opts={} @store[k.to_s] = Marshal.dump(val) @store.expire k.to_s, (opts[:expire] || @config[:expire]).to_i end end end end
Version data entries
5 entries across 5 versions & 1 rubygems