Class: DatabaseRecorder::Storage::Redis

Inherits:
Base
  • Object
show all
Defined in:
lib/database_recorder/storage/redis.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from DatabaseRecorder::Storage::Base

Instance Method Details

#connectionObject



8
9
10
# File 'lib/database_recorder/storage/redis.rb', line 8

def connection
  @connection ||= @options[:connection] || ::Redis.new
end

#loadObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/database_recorder/storage/redis.rb', line 12

def load
  stored_data = connection.get(@name)
  if stored_data
    parsed_data = JSON.parse(stored_data)
    data = Core.symbolize_recursive(parsed_data)
    @recording.cache = data[:queries] || []
    @recording.entities = data[:entities]
    true
  else
    false
  end
end

#saveObject



25
26
27
28
29
30
31
32
33
# File 'lib/database_recorder/storage/redis.rb', line 25

def save
  data = {}
  data[:metadata] = @recording. unless @recording..empty?
  data[:queries] = @recording.queries if @recording.queries.any?
  data[:entities] = @recording.entities if @recording.entities.any?
  serialized_data = data.to_json
  connection.set(@name, serialized_data)
  true
end