Sha256: 1c28884aff0339cb58ce3d4039199e52462c9635dc9117327e6a41ee5014a98a

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

require 'redis/store/ttl'
require 'redis/store/interface'
require 'redis/store/strategy'

class Redis
  class Store < self
    include Ttl, Interface

    STRATEGIES = {
      :marshal      => Strategy::Marshal,
      :json         => Strategy::Json,
      :json_session => Strategy::JsonSession,
      :yaml         => Strategy::Yaml,
    }.freeze

    def initialize(options = { })
      super options.delete(:redis_server)

      _extend_strategy  options
      _extend_namespace options
    end

    def reconnect
      @client.reconnect
    end

    def to_s
      "Redis Client connected to #{@client.host}:#{@client.port} against DB #{@client.db}"
    end

    private
      def _extend_strategy(options)
        strategy = options[:strategy]

        unless strategy === false
          strategy_class = STRATEGIES[strategy] || STRATEGIES[:marshal]
          extend Strategy, strategy_class
        end
      end

      def _extend_namespace(options)
        @namespace = options[:namespace]
        extend Namespace if @namespace
      end
  end
end

Version data entries

3 entries across 3 versions & 3 rubygems

Version Path
redis-store-json-3.0.0 redis-store-json/lib/redis/store.rb
redis-rack-json-1.5.2 redis-store-json/lib/redis/store.rb
redis-actionpack-json-4.0.0 redis-store-json/lib/redis/store.rb