Sha256: 7510e556994df25eaebad3bcd79b09e63e459e85f12256d0453a3a85ff87c51e

Contents?: true

Size: 1 KB

Versions: 6

Compression:

Stored size: 1 KB

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 || 6379,
          :password => uri.password
        }

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

        options
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 4 rubygems

Version Path
redis-store-json-3.0.0 redis-store-json/lib/redis/factory.rb
redis-rack-json-1.5.2 redis-store-json/lib/redis/factory.rb
redis-actionpack-json-4.0.0 redis-store-json/lib/redis/factory.rb
redis-store-1.1.3 lib/redis/factory.rb
redis-store-1.1.2 lib/redis/factory.rb
redis-store-1.1.1 lib/redis/factory.rb