Summary of Redis simple commands

Source: Internet
Author: User

Basic operation of the Redis key:

Keys Test*del test_string

String type operation method:

Set test_string abcget test_string

List basic operations: In Redis, the list type is a list of strings sorted by insertion order. Like a regular list in a data structure, we can add new elements to their head (left) and tail (right). When inserting, if the key does not exist, Redis creates a new linked list for that key. Conversely, if all the elements in the list are removed, the key will be removed from the database as well. The maximum number of elements that can be contained in a list is 4294967295.

Lpush test_list a b clrange test_list 0-1lpop test_list

Sets basic operations: Unlike the list type, duplicate elements are not allowed in the set collection, which is identical to the set container in the C + + standard library. In other words, if you add the same element more than once, only one copy of the element will be preserved in set. The set type has a functionally important feature in comparison to the list type, which is to perform aggregate compute operations between multiple sets on the server side, such as unions, intersections, and differences. Because these operations are done on the server side, they are highly efficient and also save a lot of network IO overhead.

Sadd Test_set a b c dsmembers Test_setsrem Test_set A



Sorted-sets basic operations: Sorted-sets and sets types are very similar, both are collections of strings and do not allow duplicate members to appear in a set. The main difference between them is that each member of the sorted-sets has a fraction (score) associated with it, and Redis is sorting the members of the collection from small to large by fractions. However, it is important to note that although the members in the Sorted-sets must be unique, the fractions (score) can be duplicated.

Zadd  test_zset 6 "sex" 7 "Seven" one "eleven" Zrevrange test_zset 0-1 withscoreszrange test_zset 0-1 withscoreszrem TE St_zset "Sex" zadd test_zset 7 "seven__" Zadd test_zset 8 "seven__"

Hashes Basic operation: We can consider the hashes type in Redis as a map container with string key and string value. Therefore, this type is ideal for storing information about value objects. such as username, password, and age. If a hash contains very few fields, the data of that type will take up only a small amount of disk space. Each hash can store 4,294,967,295 key-value pairs.

Hset test_hash_key key1 value1hgetall test_hash_keyhget test_hash_key key2hset test_hash_key key2 Value2hdel TEST_HASH_ KEY Key1

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Summary of Redis simple 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.