Class: Rediska::Databases::PStore

Inherits:
Object
  • Object
show all
Includes:
Expiring
Defined in:
lib/rediska/databases/pstore.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Expiring

included

Constructor Details

#initialize(instance_key, id) ⇒ PStore

Returns a new instance of PStore.



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rediska/databases/pstore.rb', line 27

def initialize(instance_key, id)
  @id = id

  @store = self.class.pstore(instance_key)
  @store.transaction do
    @store[db_name] ||= {}
    @db = @store[db_name]
  end

  super()
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object



39
40
41
42
43
44
# File 'lib/rediska/databases/pstore.rb', line 39

def method_missing(*args, &block)
  @store.transaction do
    hash = @db
    hash.send(*args, &block)
  end
end

Class Method Details

.db_name(id) ⇒ Object



61
62
63
# File 'lib/rediska/databases/pstore.rb', line 61

def db_name(id)
 "redis-#{id}"
end

.flushall(instance_key) ⇒ Object



52
53
54
55
# File 'lib/rediska/databases/pstore.rb', line 52

def flushall(instance_key)
  store = pstore(instance_key)
  store.transaction { store.roots.each {|r| store.delete(r) } }
end

.flushdb(instance_key, id) ⇒ Object



47
48
49
50
# File 'lib/rediska/databases/pstore.rb', line 47

def flushdb(instance_key, id)
  store = pstore(instance_key)
  store.transaction { store.delete(db_name(id)) }
end

.pstore(instance_key) ⇒ Object



57
58
59
# File 'lib/rediska/databases/pstore.rb', line 57

def pstore(instance_key)
  Utilities::SyncedPStore.new(File.join(Dir.tmpdir, instance_key.to_s))
end