Class: JOffice::PresenceManagerRedis

Inherits:
Object
  • Object
show all
Defined in:
lib/joffice_redis/storages/presence_redis.rb

Instance Method Summary collapse

Constructor Details

#initialize(service_id) ⇒ PresenceManagerRedis

Returns a new instance of PresenceManagerRedis.



25
26
27
28
29
30
31
32
# File 'lib/joffice_redis/storages/presence_redis.rb', line 25

def initialize(service_id)
  @service_id=service_id
  @db_name="#{@service_id}_weather_presence"
  @db_name_info="xmpp_user_presence_info"
  flush_db
  @presence_redis=JOffice::RedisManager.instance.open_db_em(@db_name_info)
  @weather_presence_redis=JOffice::RedisManager.instance.open_db_em(@db_name)
end

Instance Method Details

#delete_caps(user_id, resource) ⇒ Object

Use



71
72
73
74
75
76
77
# File 'lib/joffice_redis/storages/presence_redis.rb', line 71

def delete_caps(user_id, resource)
  $log.info { "Delete caps #{user_id} : '#{resource}'" }       
  
  hash_key=hash.hexdigest("%s:%s" % [user_id,resource])
  @presence_redis.delete("#{hash_key}:ver")  {|a|}
  @presence_redis.delete("#{hash_key}:node") {|a|}      
end

#flush_dbObject



46
47
48
49
50
51
52
53
# File 'lib/joffice_redis/storages/presence_redis.rb', line 46

def flush_db
  JOffice::RedisManager.instance.opend_db(@db_name) do |db|
    db.flush_db
  end	
  JOffice::RedisManager.instance.opend_db(@db_name_info) do |db|
    db.flush_db
  end	
end

#hashObject



42
43
44
# File 'lib/joffice_redis/storages/presence_redis.rb', line 42

def hash
  @hash||=Digest::SHA1.new
end

#load_caps(user_id, resource) ⇒ Object



63
64
65
66
67
68
# File 'lib/joffice_redis/storages/presence_redis.rb', line 63

def load_caps(user_id, resource)
  hash_key=hash.hexdigest("%s:%s" % [user_id,resource])       
  @presence_redis.mget("#{hash_key}:ver", "#{hash_key}:node") do |caps|
    yield(caps.empty? ? {} : {:caps_node=>caps[1], :caps_ver=>caps[0]})
  end      
end

#presence_db_emObject



34
35
36
# File 'lib/joffice_redis/storages/presence_redis.rb', line 34

def presence_db_em
  @presence_db_em||=JOffice::RedisManager.instance.open_db_em(@db_name_info)
end

#save_caps(user_id, resource, caps_node, caps_ver, caps_ext) ⇒ Object

Use



56
57
58
59
60
61
# File 'lib/joffice_redis/storages/presence_redis.rb', line 56

def save_caps(user_id, resource,  caps_node, caps_ver,caps_ext)
  $log.info { "Save caps #{user_id}/#{resource} #{caps_node} : '#{caps_ver}'" }      
  hash_key=hash.hexdigest("%s:%s" % [user_id,resource])       
  @presence_redis.set("#{hash_key}:ver", caps_ver) {|a|}
  @presence_redis.set("#{hash_key}:node", caps_node) {|a|}             
end

#weather_presence_db_emObject



38
39
40
# File 'lib/joffice_redis/storages/presence_redis.rb', line 38

def weather_presence_db_em
  @weather_presence_db_em||=JOffice::RedisManager.instance.open_db_em(@db_name)
end