目錄:
  1. Dedis数据结构

    Dedis数据结构

    閱讀時間:全文 261 字,預估用時 2 分鐘
    創作日期:2017-04-02
    文章標籤:
     
    BEGIN

    前言

    一般使用hash结构较多,尤其是存储对象,非常使用. 比如有多个对象存入redis中(redis中数据读取速度快常用于做数据中转):

    man = {
      'smoke': 'No',
      'wine': 'year, is very good!'
    }
    woman = {
      'smoke': 'No',
      'win': 'No'
    }
    #省略连接操作
    #此时用hset存入序列化后的对象到redis
    r.hset('human', '男人', json.dumps(man))
    r.hset('human', '女人', json.dumps(woman))

    在NodeJS中取出redis中的数据:

    //省略连接操作
    slient.hget('human', '男人', function(err, reply){
      //反序列化并解析成js对象赋值给man
      man = JSON.parse(reply);
    });
    //或者取出整个human
    slient.hgetall('human', function(err, reply){...})

    redis常用数据结构

    1. 字符串 string

      • set str haha
      • get str
      • del str
    2. 哈希对象 hash

      • hset dog eating yes runing yes speak none
      • hdel dog eating
      • hgetall dog
    3. 链表,栈 list

      • lpush students lucy
      • lpop students
      • lrange students 0 10
      • lindex students 0
    4. 集合 set

      • sadd students lucy
      • smembers students
      • sismember students lucy #检查lucy是否在students里
      • srem students lucy #移除元素
    5. 可排序集合 zset

      • zadd students 0 lucy
      • zrem students lucy #删除元素
      • zrange students 0 10
      • zrangebyscore students 0 10 #指定分值范围
      • 注:同时显示分值后面加 withscores
    FINISH

    隨機文章
    人生倒計時
    default