Redis various types of data commands

Source: Internet
Author: User
Tags touch command

Key operation

Keys * shows all the keys
Keys key* Show all keys with key
exists name to determine if the key with name, the successful return 1, the unsuccessful return 0
Del Key1 Delete Key1
Expire Key1 100 sets an expiration time of 100 seconds for Key1.
TTL key1 to view Key1 expiration time
Select 0 Choose a library
Move Set1 2 Move the Set1 key to the 3rd library
Persist Key1 Cancel the expiration time of Key1
Randomkey randomly displays a key
Rename Key1 name2 Change the name of a key
Type Key1 View Key1 data type
Server service Operations

Dbsize shows how many key numbers are in the current database
Info View currentRedisThe state
FLUSHDB clears all current keys
Flushall clears all keys in the database
String type

Set Key1 AAAA adds a key1
Get Key1 Extract Key1
Setnx Key1 AAA is similar to touch command, if Key1 has a value then the assignment is unsuccessful, and only if the Key1 has no value will the value be successfully assigned.
Setex Key1 Jjllk assigns a key1 to key1 a 100-second expiration time
TTL Key1 Viewing the Key1 's life cycle
Mset key1 99a key2 111 Key3 AAA means a string of keys can be assigned consecutively
Mget Key1 Key2 Key3 means to extract the key continuously.
Hash type

Create a hash group User1

Hset user1 name LV
Hset User1 age 30
Hset User1 Job It
Show it all with Hgetall user1, or use Hget user1 age to show only the age in it

Batch to create a user2 hash group

Hmset user2 name Xiaoxiao Age Job Techer batch Create a hash group on the same line
Hgetall User2 Extract All
Hmget user2 name age extracts only two
Hdel User2 Job only deletes the job record inside the user2.
Hkeys user2 extracts all the keys inside, without a value
Hvals user2 extracts all values from the inside, without the key
Hlen User2 View Hash There are several keys.
List type

Lpush List1 the "AAA BBB" command means inserting data from the left side of the data. The oldest inserted data is constantly moved to the right
Rpush List1 the "AAA BBB" command means inserting data from the right side of the data. The most recently inserted data is constantly moving to the right.
Lrange List1 0-1 shows all the data in this List1 list and marks the location.
Linsert List1 before a E means an e element is added to the front of a list1
LSet List1 4 AAA Change the 5th element value inside the List1 to AAA
Lindex list1 0 View the value of the 1th element inside the List1
Lindex List1 3 View the value of the 4th element inside the List1
Llen List1 See how many elements there are in List1
Rpop List1 starts from the right of the List1 list and takes the first number out. And will empty this value.
Lpop List1 The value from the left of the List1 list, and takes the first number out. And will empty this value.
Set type

Add a collection named Set1

Sadd Set1 JLKJL
Sadd Set1 Linx
Sadd Set1 DDD
Sadd Set1 Aava
Srem Set1 DDD Delete the DDD element inside the Set1
Smembers Set1 can take out the value of this collection, but the value of the collection is random and does not hold the position of the key value.
Spop Set1 randomly takes out an element and deletes it
Sdiff Set1 Set2 The difference set, with Set1 as the standard, showing Set2 elements without Set1
Sdiffstore setc Set1 Set2 The difference set, and save the results in SETC.
Sinter Set1 Set2 to ask for an intersection and show it out
Sinterstore setc Set1 Set2 the intersection of Set1 and Set2, and deposited him in the setc.
Sunion Set1 Set2 for Set1 and Set2, and shows
Sunionstore setc Set1 Set2 for Set1 and Set2, and deposited setc inside
Sismember Set1 DDD To determine whether an element is in Set1
Srandmember Set1 randomly extracts an element, but does not delete it
Zset type

Add an ordered collection named Set2

Zadd Set2 "AAB:"
Zadd Set2 2 "AACB"
Zadd Set2 "A55ACB"
Zadd Set2 4 "AOO55ACB"
Zrange Set2 0-1 is extracted from the sequence, the lower the number in front of the value, the higher the row ahead.
Zrevrange Set2 0-1 The inverted sequence is extracted, the higher the number in front of the higher the row in front of the.
Zrange Set2 0-1 Withscores shows the value of Set2 and the index value
Zrem Set2 AaB Delete the AAB element inside
Zrank Set2 AaB shows the index value of AAB
Zrevrank set2 AAB Reverse Display index value
Zcard Set2 Displays the number of all elements in the collection
Zcount Set2 2 12 Displays the number of elements that match between 2 and 12 by index values.
Zrangebyscore Set2 2 12 Displays a number of matching elements between 2 and 12 by index values and displays his value
Zremrangebyrank Set2 0 3 matches an element between 0 and 3 by index value and deletes the corresponding element
Zremrangebyscore Set2 2 12 Displays a number of matching elements between 2 and 12 by index values, and removes the corresponding element.

Redis various types of data commands

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.