Sha256: f8f838729f5b00c047bcb2c942ab605c743d50f3362efb5097cf0838236c8d8e

Contents?: true

Size: 1.6 KB

Versions: 1

Compression:

Stored size: 1.6 KB

Contents

class ActiveOrm::Redis::Hash < ActiveOrm::Redis

  def self.find(key, field)
    value = client.hget(normalize_key(key), field)
    value = metamorph(value) if evaluate?
    value
  end

  def self.find_each(key, *args)
    value = client.hmget(normalize_key(key), args)
    value = metamorph(value) if evaluate?
    value
  end

  def self.all(key)
    value = client.hgetall(normalize_key(key))
    value = metamorph(value) if evaluate?
    value
  end

  def self.keys(key)
    value = client.hkeys(normalize_key(key))
    value = metamorph(value) if evaluate?
    value
  end

  def self.values(key)
    value = client.hvals(normalize_key(key))
    value = metamorph(value) if evaluate?
    value
  end

  def self.value_length(key, field)
    client.hstrlen(normalize_key(key), field)
  end

  def self.count(key)
    client.hlen(normalize_key(key))
  end

  def self.exists?(key, field)
    client.hexists(normalize_key(key), field)
  end

  def self.create(key, field, value)
    client.hset(normalize_key(key), field, value)
  end

  def self.create!(key, field, value)
    client.hsetnx(normalize_key(key), field, value)
  end

  def self.create_each(key, *args)
    client.hmset(normalize_key(key), *args)
  end

  def self.increment(key, field, value)
    normalized_key = normalize_key(key)

    if value.is_a?(Float)
      client.hincrbyfloat(normalized_key, field, value)
    else
      client.hincrby(normalized_key, field, value)
    end
  end

  def self.destroy(key, *args)
    client.hdel(normalize_key(key), *args)
  end

  def self.scan(key, cursor, opts = {})
    client.hdel(normalize_key(key), cursor, opts)
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_orm-4.0.0 lib/active_orm/redis/hash.rb