• Redis基础篇


    Redis命令

    String类型

    在这里插入图片描述
    192.168.86.128:6379> keys *
    (empty array)
    192.168.86.128:6379> keys a*
    (empty array)
    192.168.86.128:6379> del name
    (integer) 0
    192.168.86.128:6379> mset k1 v1 k2 v2 k3 v3
    OK
    192.168.86.128:6379> keys *
    1)“k3”
    2)“k1”
    3)“k2”
    192.168.86.128:6379> del k1 k2 k3
    (integer) 3
    192.168.86.128:6379> keys *
    (empty array)
    192.168.86.128:6379> exists k1
    (integer) 0
    192.168.86.128:6379> expire age 20
    (integer) 0
    192.168.86.128:6379> set age 23
    OK
    192.168.86.128:6379> get age
    “23”
    192.168.86.128:6379> expire age 20
    (integer) 1
    192.168.86.128:6379> keys *
    1)“age”
    192.168.86.128:6379> ttl age
    (integer) -2
    192.168.86.128:6379> keys *
    (empty array)
    192.168.86.128:6379> set name rose
    OK
    192.168.86.128:6379> set name jack
    OK
    192.168.86.128:6379> get name
    “jack”
    192.168.86.128:6379> mset k1 v1 k2 v2 k3 v3
    OK
    192.168.86.128:6379> mget k1 k2 k3 name
    1)“v1”
    2)“v2”
    3)“v3”
    4)“jack”
    192.168.86.128:6379> set age 18
    OK
    192.168.86.128:6379> get age
    “18”
    192.168.86.128:6379> incr age
    (integer) 19
    192.168.86.128:6379> get age
    “19”
    192.168.86.128:6379> incrby age 3
    (integer) 22
    192.168.86.128:6379> get age
    “22”
    192.168.86.128:6379> set score 99.1
    OK
    192.168.86.128:6379> incrbyfloat score 0.9
    “100”
    192.168.86.128:6379> keys *
    1)“k1”
    2)“k3”
    3)“k2”
    4)“score”
    5)“age”
    6)“name”
    192.168.86.128:6379> setnx name lisi
    (integer) 0
    192.168.86.128:6379> setnx name1 lisi
    (integer) 1
    192.168.86.128:6379> get name1
    “lisi”
    192.168.86.128:6379> expire name 10
    (integer) 1
    192.168.86.128:6379> ttl name
    (integer) 6
    192.168.86.128:6379> ttl name
    (integer) 2
    192.168.86.128:6379> ttl name
    (integer) -2
    192.168.86.128:6379> keys *
    1)“k1”
    2)“k3”
    3)“k2”
    4)“score”
    5)“name1”
    6)“age”
    192.168.86.128:6379> setex name 10 jack
    OK
    192.168.86.128:6379> ttl name
    (integer) 5
    192.168.86.128:6379> ttl name
    (integer) 1
    192.168.86.128:6379> ttl name
    (integer) -2

    key的层级

    在这里插入图片描述
    192.168.86.128:6379> set heima:user:1 ‘{“id”:1, “name”:“Jack”, “age”: 21}’
    OK
    192.168.86.128:6379> set heima:user:2 ‘{“id”:2, “name”:“Rose”, “age”: 18}’
    OK
    192.168.86.128:6379> set heima:product:1 ‘{“id”:1, “name”:“小米11”, “price”: 4999}’
    OK
    192.168.86.128:6379> set heima:product:2 ‘{“id”:2, “name”:“荣耀6”, “price”: 2999}’
    OK
    192.168.86.128:6379> keys *
    1)“k3”
    2)“k1”
    3)“heima:user:2”
    4)“score”
    5)“name1”
    6)“heima:product:1”
    7)“heima:product:2”
    8)“k2”
    9)“heima:user:1”
    10)“age”

    Hash类型

    在这里插入图片描述
    在这里插入图片描述
    192.168.86.128:6379> hset heima:user:3 name Lucy
    (integer) 1
    192.168.86.128:6379> hset heima:user:3 age 21
    (integer) 1
    192.168.86.128:6379> hset heima:user:3 age 18
    (integer) 0
    192.168.86.128:6379> hget heima:user:3 age
    “18”
    192.168.86.128:6379> hmset heima:user:4 name hei age 23 sex man
    OK
    192.168.86.128:6379> hmget heima:user:4 name age sex
    1)“hei”
    2) “23”
    3) “man”
    192.168.86.128:6379> hgetall heima:user:4
    1)“name”
    2) “hei”
    3) “age”
    4) “23”
    5) “sex”
    6) “man”
    192.168.86.128:6379> hkeys heima:user:4
    1)“name”
    2) “age”
    3) “sex”
    192.168.86.128:6379> hvals heima:user:4
    1)“hei”
    2) “23”
    3) “man”
    192.168.86.128:6379> hincrby heima:user:4 age 10
    (integer) 33
    192.168.86.128:6379> hvals heima:user:4
    1)“hei”
    2) “33”
    3) “man”
    192.168.86.128:6379> hsetnx heima:user:4 sex woman
    (integer) 0
    192.168.86.128:6379> hsetnx heima:user:3 sex man
    (integer) 1
    192.168.86.128:6379> hgetall heima:user:3
    1)“name”
    2) “Lucy”
    3) “age”
    4) “18”
    5) “sex”
    6) “man”

    List类型

    在这里插入图片描述
    在这里插入图片描述
    192.168.86.128:6379> lpush users 1 2 3
    (integer) 3
    192.168.86.128:6379> lrange users 0 -1
    1)“3”
    2) “2”
    3) “1”
    192.168.86.128:6379> rpush users 4 5 6
    (integer) 6
    192.168.86.128:6379> lpop usres 1
    (nil)
    192.168.86.128:6379> lpop users 1
    1)“3”
    192.168.86.128:6379> lrange users 0 -1
    1)“2”
    2) “1”
    3) “4”
    4) “5”
    5) “6”
    192.168.86.128:6379> rpop users 1
    1)“6”
    192.168.86.128:6379> lrange users 0 -1
    1)“2”
    2) “1”
    3) “4”
    4) “5”
    192.168.86.128:6379> blpop user1 100
    另开一个窗口
    192.168.86.128:6379> lpush user1 jack
    (integer) 1
    192.168.86.128:6379> blpop user1 100
    1)“user1”
    2) “jack”
    (27.58s)

    set类型

    在这里插入图片描述
    在这里插入图片描述

    192.168.86.128:6379> sadd s1 a b c
    (integer) 3
    192.168.86.128:6379> smembers s1
    1)“c”
    2) “a”
    3) “b”
    192.168.86.128:6379> srem s1 a
    (integer) 1
    192.168.86.128:6379> sismember s1 a
    (integer) 0
    192.168.86.128:6379> scard s1
    (integer) 2
    在这里插入图片描述
    192.168.86.128:6379> sadd zs lisi wangwu zhaoliu
    (integer) 3
    192.168.86.128:6379> sadd ls wangwu mazi ergou
    (integer) 3
    192.168.86.128:6379> sinter zs ls
    1)“wangwu”
    192.168.86.128:6379> sdiff zs ls
    1)“lisi”
    2)“zhaoliu”
    192.168.86.128:6379> sunion zs ls
    1)“lisi”
    2)“zhaoliu”
    3)“wangwu”
    4)“mazi”
    5)“ergou”
    192.168.86.128:6379> sismember zs lisi
    (integer) 1
    192.168.86.128:6379> sismember ls zhangsan
    (integer) 0
    192.168.86.128:6379> srem zs lisi
    (integer) 1
    192.168.86.128:6379> smembers zs
    1)“wangwu”
    2)“zhaoliu”

    sortedset类型

    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    192.168.86.128:6379> zadd stus 85 Jack 89 Lucy 82 Rose 95 Tom 78 jerry 92 amy 76 miles
    (integer) 7
    192.168.86.128:6379> zrem stus Tom
    (integer) 1
    192.168.86.128:6379> zrank stus Rose
    (integer) 2
    192.168.86.128:6379> zrevrank stus Rose
    (integer) 3
    192.168.86.128:6379> zcard stus
    (integer) 6
    192.168.86.128:6379> zcount stus 0 80
    (integer) 2
    192.168.86.128:6379> zincrby stus 2 amy
    “94”
    192.168.86.128:6379> zrevrange stus 0 2
    1)“amy”
    2) “Lucy”
    3) “Jack”
    192.168.86.128:6379> zrangebyscore stus 0 80
    1)“miles”
    2) “jerry”

  • 相关阅读:
    华为服务器安装操作系统
    Oracle DBCA建库
    【stack】【queue】【priority_queue】【deque】详解
    [问题解决] java中InputStream转为MultipartFile
    JavaFX:获取屏幕尺寸
    抖音API:item_search_video-根据关键词取视频列表
    Django中HTML判断等于/不等于/包含/不包含某个字符
    Stable Diffuse 之 安装文件夹、以及操作界面 UI 、Prompt相关说明
    zookeeper集群+kafka集群
    美国各流域边界下载,并利用arcgis提取与处理
  • 原文地址:https://blog.csdn.net/qq_46198929/article/details/125951728