Sha256: 53f47b0552217253c89fa25f7f8a44d8fd78a7743ec4c86fe7325f10e321d08c

Contents?: true

Size: 618 Bytes

Versions: 4

Compression:

Stored size: 618 Bytes

Contents

require 'redis'

module Skalera
  module Services
    class Redis
      def self.instance(database = 0)
        redis_config = Diplomat::Service.get('redis')

        redis = ::Redis.new(url: url(password, redis_config.Address, redis_config.ServicePort, database))
        at_exit { redis.quit }
        redis
      end

      def self.url(password, host, port, database)
        pwd = password ? "#{password}:" : ''
        "redis://#{pwd}#{host}:#{port}/#{database}"
      end

      def self.password
        Diplomat.get('redis/password')
      rescue Diplomat::KeyNotFound
        nil
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
skalera-services-0.2.3 lib/skalera/services/redis.rb
skalera-services-0.2.2 lib/skalera/services/redis.rb
skalera-services-0.2.1 lib/skalera/services/redis.rb
skalera-services-0.2.0 lib/skalera/services/redis.rb