Sha256: db1fc869557befa70d8faa3cdbc825893330cd45421a09796fab6f9fcabecb01

Contents?: true

Size: 1019 Bytes

Versions: 3

Compression:

Stored size: 1019 Bytes

Contents

require 'uri'

class Redis
  class Factory
    def self.create(*redis_client_options)
      redis_client_options = redis_client_options.flatten.compact.inject([]) do |result, address|
        result << resolve(address)
        result
      end
      if redis_client_options.size > 1
        ::Redis::DistributedStore.new redis_client_options
      else
        ::Redis::Store.new redis_client_options.first || {}
      end
    end

    def self.resolve(uri) #:api: private
      if uri.is_a?(Hash)
        options = uri.dup
        options[:namespace] ||= options.delete(:key_prefix) # RailsSessionStore
        options
      else
        uri = URI.parse(uri)
        _, db, namespace = if uri.path
          uri.path.split /\//
        end

        options = {
          :host     => uri.host,
          :port     => uri.port,
          :password => uri.password
        }

        options[:db]        = db.to_i   if db
        options[:namespace] = namespace if namespace

        options
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
redis-store-1.1.0 lib/redis/factory.rb
redis-store-1.1.0.rc2 lib/redis/factory.rb
redis-store-1.1.0.rc lib/redis/factory.rb