Sha256: 4d2577a9e847cbf5fb96f4d5f87a294a1ceef19399d46b91f03f30b08f930119

Contents?: true

Size: 1.92 KB

Versions: 3

Compression:

Stored size: 1.92 KB

Contents

# frozen_string_literal: true

class ActiveRedisDB::Key < ActiveRedisDB::Base
  class << self

    def exists?(key)
      client.exists(normalize_key(key))
    end

    def type?(key)
      client.type(normalize_key(key))
    end

    def ttl?(key, format = :seconds)
      normalized_key = normalize_key(key)

      seconds?(format) ? client.ttl(normalized_key) : client.pttl(normalized_key)
    end

    def sort(key, opts = {})
      client.sort(normalize_key(key), opts)
    end

    def sample
      client.randomkey
    end

    def rename(key, value)
      client.rename(normalize_key(key), value.to_s)
    end

    def rename!(key, value)
      client.renamenx(normalize_key(key), value.to_s)
    end

    def destroy(key)
      client.del(normalize_key(key))
    end

    def persist(key)
      client.persist(normalize_key(key))
    end

    def expire(key, seconds, format = :seconds)
      normalized_key = normalize_key(key)

      if seconds?(format)
        client.expire(normalized_key, seconds)
      else
        client.pexpire(normalized_key, seconds)
      end
    end

    def expire_at(key, seconds, format = :seconds)
      normalized_key = normalize_key(key)

      if seconds?(format)
        client.expireat(normalized_key, seconds)
      else
        client.pexpireat(normalized_key, seconds)
      end
    end

    def dump(key)
      client.dump(normalize_key(key))
    end

    def match(pattern = '*')
      value = client.keys(normalize_key(pattern))
      value = nil if value.empty?
      value
    end

    def migrate(key, options)
      client.migrate(normalize_key(key), options)
    end

    def move(key, destination)
      client.move(normalize_key(key), destination)
    end

    def object(*args)
      client.object(args)
    end

    def restore(key, milliseconds, value)
      client.restore(normalize_key(key), milliseconds, value)
    end

    def scan(cursor, opts = {})
      client.scan(cursor, opts)
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
active_redis_db-1.0.2 lib/active_redis_db/key.rb
active_redis_db-1.0.1 lib/active_redis_db/key.rb
active_redis_db-1.0.0 lib/active_redis_db/key.rb