예제 #1
0
    def create(username, password):
        user_id = rdb.incr("user:uid")
        if not rdb.get("user:username:%s" % username):
            rdb.set("user:id:%s:username" % user_id, username)
            rdb.set("user:username:%s" % username, user_id)

            salt = SALT
            rdb.set("user:id:%s:password" % user_id, salt + password)
            rdb.lpush("users", user_id)
            return User(user_id)
        return None
예제 #2
0
    def create(user, content):
        post_id = rdb.incr("post:pid")
        post = Post(post_id)
        post.content = content
        post.user_id = user.id
        #post.created_at = Time.now.to_s
        user.add_post(post)  #add_post?????
        rdb.lpush("timeline", post_id)
        for follower in user.followers:  #user.followers??????
            follower.add_timeline_post(post)  #add_timeline_post?????

        mentions = re.findall('@\w+', content)
        for mention in mentions:
            u = User.find_by_username(mention[1:])
            if u:
                u.add_mention(post)  #add_mention?????
        return post_id
예제 #3
0
 def add_mention(self, post):  #@???????
     rdb.lpush("user:id:%s:mentions" % self.id, post.id)
예제 #4
0
 def add_timeline_post(self, post):  #这个方法是干什么的?????和add_post的区别???
     rdb.lpush("user:id:%s:timeline" % self.id, post.id)
예제 #5
0
 def add_outmessage(self, outmessage):
     rdb.lpush("user:id:%s:outbox" % self.id, outmessage.id)
     rdb.sadd('outbox:id', outmessage.id)
예제 #6
0
 def add_inmessage(self, inmessage):
     rdb.lpush("user:id:%s:inbox" % self.id, inmessage.id)
     rdb.sadd('inbox:id', inmessage.id)
예제 #7
0
 def add_post(self, post):
     rdb.lpush("user:id:%s:posts" % self.id, post.id)
     rdb.lpush("user:id:%s:timeline" % self.id, post.id)
     rdb.sadd('posts:id', post.id)