Class: Maxwell::Agent::RedisObjects::Set

Inherits:
Object
  • Object
show all
Includes:
Maxwell::Agent::RedisObjects
Defined in:
lib/maxwell/agent/redis_objects/set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Maxwell::Agent::RedisObjects

included, #redis

Constructor Details

#initialize(name) ⇒ Set

Returns a new instance of Set.



8
9
10
# File 'lib/maxwell/agent/redis_objects/set.rb', line 8

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/maxwell/agent/redis_objects/set.rb', line 6

def name
  @name
end

Instance Method Details

#add(object) ⇒ Object



12
13
14
# File 'lib/maxwell/agent/redis_objects/set.rb', line 12

def add(object)
  redis {|redis| redis.sadd name, object.to_json }
end

#allObject



20
21
22
# File 'lib/maxwell/agent/redis_objects/set.rb', line 20

def all
  redis {|redis| redis.smembers name}
end

#countObject



24
25
26
# File 'lib/maxwell/agent/redis_objects/set.rb', line 24

def count
  redis {|redis| redis.scard name }
end

#exists?(object) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
# File 'lib/maxwell/agent/redis_objects/set.rb', line 28

def exists?(object)
  if redis {|redis| redis.sismember name, object.to_json }
    true
  else
    false
  end
end

#find_by(key, value) ⇒ Object



36
37
38
# File 'lib/maxwell/agent/redis_objects/set.rb', line 36

def find_by(key, value)
  all.reject {|host| host if host.key != value }
end

#remove(object) ⇒ Object



16
17
18
# File 'lib/maxwell/agent/redis_objects/set.rb', line 16

def remove(object)
  redis {|redis| redis.srem name, object.to_json }
end