def on_message(self, message):
        to_user = self.get_argument('to_user_id', None)

        user_ser = UserService(self.application.db)
        message = json.loads(message)
        from_user = self.get_current_user()

        key = self.get_wait_key(from_user, to_user)
        user = user_ser.get_user_by_uuid(from_user)
        chat = {
            'message': message.get('info'),
            'time': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
            'user_id': from_user,
            'avatar': user.avatar,
            'name': user.user_name
        }
        now_waits = ChatOneToOneBySocketHandler.watis.get(key).get('waits')
        now_cache = ChatOneToOneBySocketHandler.watis.get(key).get('cache')

        #说明另一个人此时不在对话中,所以发送消息给他
        if len(now_waits) < 2:
            redis_ser = RedisCacheManager()
            MessageRealTimePush().send_message(chat, to_user)
            redis_ser.hm_set(to_user, chat)

        self.update_cache(now_cache, chat)
        self.send_to_update(now_waits, chat)
Beispiel #2
0
    def get_info(self, future):

        redis_ser = RedisCacheManager()

        total_count = redis_ser.get('total_count')
        active_count = redis_ser.get('active_count')

        data = {
            'total_count': total_count,
            'active_count': active_count,
            'all_users': self.get_all_user()
        }
        future.set_result(data)
Beispiel #3
0
    def get_info(self, future):

        redis_ser = RedisCacheManager()

        total_count = redis_ser.get('total_count')
        active_count = redis_ser.get('active_count')

        data = {
            'total_count':total_count,
            'active_count':active_count,
            'all_users':self.get_all_user()
        }
        future.set_result(data)
    def get(self):
        redis_ser = RedisCacheManager()
        user_ser = UserService(self.db)
        user_id = self.get_current_user()
        to_user_id = self.get_argument('to_user_id')

        cur_user = user_ser.get_user_by_uuid(user_id)
        to_user = user_ser.get_user_by_uuid(to_user_id)

        records = redis_ser.hm_get(user_id)

        return self.render('single_chat.html',
                           cur_user=cur_user,
                           to_user=to_user,
                           records=[records])
Beispiel #5
0
    def incr_total_count(self):
        redis_ser = RedisCacheManager()

        if not redis_ser.get('total_count'):
            redis_ser.set('total_count', self.get_total_count())

        redis_ser.incr('total_count')
Beispiel #6
0
    def incr_active_count(self):
        redis_ser = RedisCacheManager()

        if not redis_ser.get('active_count'):
            redis_ser.set('active_count', self.get_active_user_count())

        redis_ser.incr('active_count')
    def get(self):
        user_ser = UserService(self.db)
        user_id = self.get_current_user()

        cur_user = user_ser.get_user_by_uuid(user_id)
        users = user_ser.get_all_user_order_by_active()

        redis_ser = RedisCacheManager()
        redis_ser._con.flushdb()

        active_count = redis_ser.get('active_count')
        total_count = redis_ser.get('total_count')

        if not active_count or not total_count:
            pipe = redis_ser._con.pipeline()
            pipe.set('total_count', self.get_user_count())
            pipe.set('active_count', self.get_active_count())
            pipe.execute()
            active_count = redis_ser.get('active_count')
            total_count = redis_ser.get('total_count')

        data = {
            'total_count': total_count,
            'active_count': active_count,
            'users': users
        }

        records = MultPersonChatManger().cache

        return self.render('chat.html',
                           data=data,
                           cur_user=cur_user,
                           records=records)
Beispiel #8
0
 def decr_active_count(self):
     redis_ser = RedisCacheManager()
     redis_ser.decr('active_count')
def main():
    redis_ser = RedisCacheManager()
    redis_ser._con.flushdb()
Beispiel #10
0
 def __init__(self, handlers, **settings):
     super(Application, self).__init__(handlers, **settings)
     self.db = DB
     self.redis = RedisCacheManager()._con
 def save_by_redis(self, record):
     redis_ser = RedisCacheManager()
     key = datetime.datetime.now().strftime('%Y-%m-%d')
     record_str = json.dumps(record)
     redis_ser.save_in_list(key, record_str)