美文网首页redis
redis 基本介绍

redis 基本介绍

作者: 文刀雨 | 来源:发表于2018-11-15 14:13 被阅读0次

    通用命令

    1. keys *
      遍历所有key
      keys [pattern]
      keys 命令一般不再生产环境中使用
      时间复杂度O(n)
      什么时候用?
      1.热备从节点
      2.scan
    2. dbsize
      计算key的总数
    3. exists key
      检查key 是否存在 0不存在 1存在
    4. del key[key...]
      删除指定的key-value
    5. expire key seconds
      key在seconds秒后过期
      ttl key
      查看key剩余的过期时间
      persist key
      去掉key的过期时间
    6. type key
      返回key 的类型

    数据结构和内部编码

    数据结构和内部编码.png

    单线程架构

    单线程.png
    单线程为什么这么快
    1. 纯内存
    2. 非阻塞IO
    3. 避免线程切换和静态消耗
    注意
    1. 一次支持运行一条命令
      响应时间大概是100ns
    2. 拒绝长(慢)命令
      keys,flushall,flushdb,slow lua script, mutil/exec,operate big value(collection)
    3. 其实不是单线程
      fysnc file descriptor
      close file descriptor

    相关文章

      网友评论

        本文标题:redis 基本介绍

        本文链接:https://www.haomeiwen.com/subject/cghyfqtx.html