Class: Redis::Store::Factory
- Inherits:
-
Object
- Object
- Redis::Store::Factory
- Defined in:
- lib/redis/store/factory.rb
Constant Summary collapse
- DEFAULT_PORT =
6379
Class Method Summary collapse
- .create(*options) ⇒ Object
- .extract_host_options_from_hash(options) ⇒ Object
- .extract_host_options_from_uri(uri) ⇒ Object
- .host_options?(options) ⇒ Boolean
- .normalize_key_names(options) ⇒ Object
-
.resolve(uri) ⇒ Object
:api: private.
Instance Method Summary collapse
- #create ⇒ Object
-
#initialize(*options) ⇒ Factory
constructor
A new instance of Factory.
Constructor Details
#initialize(*options) ⇒ Factory
Returns a new instance of Factory.
13 14 15 16 17 |
# File 'lib/redis/store/factory.rb', line 13 def initialize(*) @addresses = [] = {} () end |
Class Method Details
.create(*options) ⇒ Object
9 10 11 |
# File 'lib/redis/store/factory.rb', line 9 def self.create(*) new().create end |
.extract_host_options_from_hash(options) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/redis/store/factory.rb', line 39 def self.() = normalize_key_names() if () else nil end end |
.extract_host_options_from_uri(uri) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/redis/store/factory.rb', line 68 def self.(uri) uri = URI.parse(uri) if uri.scheme == "unix" = { :path => uri.path } else _, db, namespace = if uri.path uri.path.split(/\//) end = { :scheme => uri.scheme, :host => uri.hostname, :port => uri.port || DEFAULT_PORT, :ssl => uri.scheme == 'rediss' } [:db] = db.to_i if db [:namespace] = namespace if namespace end if uri.user && !uri.user.empty? [:username] = uri.user end [:password] = CGI.unescape(uri.password.to_s) if uri.password if uri.query query = Hash[URI.decode_www_form(uri.query)] query.each do |(key, value)| [key.to_sym] = value end end end |
.host_options?(options) ⇒ Boolean
64 65 66 |
# File 'lib/redis/store/factory.rb', line 64 def self.() .keys.any? { |n| [:host, :db, :port, :path].include?(n) } end |
.normalize_key_names(options) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/redis/store/factory.rb', line 48 def self.normalize_key_names() = .dup if .key?(:key_prefix) && !.key?(:namespace) [:namespace] = .delete(:key_prefix) # RailsSessionStore end [:raw] = case when .key?(:serializer) [:serializer].nil? when .key?(:marshalling) ![:marshalling] else false end end |
.resolve(uri) ⇒ Object
:api: private
31 32 33 34 35 36 37 |
# File 'lib/redis/store/factory.rb', line 31 def self.resolve(uri) #:api: private if uri.is_a?(Hash) (uri) else (uri) end end |
Instance Method Details
#create ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/redis/store/factory.rb', line 19 def create if @addresses.empty? @addresses << {} end if @addresses.size > 1 ::Redis::DistributedStore.new @addresses, else ::Redis::Store.new @addresses.first.merge() end end |