zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Git-Runoob:Git 查看提交历史
    Git-Runoob:Git 分支管理
    Git-Runoob:Git 基本操作
    Git-Runoob:Git 创建仓库
    weblogic11g 安装集群 —— win2003 系统、单台主机
    关于条件宏的易错点
    关于端口号你知道多少!
    POJ 2114 Boatherds【Tree,点分治】
    Android应用开发学习笔记之Intent
    对于接收到的GPS信息详解
  • 原文地址:https://www.cnblogs.com/lisqiong/p/5587663.html
Copyright © 2011-2022 走看看