Class: Geode::RedisStore

Inherits:
Store
  • Object
show all
Defined in:
lib/geode/redis.rb

Overview

A store implemented using Redis.

Instance Method Summary collapse

Methods inherited from Store

#[], #peek

Constructor Details

#initialize(name, connection = nil) ⇒ RedisStore

Connect to a store held in Redis.

Parameters:

  • name (Symbol, String)

    The name of the store

  • connection (Hash, String) (defaults to: nil)

    Connection parameters passed to ‘Redis.new`. Defaults to empty hash



12
13
14
15
16
# File 'lib/geode/redis.rb', line 12

def initialize(name, connection = nil)
  super
  connection ||= {}
  @redis = Redis.new(connection)
end

Instance Method Details

#destroyObject



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

def destroy
  @redis.del @name
  nil
end

#openObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/geode/redis.rb', line 18

def open
  table = if @redis.exists? @name
            Marshal.load(@redis.get @name)
          else
            {}
          end

  (yield table).tap do
    @redis.set @name, Marshal.dump(table)
  end
end