Class: Swarm::Storage::RedisStorage

Inherits:
KeyValueStorage show all
Defined in:
lib/swarm/storage/redis_storage.rb

Instance Attribute Summary

Attributes inherited from KeyValueStorage

#store

Instance Method Summary collapse

Methods inherited from KeyValueStorage

#[], #[]=, #add_association, #deserialize, #initialize, #load_associations, #regex_for_type, #serialize, #trace, #trace=

Constructor Details

This class inherits a constructor from Swarm::Storage::KeyValueStorage

Instance Method Details

#all_of_type(type, subtypes: true) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/swarm/storage/redis_storage.rb', line 13

def all_of_type(type, subtypes: true)
  hsh = store.mapped_mget(*store.keys("#{type}:*"))
  if subtypes
    hsh.values
  else
    hsh.select { |_key, value| value["type"] == type }.values
  end
end

#delete(key) ⇒ Object



22
23
24
# File 'lib/swarm/storage/redis_storage.rb', line 22

def delete(key)
  store.del(key)
end

#ids_for_type(type) ⇒ Object



9
10
11
# File 'lib/swarm/storage/redis_storage.rb', line 9

def ids_for_type(type)
  store.keys("#{type}:*").map { |key| key.gsub(regex_for_type(type), '\1') }
end

#truncateObject



26
27
28
# File 'lib/swarm/storage/redis_storage.rb', line 26

def truncate
  store.flushdb
end