In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the uses and advantages and disadvantages of Redis. It is very detailed and has a certain reference value. Friends who are interested must finish reading it.
1. The disadvantages of Memcached and Redis.
Storage architecture such as MySQL+Memcached is commonly used in the industry, but with the continuous growth of traffic, there are a lot of problems.
1. MySQL needs to disassemble the library and tables constantly, and Memcached also needs to expand its capacity.
2. There is some data inconsistency between Memcached and MySQL.
3. If the hit rate of Memcached becomes low easily and penetrates directly to MySQL, the database cannot be supported.
2. The characteristics of Redis
Speaking of Redis, many developers only know that it is a non-relational database like Memcached, which can store data in the form of Kmurv directly, but it is also different from Memcached.
1. Redis not only supports simple Kmurv data storage, but also supports list, set, hash, zset and other collection class data storage.
2. Redis supports real-time data backup, which can also restore the data when it is down in time.
3. Redis supports the persistence of data, and the data stored in memory memory can be saved directly on disk.
3. Data types commonly used in Redis
String 、 Hash 、 Set 、 List 、 SortedSet 、 pub/sub 、 Transactions .
1. String:Strings is a variable stored in the simplest form of Key-Value. Where Value can be either a number or a string. The implementation is that a string is stored by default in Redis and referenced by redisObject. When digital operations such as incr, decr and other commands are detected, they are automatically converted into numbers for calculation, and then stored in String after calculation.
2. Hash:Hash stores the value of key-value pairs. That is, Key-Hash, and Hash is a structure of KMurv. If you use Memcached, you need to package and store the entire Hash in memory. If you need to query one of the values, you have to take out the whole Hash and find the corresponding value. Redis can get Value directly through commands, which greatly improves the performance. Its implementation principle: when there are few members, Redis will use compact storage similar to an one-dimensional array in order to save memory, and when there are more objects, it will be directly converted to HashMap storage.
3. Set:Set is a disordered set of natural deweighting, namely Key-Set. In addition, it also provides a series of methods to directly manipulate the set, such as intersection, union and so on, which is especially convenient for finding common friends and what to pay attention to. The underlying layer is implemented by HashMap, where value is null
4. List:List is an ordered and repeatable set, which follows the principle of FIFO, and the bottom layer relies on a two-way linked list, so it supports forward and reverse double lookups. Through List, we can get functions similar to the latest reply in a lot of ways.
5. SortedSet: similar to TreeSet in java, it is a sortable version of Set. In addition, priority sorting is supported, and a parameter of score is maintained to implement it. The underlying layer mainly relies on HashMap, which sorts by maintaining the mapping between the inserted values and the Score priority.
6. Pub/sub: publish and subscribe, similar to message queuing mq. You can choose to subscribe to a Key, and once the key publishes some messages, all objects that subscribe to the Key can receive the message. It can be mainly used in real-time messaging systems, such as chat and so on.
7. Transactions:NoSQL does not support transactions, but by providing the function of packaging execution, that is, all commands in the package must be executed together, in addition, you can lock a Key, and if a change in the Key is detected during the package execution, it will be rolled back directly.
4. Common application scenarios of Redis
Redis uses memory to provide storage and persists data through persistence. And it is a single-thread operation for request. This series of features make redis have a very magical function.
1. Find the latest reply.
If you are in a traditional relational database, you need to use select * from table where name= "" order by time desc limit 100; this consumes database performance, but with Redis, you can create a List directly in Redis through Id, specify a length of 1w, and directly output the last 100 records of the list when you need to find it.
2. Ranking problem
Common ranking problems, such as the hottest topics, game rankings, etc., can be easily achieved through Redis and can be obtained directly using ZRank.
3. Delete expired data
Redis is not a persistent database in the real sense. It can add a valid time to the data. When the valid time expires, Redis will automatically delete the corresponding data.
The above are all the uses, advantages and disadvantages of Redis. Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.