redis的5大数据类型

redis五大类型都有key,或者将key理解为java中一个对象
基础指令基本为 COMMAND KEY_NAME

  • 五大数据类型分别为String,Hash,List,Set,SortedSet
  1. 字符串String
    redis 127.0.0.1:6379> SET runoobkey redis
    OK
    redis 127.0.0.1:6379> GET runoobkey
    "redis"
  2. 哈希表Hash
    redis 127.0.0.1:6379> HSET myhash field1 "foo"
    OK
    redis 127.0.0.1:6379> HGET myhash field1
    "foo"
  3. 列表List
    redis 127.0.0.1:6379> LPUSH runoobkey redis
    (integer) 1
    redis 127.0.0.1:6379> LPUSH runoobkey mongodb
    (integer) 2
    redis 127.0.0.1:6379> LPUSH runoobkey mysql
    (integer) 3
    redis 127.0.0.1:6379> LRANGE runoobkey 0 10
    1) "mysql"
    2) "mongodb"
    3) "redis"
  4. 集合Set
    redis 127.0.0.1:6379> SADD runoobkey redis
    (integer) 1
    redis 127.0.0.1:6379> SADD runoobkey mongodb
    (integer) 1
    redis 127.0.0.1:6379> SADD runoobkey mysql
    (integer) 1
    redis 127.0.0.1:6379> SADD runoobkey mysql
    (integer) 0
    redis 127.0.0.1:6379> SMEMBERS runoobkey
    1) "mysql"
    2) "mongodb"
    3) "redis"
  5. 有序集合SortedSet
    redis 127.0.0.1:6379> ZADD runoobkey 1 redis
    (integer) 1
    redis 127.0.0.1:6379> ZADD runoobkey 2 mongodb
    (integer) 1
    redis 127.0.0.1:6379> ZADD runoobkey 3 mysql
    (integer) 1
    redis 127.0.0.1:6379> ZADD runoobkey 3 mysql
    (integer) 0
    redis 127.0.0.1:6379> ZADD runoobkey 4 mysql
    (integer) 0
    redis 127.0.0.1:6379> ZRANGE runoobkey 0 10 WITHSCORES
    1) "redis"
    2) "1"
    3) "mongodb"
    4) "2"
    5) "mysql"
    6) "4"

参考博文:https://www.runoob.com/redis/redis-tutorial.html

posted @ 2023-08-29 16:50  ControlO_o  阅读(14)  评论(0编辑  收藏  举报