Sha256: 250589ab91503699f13e1dfa923f6329bf6f76b5e26e4eab8ff2fdd57d72a34b

Contents?: true

Size: 887 Bytes

Versions: 12

Compression:

Stored size: 887 Bytes

Contents

class Redis
  class Store < self
    module Ttl
      def set(key, value, options = nil)
        if ttl = expires_in(options)
          setex(key, ttl.to_i, value, :raw => true)
        else
          super(key, value)
        end
      end

      def setnx(key, value, options = nil)
        if ttl = expires_in(options)
          setnx_with_expire(key, value, ttl.to_i)
        else
          super(key, value)
        end
      end

      protected
        def setnx_with_expire(key, value, ttl)
          multi do
            setnx(key, value, :raw => true)
            expire(key, ttl)
          end
        end

      private
        def expires_in(options)
          if options
            # Rack::Session           Merb                    Rails/Sinatra
            options[:expire_after] || options[:expires_in] || options[:expire_in]
          end
        end
    end
  end
end

Version data entries

12 entries across 12 versions & 4 rubygems

Version Path
redis-store-1.1.7 lib/redis/store/ttl.rb
redis-store-1.1.6 lib/redis/store/ttl.rb
redis-store-1.1.5 lib/redis/store/ttl.rb
redis-store-1.1.4 lib/redis/store/ttl.rb
redis-store-json-3.0.0 redis-store-json/lib/redis/store/ttl.rb
redis-rack-json-1.5.2 redis-store-json/lib/redis/store/ttl.rb
redis-actionpack-json-4.0.0 redis-store-json/lib/redis/store/ttl.rb
redis-store-1.1.3 lib/redis/store/ttl.rb
redis-store-1.1.2 lib/redis/store/ttl.rb
redis-store-1.1.1 lib/redis/store/ttl.rb
redis-store-1.1.0 lib/redis/store/ttl.rb
redis-store-1.1.0.rc2 lib/redis/store/ttl.rb