With the rapid development of the Internet, the traditional relational database (such as mysql, Microsoft SQL server, etc.) can not meet the growing business needs, such as commodity second kill, rush purchase and other very timely functions. With the application of high concurrent access, the system database will collapse. In order to solve this situation, we need to reference a cache middleware, Redis and memcached are commonly used cache Middleware in the market. They have their own advantages and disadvantages, but most Internet companies use MySQL + redis architecture. This paper mainly introduces the concept and installation configuration of redis.
Redis (remote dictionary server) is an open source non relational database, which is written in ANSI C language, complies with BSD protocol, supports network, can be based on memory, can also be persistent, and provides multi language API.
Traditional databases follow acid rules. NoSQL (short for not only SQL, which is a general term for database management system different from traditional relational database) is generally distributed, and distributed generally follows cap theorem.
Similar to memcached, it supports more value types, including string, list, set, Zset and hash. These data types all support push / pop, add / remove, intersection Union, difference and richer operations, and these operations are atomic. On this basis, redis supports various sorting methods. Like memcached, data is cached in memory to ensure efficiency. The difference is that redis will periodically write the updated data to disk or the modification operation to the additional record file, and on this basis, it realizes the master-slave synchronization. Redis introduces the cluster mode in version 3.0.
GitHub source code:https://github.com/antirez/redis
Features and advantages
- k. V key value storage and data structure storage (such as list, dictionary)
- All data (including data storage) operations are completed in memory
- Single threaded service (which means there will be more blocking), using epoll model for request response, compared with nginx
- Support master-slave replication mode, and provide high availability master-slave replication mode (sentry)
- Decentralized distributed cluster
- Rich programming interface support, such as python, golang, Java, PHP, ruby, Lua, node.js
- In addition to supporting a variety of data structures, it also supports transaction, publish / subscribe, message queue and other functions
- Supporting data persistence (AOF, RDB)
- Memcache is a distributed memory object caching system, which does not provide persistent storage function, while redis has persistent storage function
- Memcache data storage is based on LRU (in short, the most recent and least used key will be eliminated), while redis can be saved permanently (when the service is running all the time)
- Memcache is multi-threaded (which is one of the advantages of Memcache), which means less blocking, while redis is single threaded, which means more blocking
- There is little difference in performance between the two
- Memcache only supports simple K and V data storage, while redis supports multiple data formats.
- Memcache is a multi thread, non blocking IO multiplexing network model, while redis is a single thread IO multiplexing model
Install Windows version
Download the Windows version of redis at:https://github.com/microsoftarchive/redis/releases。
Download the version you need, as shown in the following figure (MSI is the installation version, zip is the decompression version)
Download the zip to the local decompression (the decompression directory of the author is D: / / program files / redis), and the directory is as follows:
Start the service, run the CMD, switch to the decompression directory, and execute the following command (and set the maximum memory)
redis-server.exe redis.windows.conf --maxmemory 200M
The effect is shown in the figure
Open the command line client and execute the following command:
To add and query key value, execute the following command:
#Set key value set key value #Get key value get key
To query and set the password, execute the following command:
#Query password config get requirepass #Set password Config set requirepass password
Enter the password and execute the following command:
The above commands are shown in the figure below.
To register and uninstall the service, execute the following command:
#Sign up for installation services redis-server --service-install redis.windows.conf --loglevel verbose #Uninstall service #redis-server --service-uninstall
The implementation effect is as follows:
After registration, you can see the service in the computer service, as shown in the figure below.
After the service is started, you can connect directly with the command line client.
This article briefly introduces the background and concept of redis and the installation and testing of Windows version. In the follow-up blog, I will continue to explain the relevant content of redis. If this article is helpful to you, it is my motivation to write!Interested friends can add attention, welcome message exchange!