zoukankan      html  css  js  c++  java
  • 【转】Redis 基础操作和命令

    笔记

    Redis提供了六种基本的数据结构:String,Hash,List,Set,Sorted Set,HyperLogLog。
    Redis的特点:纯内存操作,单线程工作模型,非阻塞I/O多路复用。
    Redis数据删除策略:定期删除(每100ms随机抽查key),惰性删除(key被命中时检查)
    Redis内存淘汰策略:推荐 redis.conf 配置中# maxmemory-policy allkeys-lru ,即内存无空间写入时,删除最近最少使用的key

    常用操作

    docker run --restart=always -d -p 6379:6379 --name rain-redis redis --requirepass "123456"

    终端连接

    redis-cli -a 123456

    查看配置

    # 查看密码
    config get requirepass
    
    # 查看最大内存限制
    config get maxmemory
    
    # 查看最大连接数
    config get maxclients
    
    # 查看内存淘汰策略
    config get maxmemory-policy

    常用指令

      1.key 相关

    # 查询key类型
    type <key>
    
    # 检验key是否存在
    exists <key>
    
    # 按模式输出存在的key
    keys <pattern>
    # 输出所有存在的key
    keys *
    
    # 删除key
    del <key1> <key2> ...
    
    # 设置过期时间
    expire <key> <seconds>
    
    # 取消过期时间
    persist <key>

      2.String 类型

    # 新增
    set <key> <value>
    
    # 获取
    get <key>
    
    # 批量新增
    mset <key1> <value1> <key2> <value2> ...
    
    # 批量获取
    mget <key1> <key2> ...
    
    # 追加字符串
    append <key> <append_value>
    
    # 获取字符串长度
    strlen <key>

      3.Hash 类型

    # 新增
    hset <key> <field> <value>
    
    # 获取
    hget <key> <field>
    
    # 批量新增
    hmset <key> <field1> <value1> <field2> <value2> ...
    
    # 批量获取
    hmget <key> <field1> <field2> ...
    
    # 统计field个数
    hlen <key>
    
    # 列出所有的field
    hkeys <key>
    
    # 列出所有的value
    hvals <key>
    
    # 列出所有的key和value
    hgetall <key>

      4.List 类型

    # 左新增
    lpush <key> <value>
    
    # 右新增
    rpush <key> <value>
    
    # 左删除并返回
    lpop <key>
    
    # 右删除并返回
    rpop <key>
    
    # 返回list长度
    llen <key>
    
    # 按index设置value
    lset <key> <index> <value>
    
    # 按index返回value
    lindex <key> <index>
    
    # 按index范围返回list
    lrange <key> <start> <stop>
    # 返回全部的list
    lrange <key> 0 -1
    
    # 删除count个等于value的值,count>0 正向搜索,count<0 逆向搜索,count=0 全部删除
    lrem <key> <count> <value>

      5.Set 类型

    # 新增
    sadd <key> <member1> <member2> ...
    
    # 统计成员数
    scard <key>
    
    # 删除成员
    srem <key> <member1> <member2> ...
    
    # 显示成员
    smember <key>

      6.Sorted Set 类型

    # 新增
    zadd <key> <score1> <member1> <score2> <member2> ...
    
    # 统计成员个数
    zcard <key>
    
    # 删除成员
    zrem <key> <member1> <member2> ...
    
    # 按index显示成员
    zrange <key> <start> <stop>
    # 显示全部成员
    zrange <key> 0 -1
    
    # 按分数范围显示成员
    zrangebyscore <key> <min> <max>

      7.HyperLogLog 类型,常用来做基数统计

    # 新增
    pfadd <key> <element1> <element2> ...
    
    # 统计基数
    pfcount <key1> <key2> ...
    
    # 合并HyperLogLog
    pfmerge <destkey> <sourcekey1> <sourcekey2>

    一图浏览Redis基础操作和命令

     

    Redis 命令参考

    http://doc.redisfans.com/


    作者:一杉风雨
    链接:https://www.jianshu.com/p/917f6b826d3a
    来源:简书
    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

  • 相关阅读:
    How to convert VirtualBox vdi to KVM qcow2
    (OK)(OK) adb -s emulator-5554 shell
    (OK)(OK) using adb with a NAT'ed VM
    (OK) How to access a NAT guest from host with VirtualBox
    (OK) Creating manually one VMs from an existing VDI file in CLI (VBoxManage) in Fedora 23
    (OK)(OK) Creating VMs from an existing VDI file in CLI (VBoxManage) in Fedora 23
    (OK) Creating_VMs_from_an_existing_VDI_file.txt
    (OK) Creating VMs from an existing VDI file —— in OS X
    (OK) install_IBM_SERVER.txt
    (OK) install chrome & busybox in android-x86_64 —— uninstall chrome
  • 原文地址:https://www.cnblogs.com/appium/p/12033898.html
Copyright © 2011-2022 走看看