Class: RedisHA::HashMap
- Inherits:
-
Base
- Object
- Base
- RedisHA::HashMap
show all
- Defined in:
- lib/redis_ha/crdt/hash_map.rb
Constant Summary
collapse
- DEFAULT_MERGE_STRATEGY =
this lambda defines how the individual response hashes are merged the default is to merge in reverse-chronological order
->(v) { v
.sort{ |a,b| a[:_time] <=> b[:_time] }
.inject({}){ |t,c| t.merge!(c) } }
Instance Attribute Summary
Attributes inherited from Base
#key, #pool
Instance Method Summary
collapse
Methods inherited from Base
#initialize
Constructor Details
This class inherits a constructor from RedisHA::Base
Instance Method Details
#get ⇒ Object
16
17
18
19
20
21
22
23
24
|
# File 'lib/redis_ha/crdt/hash_map.rb', line 16
def get
versions = pool.get(@key).map do |v|
next if v.nil? || v == ""
Marshal.load(v) rescue nil
end.compact
merge_strategy[versions].tap do |merged|
merged.delete(:_time)
end
end
|
#merge_strategy ⇒ Object
26
27
28
|
# File 'lib/redis_ha/crdt/hash_map.rb', line 26
def merge_strategy
@merge_strategy || DEFAULT_MERGE_STRATEGY
end
|
#set(data = {}) ⇒ Object
10
11
12
13
14
|
# File 'lib/redis_ha/crdt/hash_map.rb', line 10
def set(data = {})
data.merge!(:_time => Time.now.to_i)
pool.set(@key, Marshal.dump(data))
true
end
|