Class: RedisHA::Set

Inherits:
Base
  • Object
show all
Defined in:
lib/redis_ha/crdt/set.rb

Constant Summary collapse

DEFAULT_MERGE_STRATEGY =

this lambda defines how the individual response hashes are merged the default is set union

->(v) { v.inject(&:|) }

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

#add(*items) ⇒ Object



7
8
9
10
# File 'lib/redis_ha/crdt/set.rb', line 7

def add(*items)
  pool.sadd(@key, *items)
  true
end

#getObject



17
18
19
20
# File 'lib/redis_ha/crdt/set.rb', line 17

def get
  versions = pool.smembers(@key).compact
  merge_strategy[versions]
end

#merge_strategyObject



22
23
24
# File 'lib/redis_ha/crdt/set.rb', line 22

def merge_strategy
  @merge_strategy || DEFAULT_MERGE_STRATEGY
end

#rem(*items) ⇒ Object



12
13
14
15
# File 'lib/redis_ha/crdt/set.rb', line 12

def rem(*items)
  pool.srem(@key, *items)
  true
end