Class: Hirameki::Config
- Inherits:
-
Object
- Object
- Hirameki::Config
- Defined in:
- lib/hirameki/config.rb
Instance Attribute Summary collapse
-
#expiration_time ⇒ Object
Returns the value of attribute expiration_time.
-
#pepper ⇒ Object
Returns the value of attribute pepper.
Instance Method Summary collapse
-
#redis ⇒ Object
Returns the current Redis connection.
-
#redis=(server) ⇒ Object
Accepts: 1.
- #redis_id ⇒ Object
Instance Attribute Details
#expiration_time ⇒ Object
Returns the value of attribute expiration_time.
5 6 7 |
# File 'lib/hirameki/config.rb', line 5 def expiration_time @expiration_time end |
#pepper ⇒ Object
Returns the value of attribute pepper.
5 6 7 |
# File 'lib/hirameki/config.rb', line 5 def pepper @pepper end |
Instance Method Details
#redis ⇒ Object
Returns the current Redis connection. If none has been created, will create a new one.
34 35 36 37 |
# File 'lib/hirameki/config.rb', line 34 def redis return @redis if @redis self.redis = Redis.respond_to?(:connect) ? Redis.connect : "localhost:6379" end |
#redis=(server) ⇒ Object
Accepts:
1. A 'hostname:port' String
2. A 'hostname:port:db' String (to select the Redis db)
3. A 'hostname:port/namespace' String (to set the Redis namespace)
4. A Redis URL String 'redis://host:port'
5. An instance of `Redis`, `Redis::Client`, `Redis::DistRedis`,
or `Redis::Namespace`.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/hirameki/config.rb', line 14 def redis=(server) case server when String if server =~ /redis\:\/\// redis = Redis.connect(url: server, thread_safe: true) else server, namespace = server.split('/', 2) host, port, db = server.split(':') redis = Redis.new(host: host, port: port, thread_safe: true, db: db) end @redis = redis when Redis, Redis::Namespace @redis = server else @redis = Redis.new(host: "localhost", port: 6379) end end |
#redis_id ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/hirameki/config.rb', line 39 def redis_id # support 1.x versions of redis-rb if redis.respond_to?(:server) redis.server elsif redis.respond_to?(:nodes) # distributed redis.nodes.map { |n| n.id }.join(', ') else redis.client.id end end |