Class: Redis::Database::Watcher

Inherits:
Object
  • Object
show all
Defined in:
lib/redis/database.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWatcher

Returns a new instance of Watcher.



8
9
10
11
# File 'lib/redis/database.rb', line 8

def initialize
  @watched = []
  @bound = true
end

Instance Attribute Details

#boundObject (readonly)

Returns the value of attribute bound.



6
7
8
# File 'lib/redis/database.rb', line 6

def bound
  @bound
end

Instance Method Details

#bind(database, *keys) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/redis/database.rb', line 13

def bind database, *keys
  return unless @bound
  keys.each do |key|
    entry = [database, key]
    next if @watched.include? entry
    @watched << entry
    (database.watchers[key] ||= []).push self
  end
end

#unbindObject



23
24
25
26
27
28
29
30
31
# File 'lib/redis/database.rb', line 23

def unbind
  return unless @bound
  @watched.each do |database, key|
    key_df_list = database.watchers[key]
    next unless key_df_list
    key_df_list.delete_if { |e| e == self }
  end
  @bound = false
end