Class: DatabaseRecorder::Storage::Redis
- Inherits:
-
Base
- Object
- Base
- DatabaseRecorder::Storage::Redis
show all
- Defined in:
- lib/database_recorder/storage/redis.rb
Instance Method Summary
collapse
Methods inherited from Base
#initialize
Instance Method Details
#connection ⇒ Object
8
9
10
|
# File 'lib/database_recorder/storage/redis.rb', line 8
def connection
@connection ||= @options[:connection] || ::Redis.new
end
|
#load ⇒ Object
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
|
#save ⇒ Object
25
26
27
28
29
30
31
32
33
|
# File 'lib/database_recorder/storage/redis.rb', line 25
def save
data = {}
data[:metadata] = @recording.metadata unless @recording.metadata.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
|