def create(data: dict) -> Comment: # print(data) if data['replyid'] != -1: #几条回复 howmanyreply = int( to_string( r.hget('comments:{}'.format(data['replyid']), 'howmanyreply'))) + 1 r.hset('comments:{}'.format(data['replyid']), 'howmanyreply', howmanyreply) #作者有没有回复 replycomment = Comment(data['replyid']) replycommentinfo = replycomment.info() if data['referid'] == -1: if data['openid'] == data['postuserid'] and replycommentinfo[ 'openid'] != data['openid']: authorreply = int( to_string( r.hget('comments:{}'.format(data['replyid']), 'authorreply'))) + 1 r.hset('comments:{}'.format(data['replyid']), 'authorreply', authorreply) else: refercomment = Comment(data['referid']) refercommentinfo = refercomment.info() if data['openid'] == data['postuserid'] and refercommentinfo[ 'openid'] != data['openid']: authorreply = int( to_string( r.hget('comments:{}'.format(data['replyid']), 'authorreply'))) + 1 r.hset('comments:{}'.format(data['replyid']), 'authorreply', authorreply) elif data['openid'] == data['postuserid'] and refercommentinfo[ 'openid'] != data['openid']: authorreply = int( to_string( r.hget('comments:{}'.format(data['replyid']), 'authorreply'))) + 1 r.hset('comments:{}'.format(data['replyid']), 'authorreply', authorreply) r.rpush('subcomments:{}'.format(data['replyid']), data['cid']) else: r.lpush('post:{}:comments'.format(data['postid']), data['cid']) # if hostid!=data['userid']: # 评论通知效果先不考虑 # r.lpush('user:{}:comments'.format(data['replyuserid']),cid) r.incr('post:{}:commentsnum'.format(data['postid'])) r.hmset('comments:{}'.format(str(data['cid'])), data) return Comment(data['cid'])
def getThumbs(self): tmp = r.get("comment:{}:thumbs".format(self.id)) if tmp == None: return '0' return to_string(tmp)
def commentsnum(self): tmp = r.get("post:{}:commentsnum".format(self.id)) if tmp == None: return '0' return to_string(tmp)
def collects_num(self): tmp = r.get("post:{}:collects".format(self.id)) if tmp == None: return '0' return to_string(tmp)
def getThumbs(self): return to_string(r.get("post:{}:thumbs".format(self.id)))
def getViews(self): return to_string(r.get("post:{}:views".format(self.id)))
def username(self): return to_string(r.hget('user:{}'.format(self.userid), 'username'))