Module: Redis::Hashes

Defined in:
lib/redis/hashes.rb

Instance Method Summary collapse

Instance Method Details

#redis_HDEL(key, field) ⇒ Object



55
56
57
58
59
60
# File 'lib/redis/hashes.rb', line 55

def redis_HDEL key, field
  hash = @database[key] || {}
  result = hash.has_key? field
  hash.delete field
  result
end

#redis_HEXISTS(key, field) ⇒ Object



11
12
13
# File 'lib/redis/hashes.rb', line 11

def redis_HEXISTS key, field
  (@database[key] || {}).has_key? field
end

#redis_HGET(key, field) ⇒ Object



47
48
49
# File 'lib/redis/hashes.rb', line 47

def redis_HGET key, field
  (@database[key] || {})[field]
end

#redis_HGETALL(key) ⇒ Object



51
52
53
# File 'lib/redis/hashes.rb', line 51

def redis_HGETALL key
  @database[key] || {}
end

#redis_HINCRBY(key, field, increment) ⇒ Object



62
63
64
65
66
67
# File 'lib/redis/hashes.rb', line 62

def redis_HINCRBY key, field, increment
  hash = @database[key] ||= {}
  value = redis_i(hash[field] ||= 0)
  value += redis_i increment
  hash[field] = value
end

#redis_HKEYS(key) ⇒ Object



22
23
24
# File 'lib/redis/hashes.rb', line 22

def redis_HKEYS key
  (@database[key] || {}).keys
end

#redis_HLEN(key) ⇒ Object



43
44
45
# File 'lib/redis/hashes.rb', line 43

def redis_HLEN key
  (@database[key] || {}).size
end

#redis_HMGET(key, *fields) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/redis/hashes.rb', line 35

def redis_HMGET key, *fields
  hash = (@database[key] || {})
  redis_t Hash, hash
  fields.collect do |field|
    hash[field]
  end
end

#redis_HMSET(key, *args) ⇒ Object



30
31
32
33
# File 'lib/redis/hashes.rb', line 30

def redis_HMSET key, *args
  (@database[key] ||= {}).merge! Hash[*args]
  :'+OK'
end

#redis_HSET(key, field, value) ⇒ Object



4
5
6
7
8
9
# File 'lib/redis/hashes.rb', line 4

def redis_HSET key, field, value
  hash = @database[key] ||= {}
  result = !hash.has_key?(field)
  hash[field] = value
  result
end

#redis_HSETNX(key, field, value) ⇒ Object



15
16
17
18
19
20
# File 'lib/redis/hashes.rb', line 15

def redis_HSETNX key, field, value
  hash = @database[key] || {}
  return false if hash.has_key? field
  redis_HSET key, field, value
  return true
end

#redis_HVALS(key) ⇒ Object



26
27
28
# File 'lib/redis/hashes.rb', line 26

def redis_HVALS key
  (@database[key] || {}).values
end