Sha256: 54e400074a8bd3e062f0fa39a5301bb34beecf3716c79af981dce206b3705de3

Contents?: true

Size: 1.6 KB

Versions: 3

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

3 entries across 3 versions & 1 rubygems

Version Path
active_orm-4.0.3 lib/active_orm/redis/hash.rb
active_orm-4.0.2 lib/active_orm/redis/hash.rb
active_orm-4.0.1 lib/active_orm/redis/hash.rb