Redis Cluster:
If deployed to multiple computers, it will be the same as a normal cluster; because Redis is single-threaded and multi-core The CPU can only use one core, so if it is deployed on the same computer and runs multiple Redis instances to form a cluster, the CPU utilization can be improved.
Recommended:
redis video tutorialBuild a Redis cluster under Windows system:Requires 4 components:
Redis, Ruby language operating environment, Redis Ruby driver redis-xxxx.gem, tool for creating Redis cluster redis-trib.rb
Install Redis and run 3 instances (Redis cluster requires at least More than 3 nodes, less than 3 cannot be created);
Use the redis-trib.rb tool to create a Redis cluster. Since this file is written in ruby language, you need to install the Ruby development environment and driver. redis-xxxx.gem
1. Download and install Redis
The GitHub path is as follows: https://github.com/MSOpenTech/redis/releases/
Redis provides Download files in msi and zip formats. Download zip format version 3.0.504 here.
Just decompress the downloaded Redis-x64-3.0.504.zip. For ease of use, it is recommended to place it in the root directory of the drive letter. Next, and change the directory name to Redis, such as: C:\Redis or D:\Redis
Start 3 different Redis instances through the configuration file. Since the default port of Redis is 6379, 6380 is used here. , 6381, and 6382 to run 3 Redis instances.
Note: In order to avoid unnecessary errors, try to save the configuration file in utf8 format and do not contain comments;
There are two ways to save logs in the configuration file (save in file, Save to System Log) Please choose one of them according to your needs:
loglevel notice #The recording level of the log, notice is suitable for the production environmentlogfile "D:/ Redis/Logs/redis6380_log.txt" #Specify the path to keep the log. The default is to create it in the Redis installation directory. If there are subdirectories, you need to create them manually, such as the Logs directory here
syslog-enabled yes #Whether to use System log
syslog-ident redis6380 #In the identification name of the system log
, the method of saving in a file is used, so first create a new Logs under the Redis directory D:/Redis The contents of the folder
redis.6380.conf are as follows:
port 6380 loglevel notice logfile "D:/Redis/Logs/redis6380_log.txt" appendonly yes appendfilename "appendonly.6380.aof" cluster-enabled yes cluster-config-file nodes.6380.conf cluster-node-timeout 15000 cluster-slave-validity-factor 10 cluster-migration-barrier 1 cluster-require-full-coverage yes
The contents of redis.6381.conf are as follows:
port 6381 loglevel notice logfile "D:/Redis/Logs/redis6381_log.txt" appendonly yes appendfilename "appendonly.6381.aof" cluster-enabled yes cluster-config-file nodes.6381.conf cluster-node-timeout 15000 cluster-slave-validity-factor 10 cluster-migration-barrier 1 cluster-require-full-coverage yes
redis.6382.conf The contents are as follows:
port 6382 loglevel notice logfile "D:/Redis/Logs/redis6382_log.txt" appendonly yes appendfilename "appendonly.6382.aof" cluster-enabled yes cluster-config-file nodes.6382.conf cluster-node-timeout 15000 cluster-slave-validity-factor 10 cluster-migration-barrier 1 cluster-require-full-coverage yes
The configuration content is explained as follows:
port 6380 #端口号 loglevel notice #日志的记录级别,notice是适合生产环境的 logfile "Logs/redis6380_log.txt" #指定log的保持路径,默认是创建在Redis安装目录下,如果有子目录需要手动创建,如此处的Logs目录 syslog-enabled yes #是否使用系统日志 syslog-ident redis6380 #在系统日志的标识名 appendonly yes #数据的保存为aof格式 appendfilename "appendonly.6380.aof" #数据保存文件 cluster-enabled yes #是否开启集群 cluster-config-file nodes.6380.conf cluster-node-timeout 15000 cluster-slave-validity-factor 10 cluster-migration-barrier 1 cluster-require-full-coverage yes
Save the above configuration files to the Redis directory, and use these configuration files to install 3 redis services. The command is as follows:
Note : It is best to use the full path for configuration files such as redis.6380.conf to avoid problems when restarting the Redis cluster. The blogger’s installation directory is D:/Redis
D:/Redis/redis-server.exe --service-install D:/Redis/redis.6380.conf --service-name redis6380 D:/Redis/redis-server.exe --service-install D:/Redis/redis.6381.conf --service-name redis6381 D:/Redis/redis-server.exe --service-install D:/Redis/redis.6382.conf --service-name redis6382
To start these three services, the command is as follows:
D:/Redis/redis-server.exe --service-start --service-name Redis6380 D:/Redis/redis-server.exe --service-start --service-name Redis6381 D:/Redis/redis-server.exe --service-start --service-name Redis6382
Execution result:
##2. Download and install ruby
2.2. Download the Redis driver in ruby environment. Considering compatibility, the download here is version 3.2.2
The command is as follows:
gem install --local path_to_gem/filename.gem
Actual operation As follows:
2.3. Download the ruby script file redis-trib.rb officially provided by Redis to create a Redis cluster. The path is as follows:
注意:因为redis-trib.rb是ruby代码,必须用ruby来打开,若redis-trib.rb无法识别,需要手动选择该文件的打开方式:
**选择ruby为的打开方式后,redis-trib.rb的logo都会发生改变,如下图:
3.创建Redis集群
CMD下切换到Redis目录,使用redis-trib.rb来创建Redis集群:
redis-trib.rb create --replicas 0 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382
执行结果:
检验是否真的创建成功,输入以下命令:
redis-trib.rb check 127.0.0.1:6380
出现以下信息,说明创建的Redis集群是没问题的
使用Redis客户端Redis-cli.exe来查看数据记录数,以及集群相关信息
D:/Redis/redis-cli.exe -c -p 6380
-c 表示 cluster
-p 表示 port 端口号
输入dbsize查询 记录总数
dbsize
或者一次输入完整命令:
D:/Redis/redis-cli.exe -c -p 6380 dbsize
结果如下:
输入cluster info可以从客户端的查看集群的信息:
cluster info
结果如下:
更多redis知识请关注redis使用教程栏目。
The above is the detailed content of Example of building a redis cluster under Windows. For more information, please follow other related articles on the PHP Chinese website!

RedisisclassifiedasaNoSQLdatabasebecauseitusesakey-valuedatamodelinsteadofthetraditionalrelationaldatabasemodel.Itoffersspeedandflexibility,makingitidealforreal-timeapplicationsandcaching,butitmaynotbesuitableforscenariosrequiringstrictdataintegrityo

Redis improves application performance and scalability by caching data, implementing distributed locking and data persistence. 1) Cache data: Use Redis to cache frequently accessed data to improve data access speed. 2) Distributed lock: Use Redis to implement distributed locks to ensure the security of operation in a distributed environment. 3) Data persistence: Ensure data security through RDB and AOF mechanisms to prevent data loss.

Redis's data model and structure include five main types: 1. String: used to store text or binary data, and supports atomic operations. 2. List: Ordered elements collection, suitable for queues and stacks. 3. Set: Unordered unique elements set, supporting set operation. 4. Ordered Set (SortedSet): A unique set of elements with scores, suitable for rankings. 5. Hash table (Hash): a collection of key-value pairs, suitable for storing objects.

Redis's database methods include in-memory databases and key-value storage. 1) Redis stores data in memory, and reads and writes fast. 2) It uses key-value pairs to store data, supports complex data structures such as lists, collections, hash tables and ordered collections, suitable for caches and NoSQL databases.

Redis is a powerful database solution because it provides fast performance, rich data structures, high availability and scalability, persistence capabilities, and a wide range of ecosystem support. 1) Extremely fast performance: Redis's data is stored in memory and has extremely fast read and write speeds, suitable for high concurrency and low latency applications. 2) Rich data structure: supports multiple data types, such as lists, collections, etc., which are suitable for a variety of scenarios. 3) High availability and scalability: supports master-slave replication and cluster mode to achieve high availability and horizontal scalability. 4) Persistence and data security: Data persistence is achieved through RDB and AOF to ensure data integrity and reliability. 5) Wide ecosystem and community support: with a huge ecosystem and active community,

Key features of Redis include speed, flexibility and rich data structure support. 1) Speed: Redis is an in-memory database, and read and write operations are almost instantaneous, suitable for cache and session management. 2) Flexibility: Supports multiple data structures, such as strings, lists, collections, etc., which are suitable for complex data processing. 3) Data structure support: provides strings, lists, collections, hash tables, etc., which are suitable for different business needs.

The core function of Redis is a high-performance in-memory data storage and processing system. 1) High-speed data access: Redis stores data in memory and provides microsecond-level read and write speed. 2) Rich data structure: supports strings, lists, collections, etc., and adapts to a variety of application scenarios. 3) Persistence: Persist data to disk through RDB and AOF. 4) Publish subscription: Can be used in message queues or real-time communication systems.

Redis supports a variety of data structures, including: 1. String, suitable for storing single-value data; 2. List, suitable for queues and stacks; 3. Set, used for storing non-duplicate data; 4. Ordered Set, suitable for ranking lists and priority queues; 5. Hash table, suitable for storing object or structured data.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version
Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download
The most popular open source editor