Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install and deploy Redis

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

Editor to share with you how to install and deploy Redis, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

What is Redis

Redis:REmote DIctionary Server (remote Dictionary Server)

Redis is completely open source and free, written in C language, complies with the BSD protocol, and is a high-performance (key/value) distributed memory database. It is also a NoSQL database running on memory and supporting persistence. It is one of the most popular NoSql databases and is also known as a data structure server. At the same time, Redis is a simple, efficient, distributed, memory-based caching tool. After building up the server, provide Key-Value-style caching service through network connection (similar to database).

Redis has the following advantages:

1. Extremely high performance Redis reads at 110000 beats per second and writes at 80 thousand beats per second.

two。 The rich data types supported by Redis are String, Hash, List, Set, and Ordered Set database types.

3. Atomic Redis all operations are atomic and are wrapped by MULTI and EXEC instructions.

4. Rich read and write Redis supports publish/subscribe, notification, key expiration and other features.

5. High-speed read and write redis uses its own splitter, the amount of code is very short, does not use lock (MySQL), so the efficiency is very high.

Redis also has the following disadvantages:

1. Persistent Redis stores the data directly in memory. If you want to save the data to disk, the first method is to use ① scheduled snapshot (snapshot): write the entire database to disk at regular intervals, writing all the data each time, but the cost is very high. The second method is ②-based appending (aof): only the changed data is tracked, but the appended log may be too large and all operations are performed again, resulting in slow recovery.

two。 Consumes memory and occupies too much memory.

What can Redis do?

In enterprise development, Redis can be used as database, cache, hot data (data that is often queried but not modified or deleted), message middleware and so on.

Examples of common scenarios in Redis are as follows:

Caching

Nowadays, caching is a must-kill skill used by almost all medium and large websites. Reasonable use of caching can not only improve the access speed of the website, but also greatly reduce the pressure on the database. Redis provides the function of key expiration as well as flexible key elimination strategy.

Ranking

Such as Taobao monthly sales list, goods on the new list according to time, and so on. The ordered set data class construction provided by Redis can realize a variety of complex ranking applications.

Counter

Such as the number of views of goods on e-commerce websites, the number of videos played on video websites, and so on. In order to ensure the real-time efficiency of the data, you have to give + 1 to each browse, and it is undoubtedly a challenge and pressure to request the database operation every time when the concurrency is high. Redis provides incr commands to achieve counter function, memory operation, very good performance, very suitable for these counting scenarios.

Distributed session

In cluster mode, when there are few applications, it can be satisfied by using the session replication feature of the container. In systems with more and more complex applications, session services centered on Redis and other in-memory databases are generally built. Session is no longer managed by containers, but by session services and in-memory databases.

Distributed lock

The technical challenge brought by distributed technology is the concurrent access to the same resource, such as global ID, inventory reduction, seconds kill and so on. Pessimistic locks and optimistic locks of the database can be used in scenarios with small concurrency, but in the case of high concurrency, it is not ideal to use database locks to control the concurrent access of resources, which greatly affects the performance of the database. You can use the setnx function of Redis to write distributed locks. If the setting returns 1, it means that the lock was acquired successfully, otherwise the lock failed, and there are more details to be considered in the practical application.

Social Network

Like, step on, follow / be followed, mutual friends and so on are the basic functions of social networking sites. The visit volume of social networking sites is usually large, and the traditional relational database type is not suitable for storing this type of data. The data structures such as hash and collection provided by Redis can easily achieve these functions.

Latest list

Redis list structure, LPUSH can insert a content ID in the list header as a keyword, LTRIM can be used to limit the number of lists, so that the list is always N ID, no need to query the latest list, just go to the corresponding content page according to ID.

Message system

Message queuing is a necessary middleware for large websites, such as ActiveMQ, RabbitMQ, Kafka and other popular message queuing middleware, which is mainly used for business decoupling, traffic peaking and low real-time asynchronous processing. Redis provides publish / subscribe and blocking queue functions to implement a simple message queuing system. However, this cannot be compared with professional messaging middleware.

III. Download, install and deploy Redis

As the enterprise does Redis development, 99% of them are the application and installation of Linux version, so this article only introduces the installation and operation of Linux. Friends can install and use Baidu on their own under Windows. Go to the above website and click Download to download the .gz installation package and put it in the / opt directory under Linux (I installed version 6.0.5 of Redis here).

Decompress command: tar-zxvf redis-6.0.5.tar.gz

The above command only unzips Redis. If you want to install Redis, you need the Linux system to have a gcc environment. If not, you can install it using yum install gcc-c++, and then use gcc- v to view the version.

If the Linux environment already has a gcc environment, install it directly using the following command:

The installation command is make install

When installed, it cannot boot by default like Tomcat. You can change the daemonize attribute in the redis.conf file to yes.

Enable the redis service: redis-server / myredis/redis.conf (here is the redis configuration file with modified properties)

Check whether the backend Redis service is started:

Ps-ef | grep redis

Enable the Redis service:

Redis-cli-p 6379

Close normally and the data will be saved.

Use the shutdown command to close from the redis command line.

Abnormal shutdown can easily lead to data loss

Power off, manual kill down redis process, etc.

Several other redis commands

Fourth, a few little knowledge of Redis

Redis is a single process that uses a single process model to handle client requests. The response to events such as read and write is achieved by wrapping the epoll function. The actual processing speed of Redis depends entirely on the execution efficiency of the main process.

Epoll is an improved epoll made by the Linux kernel to deal with a large number of file descriptors. It is an enhanced version of the multiplexed IO interface select/poll under Linux. It can significantly improve the CPU utilization of the system when there is only a small amount of active programs in a large number of concurrent connections.

Redis has 16 databases by default, the subscript starts from zero, and the initial default uses the zero library. You can use the SELECT command to connect to the specified database.

The dbsize directive can view the number of key in the current database, and keys * can view all the key.

Flushdb: clear the current library (use with caution)

Flushall: clear all libraries (use with caution)

Unified password management, 16 libraries all have the same password, either OK or none of them can be connected.

Redis indexes all start from scratch.

The default port for Redis is 6379

These are all the contents of the article "how to install and deploy Redis". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more 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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report