Redis data types

Source: Internet
Author: User

iv. Redis data Types
string is the simplest type, you can understand the same type as memcached, a key corresponding to a value, riding on the supported operation is similar to the operation of memcached, it is more functional. Sets the object that can be stored in binary.
/usr/local/redis/bin/redis-cli

127.0.0.1:6379> mset key1 Szk key2 Love Key3 YC
Ok
127.0.0.1:6379> mget key1 Key2 Key3
1) "Szk"
2) "Love"
3) "YC"


List is a linked list structure, the main function is push, pop, get all the values of a range and so on. In Operation Key is understood as the name of the link. Using the list structure, we can easily achieve the latest message ranking and other functions. Another application of list is the message queue, which can take advantage of the push operation of list, the task exists in list, and then the worker thread takes out the task with the pop operation to execute.


127.0.0.1:6379> Lpush List1 123
(integer) 1
127.0.0.1:6379> Lpush list1 AAA
(integer) 2
127.0.0.1:6379> Lpush List1 "123 456"
(integer) 3
127.0.0.1:6379> Rpop List1
"123"
127.0.0.1:6379> Rpop List1
"AAA"
127.0.0.1:6379> Rpop List1

Set is a collection, similar to our set concept in mathematics, the operation of the set has added delete elements, there are many sets of orthogonal poor operation. In Operation Key is understood as the name of the collection. For example, in a microblog application, you can have a collection of all the followers of a user, and a collection of all their fans. Because Redis is very user-friendly for a few to provide the intersection, set, difference sets and other operations, then it can be very convenient to achieve such as common concern, common preferences, two-degree friends and other functions, to all of the above collection operations, you can also use different commands to choose whether to return the results to the client or save set into a new collection. QQ has a social function called "friend Tag", then you can use the collection of Redis to implement, each user's tags are stored in a collection.

127.0.0.1:6379> sadd Set1 ZBC
(integer) 1
127.0.0.1:6379> sadd Set1 szk
(integer) 1
127.0.0.1:6379> smembers Set1
1) "ZBC"

Sorted Set is an ordered set, it is more than set a weight parameter score, so that the elements in the set can be ordered by score, such as a storage of the class of students sorted sets, its collection value can be the student's school number , and score can be the test score, so that when the data is inserted into the collection, it has been sorted in a natural way.

127.0.0.1:6379> zadd mset2 2 "CDE 123"
(integer) 1
127.0.0.1:6379> zadd Mset2 4 "a123a"
(integer) 1
127.0.0.1:6379> zadd Mset2 "123-AAA"
(integer) 1
127.0.0.1:6379> zrange Mset2 0-1
1) "CDE 123"
2) "a123a"
3) "123-AAA"

Hash: In memcached, some structured information is often packaged into HashMap, which is stored as a string value (usually in JSON format) after the client is serialized, such as the user's nickname, age, gender, and integral.

v. Redis Persistence

  • Redis provides two methods of persistence, namely, RDB (Redis DataBase) and aof (Append only FIle)

  • An RDB, in short, generates snapshots of Redis-stored data at different points in time and stores it on media such as disks.

  • AOF, it is a change of an angle to achieve persistence, that is, Redis executed all the written instructions recorded down, at the next Redis restart, as long as these write instructions from the front to the back of the execution once, you can achieve data recovery.

  • In fact, the RDB and aof two ways can also be used simultaneously, in this case, if the Redis restart, it will take precedence in the AOF way for data recovery, because the AOF mode of data recovery is more complete.

  • If you don't have the need for data persistence, you can also turn off the RDB and aof mode, so Redis will become a pure memory database, just like memcached.


Redis data types

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.