• redis+php微博功能的redis数据结构设计总结(四)


    概述:

    1.完全采用redis作为数据库实现微博的登录
    2.发布
    3.微博的显示
    4.实现整个功能使用了redis的string,list,hashes四个数据类型,以及string类型的数值自增功能

    一、用户信息

    将数据以string类型存储

    incr global:userid  (存储用户自增id)
    set user:userid:1:username zhangshan
    set user:userid:1:password 1212121212
    set user:username:zhangshan:userid 1

    二、关注与粉丝

    将关注他人与自己粉丝数据以set集合类型存储

    sadd followed:1  2        (将用户id2存入成id的粉丝)

    sadd following:1  3      (用户id1关注用户id3)

    三、微博发布

    将微博发布分为

    1.发布微博内容并以hash类型存储微博发布的内容相关信息

    incr global:postid                                                                       (存储微博自增id)

    hset post:postid:$postid userid 2                                            (存储微博的用户id)

    hset post:postid:$postid username dongzi                             (存储微博的用户id)

    hset post:postid:$postid time      1466020851                       (存储微博的发布时间)

    hset post:postid:$postid content     这是一条微博内容           (存储微博内容)

    2.获取用户的所有粉丝及用户自身的id
    smembers followed:2   (获取用户id2的所有粉丝)

    3.将发布的postid与用户信息关联

    lpush recivepost:3 $postid   (将用户发布的最新id$postid给用户id3)

    4.单独建立一个list类型存入自己发送的所有微博id
    lpush userpostid:1 $postid

    源码下载地址:https://github.com/lisiqiong/learning/tree/master/rweibo

  • 相关阅读:
    C# 常用函数和方法集
    CSS选择器、优先级和匹配原理
    都是王安石惹的祸?
    世界上的一类
    历史之不可理喻片段
    历史惊人的相似
    20世纪鲜为人知的军事巨灾
    unity制作简单血条
    Unity中Instantiate物体失效问题
    Unity3D实现DoubleClick的一种方法
  • 原文地址:https://www.cnblogs.com/lisqiong/p/5587663.html
Copyright © 2020-2023  润新知