JavaWeb [Redis] data types and instructions

JavaWeb [Redis] data types and instructions

Redis data type

(1) Redis and Map analogy
Redis stores data in the form of keys and values. Redis can be understood as a Map collection
1: Key: all strings
2: Value: There are five data types: string json string
string (String)! !! Key----value Map<String,String>
hash (hash) Big key—small key—value Map<String,Map<String,String>>
list of strings (list) key----value 1 , Value 2, value 3 Map<String,LinkedList>
string set (set) key----value 1, value 2, value 3 Map<String, HashSet>
sorted set key--- -Value 1, Value 2, Value 3 Map<String,LinkedHashSet>
Insert picture description here

  • (2) What is enough to master the value of the string type?
    The other four collections can be converted into json strings, no need to master

Redis instruction-string type***

  • (1) String type string
  • (2) Instructions
 set name baoqiang  //添加一个键值对  如果键存在,则修改  set()
 get name           //根据键获取值
 del name           //根据键删除键值对
 mget name age      //根据多个键查看值
1234

Redis instruction-Hash type

  • (1) Hash (hash)
  hset myhash username haohao  //添加数据
  hset 北京    111     冰冰
  hget myhash username         //根据大键和小键获取值
  hdel myhash username         //根据大键和小键删除值
1234

Redis instruction-list type List

  • (1)
    The value of list type list can be repeated.
    Stack: first in, last out
  • (2) Instructions
lpush mylist a b c  //压栈 添加数据,键为mylist 值为:a b  c
lpop  mylist        //从左边弹栈  删除操作,删除的顺序和添加的顺序相反
rpop  mylist        //从右边弹栈
123

Insert picture description here

Redis instruction-set type set

  • (1)
    The value of the collection type set cannot be repeated
  sadd myset a b c  //添加数据
  smembers myset    //获取数据
  srem myset a b    //删除数据
123

Redis instructions-general instructions

  • (1) Redis general instructions

    Commands that can be used for all data types

      keys *      //查看Redis中所有的键  
      del  myset  //删除指定的键值对
      exists key  //判断键是否存在   0表示不存在,  1表示存在
      type myset  //测试你的键是什么类型
    

Guess you like

Origin blog.csdn.net/qq_37924905/article/details/108737225