Beispiel #1
0
Datei: db.py Projekt: zz2/ihere
def put_msg(channel_id, line):
    '''
        把line一句话记录给channel_id, 
        先记录在redis中,当达到MAX_LINE行是记录到数据库中,
        需要注意下面的fsync_msg的使用 
    '''
    key = id2channel_msg_key(channel_id)
    print '-------------', key, line
    r_db.lpush(key, line)
    if r_db.llen(key) >= config.MAX_LINE:
        msg = r_db.lrange(key, 0, -1)
        msg = (config.LINE_SPLIT).join(msg)
        create_msg(id, msg)
        r_db.delete(key)
Beispiel #2
0
Datei: db.py Projekt: zz2/ihere
def bcast_msg(channel_id, msg):
    '''把这个消息广播到参与这个channel中的所有member里面'''
    key = id2channel_mem_key(channel_id)
    for nickname in r_db.smembers(key):
        mem_key = nickname2mem_key(nickname)
        r_db.lpush(mem_key, msg)