Redis - Hash and List type

Hash

如果使用字符串类型来存储对象,需要大量的变量来存储Redis设计了一个专门存储对象的数据类型--hash

HSET Key Field, value
EG: HSET U1 name "Liling" attribute (field) # save the object (key) and value (value)
hget Key Field,
EG: hget U1 name # get the object property value
hmset Key f1 v1 F2 v2 ...
EG hmset u1 name liming id 2 age 22 # save the object (key) of the plurality of attributes (field) and the value (value):
hmget Key F1 F2 F3 ...
value hmget u1 name acquired plurality of object attributes # Age ID: EG
hgetall key
EG: hgetall U1 # acquired key defines all attributes and values
hkeys key
EG: hkeys U1 # acquired key corresponding to all the attribute names
hvals key
EG: hvals U1 # acquires all the properties key corresponding to the value of
hlen key
EG: hlen U1 # Get the number key corresponding attribute
hexists key Field
EG: hexists # U1 name attribute is determined whether there exists a return, there is no return 0
HDEL key Field
EG: HDEL U1 ID # key to delete the corresponding attribute (Field), attention only delete property, do not delete the object
hstrlen key feild
eg: hstrlen u1 name # Get the length of the key corresponding to the property worth
hincrby key (numerical) value Field
EG: Age 10 # U1 hincrby value calculation
hsetnx key Field
EG: hsetnx Liming # U1 name if no matter if

Here Insert Picture Description

List

 list 列表(字符串列表)底层使用双向链表实现,有序存储多个数据,列表值可以重复。

Key v1 v2 v3 ... LPUSH
EG: LPUSH the Users Dandan, chenkun Lilei # save more elements from the left to the list after the last out to create
RPUSH Key v1 v2 v3 ...
EG: RPUSH the Users LL kk jj ii HH # save from the right the plurality of elements in list to
Lrange Key Start End
EG: Lrange Users # 0 100 show list corresponding to the index element. Loop output list 0 100,0 -1 indicates the last
linsert the BEFORE Key | an AFTER Pivot value
EG: the before kk tingting # linsert the Users in the corresponding position insert elements
RPOP Key
EG: RPOP Key # delete the last element
lpop Key
EG: lpop users # delete the first element
LSET Key index value
EG: value lset users 0 mmm # modify index corresponding elements
lindex Key index
EG: value lindex users 5 # Gets index corresponding elements
LLEN Key
EG: LLEN get a list of users # length (number)
LTRIM STOP Key Start
eg: ltrim users 2 5 # cutting list, cutting list will change after note (caution) occurs
lrem Key COUNT value
EG: lrem the Users LL # 2 remove an element of the same count (how many) a

Here Insert Picture Description

Published 162 original articles · won praise 9 · views 3086

Guess you like

Origin blog.csdn.net/ll_j_21/article/details/104712534
Recommended