zoukankan      html  css  js  c++  java
  • redis在微博与微信等互联网应用笔记

    Redis实战redis在微博与微信等互联网应用实例讲解全集

    1. 对象缓存

    id user balance
    1 john 1200
    2 tom 3000

    对于这种存储,redis可以使用mset or hmset实现

        mset user:{userId}:name john user:{userId}:balance:1200
        mget user:{userId}:name user:{userId}:balance
        mset user:1:name john user:1:balance:1200
        mget user:1:name user:1:balance
    
        hmset user {userId}:name john {userId}:balance 1888
        hmget user {userId}:name {userId}:balance
        hmset user 1:name john 1:balance 1888
        hmget user 1:name 1:balance
    

    2. 计数器

        incr article:readcount:{文章id}    
        get article:readcount:{文章id}
    

    3. web集群session共享

    spring session + redis实现session共享   
    

    4. 分布式系统全局序列号

    分库分表情况下,自行生成主键id,高并发情况下,每次批量取出1000个id存入内存中供使用,用完再取

        INCRBY orderId 1000   //redis批量生成序列号提升性能
    

    5. redis实现电商购物车

    电商购物车

    1. 以用户id为key
    2. 商品id为field
    3. 商品数量为value
        //向购物车添加商品
        hset cart:1001 10099 1
        hset cart:1001 20088 1
        hset cart:1001 30088 1
        //往存在购物车中的商品增加数量
        hincrby cart:1001 10099 1
        //获取购物车中商品的数目
        hget cart:1001 10099
        //获取购物车中存在的不同商品总数
        hlen cart:1001
        //删除商品
        hdel cart:1001 10099
        //获取所有商品
        hgetall cart:1001
    

    Hash结构优缺点

    优点

    1. 同类数据归类整合存储,方便数据管理
    2. 相比string操作消耗内存与cpu更小
    3. 相比string存储更节省空间
    

    缺点

    1. 过期功能不能使用在field,只能用在key上
    2. redis集群架构下不适合大规模使用
    

    队列的使用

    set的使用

  • 相关阅读:
    Quartz2D使用(绘图路径)
    Quartz2D简单使用(三)
    Quartz2D使用(矩阵操作)
    Quartz2D使用(图片剪切)
    Quartz2D简单使用(二)
    Quartz2D使用(图形上下文栈)
    Quartz2D简单使用(一)
    Quartz2D简单介绍
    虚基类
    傅立叶变换理解
  • 原文地址:https://www.cnblogs.com/ifme/p/11796477.html
Copyright © 2011-2022 走看看