Sha256: 1068c206d8dee5f604d41dce4a64ed9cb9e6a0154d31f5beb8f8221e1501b1ee

Contents?: true

Size: 842 Bytes

Versions: 2

Compression:

Stored size: 842 Bytes

Contents

module Geong
  module Cache
    def self.redis(options = {})
      require "redis"
      redis = Redis.new(options)
      if options[:default_ttl_seconds] or options[:default_ttl_milliseconds]
        redis.singleton_class.prepend RedisDefaultTTL
        redis.default_ttl_seconds = options[:default_ttl_seconds]
        redis.default_ttl_milliseconds = options[:default_ttl_milliseconds]
      end
      redis
    end

    module RedisDefaultTTL
      def default_ttl_seconds=(ttl_seconds)
        @default_ttl_seconds = ttl_seconds
      end
      
      def default_ttl_milliseconds=(ttl_milliseconds)
        @default_ttl_milliseconds = ttl_milliseconds
      end
      
      def []=(key, value)
        set(key, value, {ex: @default_ttl_seconds, px: @default_ttl_milliseconds})
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
geong-0.0.2 lib/geong/cache.rb
geong-0.0.1 lib/geong/cache.rb