Redis is divided into five basic data types: String, Hash, List, Set, SortedSet
1.String
增 set key value
Check get key
改 set oldkey newvalue
删del key
Composite: getset first set and then get
Self-increment: incr key is equivalent to key++
Decrement : decr key is equivalent to key--
2.hash
Features: Similar to Java's HashMap, it is also a key-value pair format, the keys cannot be repeated, and the query is fast
increase
hset library name key value one
hmset library name key value key value ... multiple entries
check
hget library key one
hmget library key key key ... multiple
hgetall library key-value pair
change
hset library existing key
delete
hdel library key delete record
hdel library delete library
3. Store the list
1) The underlying structure of ArrayList is an array, which is fast to search according to the index, and slow to add or delete.
2)Linkedlist底层使用链表,根据指针增删快,查询需要通过下标,从头开始,速度慢
linkedlist
常用命令:
增
头部 : lpush key value1 value2…
尾部 : rpush key value1、value2…
查
lrange key start end
获取链表中从start到end的元素的值,start和end从0开始计数
如果值为负数,表示从链尾开始获得
llen key
获取元素个数
改
lset key index value
index : 0为头元素
-1为尾元素
删
lrem 个数 value 指定
个数为正数,从头到尾查找删除,
个数为负数,从尾到头查找删除,
个数为0,删除所有
lpop key 左端开始
如果该key不存在,返回nil
rpop key 右端开始