Redis Common operations

Source: Internet
Author: User

One, common commands of type string

Set key1 com #一个key对应一个value, multiple copies, overwriting the previous value

Setnx key1 Zhangsan #如果key1不存在则创建key1, and returns 1, if Key1 exists, the value of key1 will not be overwritten and return 0

Setex Key3 Fansik #创建key3设置过期时间为100秒

TTL Key3 #查看key还有多久过期

Mset Key4 123 Key5 213 #同时设置多个值

Mget key1 key2 Key4 key5 #批量获取key值

Del Key1 #删除key1

Ii. common commands for hash types

Hset hash1 name Fanjinbao #建立一个key为name, value is a hash of Fanjinbao

Hget hash1 name #获取name的value

Hmset HASH1 Work It Singel Yes #批量创建键值对

Hmget HASH1 Work Single #批量获取key的value

Hgetall Hash1 #获取hash1所有的key和value

Hdel hash1 name #删除hash1中的name

Hkeys Hash1 #列出hash1所有的key值

Hvals Hash1 #列出hash1所有的value

Hlen Hash1 #查看hash1有几个filed (return its length)

Iii. Common commands for list types

Lpush List A b c #从左向list中添加a c c three values

Lrange list 0-1 #列出list中的值 (no rrange)

Lpop list #取最左侧的值 (the value taken is equivalent to being deleted)

Rpush List 1 2 3 #从右向list中添加1 2 33 values

Rpop list #取最右侧的值 (the value taken is equivalent to being deleted)

Linsert list before 1 ABX #在1的前面插入abx

LSet List 3 Hello #修改指定元素的值

Lindex List 1 #查看列表中的值 (and lpop the difference is that the viewed value is not deleted)

Llen List #查看列别中值得个数

Iv. common commands for set types

Sadd Set1 a b c D #向集合中添加元素

Smembers Set1 #查看集合中的元素

Srem Set1 a #删除集合中的元素

Spop Set1 #取出集合中的元素 (the value removed will be removed)

Sdiff Set1 Set2 #比较两个集合差值, which collection precedes the previous set of elements that are not in the latter collection

Sdiffstore Set3 Set1 Set2 #将set1与set2的差值存储到set3中

Sinter Set1 Set2 #列出set1和set2中相同的元素 (intersection)

Sinterstore Set3 Set1 Set2 #将交集结果存储到set3中

Sunion Set1 Set2 #列出set1和set2并集 (Set1 and Set2 all elements)

Sunionstore Set3 Set1 Set2 #将并集结果保存到set3中

Sismember Set3 Fansik #判断set3里是否有fansik, there is return 1, no then 0

Srandmember Set3 #随机取出set3中的一个元素

V. Common commands for Zset types (ordered collection)

Zadd Zset 1 123 2 234 #创建有序集合

Zrange zset 0-1 #查看有序集合元素, displayed sequentially

Zrange zset 0-1 withscores #带分值显示

Zrem Zset 123 #删除一个元素

Zrank Zset 555 #返回元素的索引值, index value starting from 0, sorted by score

Zrevrank zset 444 #返回元素的索引值, index value starting from 0, reverse sort by score

Zcard Zset #反馈集合中所有元素的个数

Zcount Zset 1 #返回分值范围内1-10 of the number of elements

Elements of Zrangebyscore Zset 1 #返回分值范围内1-10

Zremrangebyrank Zset 0 2 #删除索引范围0-2 elements, sorted by score

Elements of Zremrangebyscore Zset 1 #删除分值范围1-10

Six, key values and server commands

Keys * #取出所有key值

Keys set* #模糊匹配

exists list #有list键返回1, otherwise returns 0

Del list #删除list键成功返回1, otherwise returns 0

Expire Set1 #修改set1的过期时间为10秒

TTL set1 #查看set1键还有多长时间过期, unit is S, when Kset1 does not exist, returns-2 when Set1 exists but does not set remaining lifetime, returns 1, otherwise, returns the remaining lifetime of Set1

Select 1 #选择数据库, 0 data is entered by default

Move Set1 2 #把set1移动到2数据库

Persist Zset #取消zset的过期时间

Randomkey #随机返回一个key

Rename Key4 Keyfansik #重命名一个key

Type Keyfansik #查看一个键的类型

VII. Service-related operations

Dbsize #返回当前数据库中键的个数

Info #返回redis数据库状态信息

Flushdb #清空当前数据库中所有的键

Flushall #清空所有数据库中的所有的key

Redis Common operations

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.