Common Redis commands and redis commands

Source: Internet
Author: User

Common Redis commands and redis commands

1. SELECT command

Redis has 0 ~ For 15 databases, SELECT 6 is used to operate under database 6.



2. SET: Value Assignment Command

SET server: name "fido" to SET Key to server: name and Value to "fido"



3. GET: Value command

GET server: name will GET "fido"



4. DEL: delete command

DEL server: name will delete the Key of server: name and its Value.



5. INCR: Self-increasing numeric value command (this is a thread-safe counting command, and the count won't go wrong under multiple threads)

SET ten 10

The result of INCR ten is (integer) 11.



6. EXPIRE: Expiration command

SET timeout "120 s"

EXPIRE timeout expires 60 seconds later



7. TTL (Time To Live): Check the expiration Time

TTL timeout

Result: (integer) 55, with 55 seconds left.

After the timeout: (integer)-2 means it will not exist (if it is-1, this will not expire)



8. List data structure (arranged in a certain order)

RPUSH print "! "Insert to the right of the list "! "

LPUSH print "World" is inserted on the left of the list"

LPUSH print "Hello" insert "Hello" to the left of the list"

LRANGE print 0-1 to get the list sub-set 0 as the initial bit, and-1 is the final bit

Print:

1) "Hello"
2) "World"
3 )"! "

LLEN print returns the list length (integer) 3.

LPOP print displays a data entry from the left of the list.

RPOP print pops up a data from the right side of the list.

Result: LRANGE print 0-1

"World"



9. Set Data Structure (similar to List, but unordered and each element appears only once)

SADD setTest "fucking" adds the "fucking" element to the Set.

SADD setTest "day" adds the "day" element to the Set.

SREM setTest "fucking" deletes the "fucking" element in the Set.

SISMEMBER setTest "fucking" View "fucking" is no longer in set. If 1 is returned, 0 indicates that there is no set.

SMEMBERS setTest: "day"

SUNION setTest setTest2 connects two sets



10. Sorted Sets)

ZADD sortedSetTest 1 "A" insert element "A" sort by number 1

ZADD sortedSetTest 2 "B" insert element "B" sort by number 2

ZADD sortedSetTest 3 "C" insert element "C" sort by number 3

ZRANGE sortedSetTest 0-1

View results:

""
"B"
"C"



11. Hash Data Structure

HSET user: 007 name "James Bond" set Key = user: 007, Value = name "James Bond" (this is another Key-Value)

HSET user: 007 gender "male"

HGET user: 007 name query the Value of name under user: 007

Result:

"James Bond"

HGETALL user: 007 query all Key-values under user: 007

Result:

1) "name"
2) "James Bond"
3) "gender"
4) "male"

HMSET user: 008 name "Xingchi_Zhou" gender "male": directly set multiple Key-values to the same effect as the values assigned by the preceding statements.

HSET user: 007 bulletCount 1 Value: number of bullets "1"

HINCRBY user: 007 bulletCount 100 increase value: number of bullets (integer) 101

HDEL user: 007 bulletCount Delete value: number of bullets (nil)



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.