Class: CFRuntime::RedisClient
- Inherits:
-
Object
- Object
- CFRuntime::RedisClient
- Defined in:
- lib/cf-runtime/redis.rb
Class Method Summary collapse
-
.create(options = {}) ⇒ Object
Creates and returns a
Redis
instance connected to a single redis service. -
.create_from_svc(service_name, options = {}) ⇒ Object
Creates and returns a
Redis
instance connected to a redis service with the specified name. -
.options_for_svc(service_name, options = {}) ⇒ Object
Merges provided options with connection options for specified redis service.
Class Method Details
.create(options = {}) ⇒ Object
Creates and returns a Redis
instance connected to a single redis service. Passes optional Hash of non-connection-related options to Redis.new
. Raises ArgumentError
If zero or multiple redis services are found.
9 10 11 12 13 14 15 16 17 |
# File 'lib/cf-runtime/redis.rb', line 9 def self.create(={}) service_names = CloudApp.service_names_of_type('redis') if service_names.length != 1 raise ArgumentError.new("Expected 1 service of redis type, " + "but found #{service_names.length}. " + "Consider using create_from_svc(service_name) instead.") end create_from_svc(service_names[0],) end |
.create_from_svc(service_name, options = {}) ⇒ Object
Creates and returns a Redis
instance connected to a redis service with the specified name. Passes optional Hash of non-connection-related options to Redis.new
. Raises ArgumentError
If specified redis service is not found.
23 24 25 |
# File 'lib/cf-runtime/redis.rb', line 23 def self.create_from_svc(service_name, ={}) Redis.new((service_name,)) end |
.options_for_svc(service_name, options = {}) ⇒ Object
Merges provided options with connection options for specified redis service. Returns merged Hash containing (password, :host, :port) Raises ArgumentError
If specified redis service is not found.
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/cf-runtime/redis.rb', line 30 def self.(service_name,={}) service_props = CFRuntime::CloudApp.service_props(service_name) if service_props.nil? raise ArgumentError.new("Service with name #{service_name} not found") end = [:host] = service_props[:host] [:port] = service_props[:port] [:password] = service_props[:password] #host and port are ignored if path is provided, so we null it out [:path] = nil end |