Class: ActiveOrm::Redis::Hash

Inherits:
ActiveOrm::Redis show all
Defined in:
lib/active_orm/redis/hash.rb

Instance Attribute Summary

Attributes inherited from ActiveOrm::Redis

#client

Attributes inherited from Base

#configuration

Class Method Summary collapse

Methods inherited from ActiveOrm::Redis

client, #initialize

Methods included from Base

#evaluate, #evaluate?

Methods inherited from Base

configuration, configuration=, configure

Constructor Details

This class inherits a constructor from ActiveOrm::Redis

Class Method Details

.all(key) ⇒ Object



15
16
17
18
19
# File 'lib/active_orm/redis/hash.rb', line 15

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

.count(key) ⇒ Object



37
38
39
# File 'lib/active_orm/redis/hash.rb', line 37

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

.create(key, field, value) ⇒ Object



45
46
47
# File 'lib/active_orm/redis/hash.rb', line 45

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

.create!(key, field, value) ⇒ Object



49
50
51
# File 'lib/active_orm/redis/hash.rb', line 49

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

.create_each(key, *args) ⇒ Object



53
54
55
# File 'lib/active_orm/redis/hash.rb', line 53

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

.destroy(key, *args) ⇒ Object



61
62
63
# File 'lib/active_orm/redis/hash.rb', line 61

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

.exists?(key, field) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/active_orm/redis/hash.rb', line 41

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

.find(key, field) ⇒ Object



3
4
5
6
7
# File 'lib/active_orm/redis/hash.rb', line 3

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

.find_each(key, *args) ⇒ Object



9
10
11
12
13
# File 'lib/active_orm/redis/hash.rb', line 9

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

.increment(key, field, value) ⇒ Object



57
58
59
# File 'lib/active_orm/redis/hash.rb', line 57

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

.keys(key) ⇒ Object



21
22
23
24
25
# File 'lib/active_orm/redis/hash.rb', line 21

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

.scan(key, cursor, opts = {}) ⇒ Object



65
66
67
# File 'lib/active_orm/redis/hash.rb', line 65

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

.value_length(key, field) ⇒ Object



33
34
35
# File 'lib/active_orm/redis/hash.rb', line 33

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

.values(key) ⇒ Object



27
28
29
30
31
# File 'lib/active_orm/redis/hash.rb', line 27

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