redis的常用命令
redis的常用命令
了解redis的常用命令之前先了解一下redis:redis是一个运行在内存中,存储内容为键值对形式的一个高效的非关系性数据库,redis存储的值类型有很多:string,list, set,sorted set,hash, geospatial,bitmap 等。
string类型的相关操作
SETstores a string value 存储(已存在则修改)一个值.SETNXstores a string value only if the key doesn’t already exist. Useful for implementing locks 存储一个值(只有当这个key不存在的时候).GETretrieves a string value 检索一个值.MGETretrieves multiple string values in a single operation 一次检索多个key.INCRBYatomically increments (and decrements when passing a negative number) counters stored at a given key 根据一个数字自增一个key的value,INCR以1为单位自增.
list类型的相关操作
LRANGE查看list lrange list1 0 -1LPUSHadds a new element to the head of a list; RPUSH adds to the tail 头部添加一个元素, RPUSH 是在尾部添加一个元素.LPOPremoves and returns an element from the head of a list; RPOP does the same but from the tails of a list 头部删除一个元素, RPOP 是在尾部添加一个元素.LLENreturns the length of a list 返回list的长度.LMOVEatomically moves elements from one list to another 将list1 的一个元素移动的list2中去LMOVE list1 list2 LEFT LEFT.LTRIMreduces a list to the specified range of elements 限制list的长度LTRIM list1 0 1.
set类型的相关操作
SADDadds a new member to a set 添加一个成员到set中.SREMremoves the specified member from the set 删除特定的成员.SISMEMBERtests a string for set membership 查询set是否包含一个成员.SINTERreturns the set of members that two or more sets have in common (i.e., the intersection) 返回一个set与2个或多个set的交集.
1 | |
SCARDreturns the size (a.k.a. cardinality) of a set 返回set的大小.
redis的常用命令
https://avatar0813.github.io/2023/06/25/redis/redis常用命令/