Redis data storage type introduction

Redis data storage type introduction

Redis data type (commonly used in 5)
string String
hash HashMap
list LinkedList
set HashSet
sorted_set TreeSet
Insert picture description here

string type

Insert picture description here
Basic operation of string type
Add/modify data: set key value
Get data: get key
Delete data: del key
Add/modify multiple data: mset key1 value1 key2 value2
Get multiple data: mget key1 key2...
Get the number of data characters: Strlen key
appends information to the back of the original information (if there is no information, create a new one): append key value

Extended operation type string data
solutions

provided the specified range increases the numerical data value
incr key: increments. 1
incrby Key INCREMENT: the specified number of increments
incrbyfloat key increment: Increase decimal
setting numerical value range specified data reduction
DECR Key
decrby The key increment
setting data has a specified life cycle
setex key seconds value
psetex key milliseconds value
string key setting conventions
hot data in the database key name convention

eg1: table name: primary key name: primary key value: field name

hash type

Add: hset key field value
Get: hget key field
hgetall key
delete: hdel key field1 [field2]
Add/modify multiple data: hmset key field1 value1 field2 value2 …
Get multiple data: hmget key field1 field2 …
Get in the hash table Number of fields: hlen key to
get the specified field in the
hash table : hexists key field to get all the field names or field values ​​in the hash table: hkeys key, hvals key
set the numerical data of the specified field to increase the value of the specified range: hincrby key field increment, hincrbyfloat key field increment

Basic operation of list type data

Add/modify data
lpush key value1 [value2]…
rpush key value1 [value2] …
get data
lrange key start stop
lindex key index
llen key

Guess you like

Origin blog.csdn.net/yang13676084606/article/details/105160840