“This is the ninth day of my participation in the First Challenge 2022. For details: First Challenge 2022”

👨🎓 Author: Bug Bacteria

✏️ blog: CSDN, Nuggets, etc

💌 public account: Magic House of the Circle of the Apes

🚫 special statement: original is not easy, reprint please attach the original source link and this article statement, thank you for your cooperation.

🙏 Copyright notice: part of the text or pictures in the article may come from the Internet or Baidu Encyclopedia, if there is infringement, please contact bug bacteria processing.

Hi, family, I’m bug 🐛, here I go again. Today we are going to talk about something, OK, and we will continue the Series of articles on SpringBoot. Hope to help more beginners quickly start!

In the process of reviewing articles, if you think the articles are helpful to you at all, please don’t be too mean with your likes and bravely light up the articles 👍. Your likes (collect ⭐️+ pay attention to 👨 port + message board) are the best encouragement and support for bugs on my creation path. Time does not abandon 🏃🏻♀️, creation stopped 💕, refueling 🏻

One, foreword

Compared with relational database, non-relational database also has its advantages. Today we will take a look at non-relational databases Redis🐳.

I don’t know how many friends are still ignorant of Redis, if so, then you have come to the right place, today bug bacteria will teach you hand in hand, how to integrate Redis in the project and practice and analysis of redis in daily use need to pay attention to those problems.

So, next, let’s first understand some concepts related to Redis. Sharpening the knife does not mistake firewood workers ~

2. First acquaintance with Redis

1. What is Redis?

Redis is a non-relational in-memory database widely used in Nosql database. Like MongeDB, these are non-relational databases. We are familiar with MySQL, Oracle, SQL Server is a relational database!

Inside Redis is a key-value storage system. It supports more value types, including String, list, set, zset, sorted set, hash, and so on.

Redis is a NoSQL database that runs based on memory and supports persistence. Redis is one of the most popular NoSQL databases and is also known as data structure server.

2. What are the advantages of redis?

  • Fast, because the data is in memory, similar to a HashMap, which has the advantage of O(1) time complexity for both lookup and operation.
  • Supports rich data types, such as String, list, set, sorted set, hash, etc.
  • Transactions are supported and operations are atomic. Atomicity is when changes to data are either all or none.
  • Rich features: can be used for cache, message, by key set expiration time, will be automatically deleted after expiration, etc.

3. Why redis cache?

As the growth of the business and the improvement of the product, such as rapid growth in the data to the mysql | Oracle relational database brings pressure overload, as our requirements for product performance, the traditional way of data query has far can’t satisfy. Therefore, we need to find another mode to improve the efficiency of data query.

NoSQL in-memory databases (such as Redis) feature data in memory, data processing speed compared to disk increased by several orders of magnitude (Redis read speed is 110000 times /s, write speed is 81000 times /s).

Therefore, by transferring frequently accessed data to the memory database, not only can alleviate the mysql | Oracle relational database access such as pressure, but also greatly improve the speed of data access, improve the user experience, improve system performance, etc.

4. Common problems with Redis

  • Cache and database double-write consistency problems
  • Cache avalanche problem
  • Cache breakdown problem
  • Concurrency contention issues for caches
  • . .

5. How is Redis different from mysql?

  • The type of

A: In terms of types, mysql is a relational database and Redis is a cache database.

  • On the role

A: mysql is used to store persistent data to hard disk, which is powerful but slow, while Redis is used to store frequently used data to cache, which is fast to read.

  • On the demand

A: mysql and Redis are generally used together because of their different requirements.

6. What common scenarios does Redis have?

  1. Session cache
  2. Full page caching
  3. The queue
  4. Leaderboards/counters
  5. .

Finally, we will add some questions in the development of the interview often test redis, after all, redis is also a high frequency test point! Pay more attention to this. As for the answers to the interview questions, I will sort them out later. Can you preview and see how many answers you can get? If all answers are correct, then I think you redis can not prepare, directly proceed to the next point of review.

7. Redis often asks interview questions

  1. What data types do Redis support?
  2. What is Redis persistence? What persistence methods does Redis have? What are the pros and cons?
  3. What are the architectural patterns of Redis? Talk about their characteristics
  4. Have you ever used Redis distributed locks? How does it work?
  5. Have you used Redis for asynchronous queues and how? What are the disadvantages?
  6. What is cache penetration? How to avoid it? What is cache avalanche? How to avoid it?
  7. Redis common command?
  8. Why can Redis single thread support high concurrency?
  9. What about Redis’s memory flushing strategy?
  10. How to solve Redis concurrency competition problem?

. .

Windows10 how to build Redis?

Most of the above is to explain some concepts and knowledge points related to Redis. Surely after reading, those who have not touched Redis will have some initial impression on it.

Now we’re going to build it. Because the office machine is not convenient to build centos | Ubuntu, so I just build one on Windows. If you have the resources to build one on your private server is the best.

1. Download Redis

A. Download a Win installation package from the official website of Redis. Redis supports 32 and 64 bits. This will depend on your system version, here we download redis-x64-3.2.100. zip.

Download: github.com/MSOpenTech/…

2. Decompress and install Redis

B. Decompress the download and rename the folder to Redis.

3. Start the Redis service

C, open a CMD window, use the CD command to switch to your redis directory, the following is my redis directory.

C:\Users\Administrator\Desktop\redis
Copy the code

Or just enter CMD in the Redis folder and press Enter.

Run the following command:

redis-server.exe redis.windows.conf
Copy the code

The actual screenshot of the command is as follows:

As above redis service up! The port number is 6379.

4. Start the Redis client

D. Next, we will start the Redis client again for redis service connection.

Remember that! Another CMD small black window.

This time the small black window can not be closed, once closed, your Redis service will stop, then you can not use the client for Redis operations, so after the Redis related operations, the above window must be open!!

See my specific, as follows:

E. Enter the following command in the second window (client) to connect redis service.

redis-cli.exe
Copy the code

If the preceding information is displayed, the client is started and the service connection is successful.

Four, redis command combat

Next, we can do this with the redis command.

Ok! Let’s just do a quick test run of reading and writing data.

1. Insert the key

Set key1 value1 // Set key set year 2022Copy the code

Select * from key; select * from key; select * from key;

2. Obtain the key value

Enter the following command to obtain the value of year.

Syntax: get key1 // Get key

get year
Copy the code

Ok! It also correctly returns the value that was inserted.

5. Homework

The rest is up to you to practice, I will not give you a demonstration oh. Grammar is a lot of gameplay, I hope we can practice those commonly used commands on the line, the rest of the actual encounter to baidu.

Below I give you a simple list of a few commonly used, this you play to see!

  • How do I delete a key?

    DEL key

  • How do I determine whether a key exists?

    EXISTS key

  • How do I set the key expiration time?

    EXPIRE key seconds

  • How do I delete the key expiration time?

    PERSIST key

  • How do I get all the keys?

    keys *

.

OK, that’s all for this episode. If you have any questions, feel free to comment in the comments section. See you next time.

Six, the past popular recommendation

  • Springboot series (14) : Redis Zero-based teaching – environment preparation
  • Springboot series (fourteen) : Redis zero basic teaching (to achieve mobile phone number verification code function)- actual combat
  • Springboot series (14) : Redis zero-based teaching (with complete source code)- the end
  • How to integrate Swagger online Interface documents
  • Springboot series (12) : how to code to send email reminders
  • . .

If you want to learn more, you can pay attention to the bug bug column “SpringBoot Zero-based Introduction”, from scratch, from zero to one! Hope I can help you.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

☘️ Be who you want to be, there is no time limit, you can start whenever you want,

🍀 You can change from now on, you can also stay the same, this thing, there are no rules to speak of, you can live the most wonderful yourself.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

💓 If this article is helpful to you, please leave a like! (# ^. ^ #);

💝 if you like the article shared by bug fungus, please give bug fungus a point of concern! (๑ ‘ᴗ ‵ ๑);

💗 if you have any questions about the article, please also leave a message at the end of the article or add a group [QQ communication group :708072830];

💞 In view of the limited personal experience, all views and technical research points, if you have any objection, please directly reply to participate in the discussion (do not post offensive comments, thank you);

💕 copyright notice: original is not easy, reprint please attach the original source link and this article statement, all rights reserved, piracy will investigate!! thank you