Sha256: a8a1acfca27cf4ebd7a457c6bcad0f594853797d72c62a82661246323e059642

Contents?: true

Size: 1.54 KB

Versions: 2

Compression:

Stored size: 1.54 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)
    value.is_a?(Float) ? client.hincrbyfloat(normalize_key(key), field, value) : client.hincrby(normalize_key(key), field, value)
  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

2 entries across 2 versions & 1 rubygems

Version Path
active_orm-2.4.0 lib/active_orm/redis/hash.rb
active_orm-2.3.0 lib/active_orm/redis/hash.rb