Class: HeavyKeeper::Bucket

Inherits:
Object
  • Object
show all
Defined in:
lib/heavy_keeper/bucket.rb

Instance Method Summary collapse

Constructor Details

#initialize(storage = HeavyKeeper.config.storage) ⇒ Bucket

Returns a new instance of Bucket.



9
10
11
# File 'lib/heavy_keeper/bucket.rb', line 9

def initialize(storage = HeavyKeeper.config.storage)
  @storage = storage
end

Instance Method Details

#clear(key) ⇒ Object



23
24
25
# File 'lib/heavy_keeper/bucket.rb', line 23

def clear(key)
  storage.del(hash_key(key))
end

#get(key, i, j) ⇒ Object



17
18
19
20
21
# File 'lib/heavy_keeper/bucket.rb', line 17

def get(key, i, j)
  value = storage.hget(hash_key(key), "#{i}:#{j}")

  value ? JSON.parse(value) : value
end

#set(key, i, j, value) ⇒ Object



13
14
15
# File 'lib/heavy_keeper/bucket.rb', line 13

def set(key, i, j, value)
  storage.hset(hash_key(key), "#{i}:#{j}", JSON.generate(value))
end