Sha256: b064b91df35e573f9caa0e0cd8d1905d8e32384127b1ecf7afb451690ee4e180

Contents?: true

Size: 987 Bytes

Versions: 4

Compression:

Stored size: 987 Bytes

Contents

module Rack
  module Cache
    class EntityStore
      class RedisBase < EntityStore
        # The underlying ::Redis instance used to communicate with the Redis daemon.
        attr_reader :cache

        extend Rack::Utils

        def open(key)
          data = read(key)
          data && [data]
        end

        def self.resolve(uri)
          new ::Redis::Factory.convert_to_redis_client_options(uri.to_s)
        end
      end

      class Redis < RedisBase
        def initialize(server, options = {})
          @cache = ::Redis.new server
        end

        def exist?(key)
          cache.exists key
        end

        def read(key)
          cache.get key
        end

        def write(body)
          buf = StringIO.new
          key, size = slurp(body){|part| buf.write(part) }
          [key, size] if cache.set(key, buf.string)
        end

        def purge(key)
          cache.del key
          nil
        end
      end

      REDIS = Redis
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
instructure-redis-store-1.0.0.2.instructure1 lib/rack/cache/redis_entitystore.rb
instructure-redis-store-1.0.0.1.instructure1 lib/rack/cache/redis_entitystore.rb
redis-store-1.0.0.1 lib/rack/cache/redis_entitystore.rb
redis-store-1.0.0.rc1 lib/rack/cache/redis_entitystore.rb