Example of building a redis cluster under Windows
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!

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Redis cluster mode deploys Redis instances to multiple servers through sharding, improving scalability and availability. The construction steps are as follows: Create odd Redis instances with different ports; Create 3 sentinel instances, monitor Redis instances and failover; configure sentinel configuration files, add monitoring Redis instance information and failover settings; configure Redis instance configuration files, enable cluster mode and specify the cluster information file path; create nodes.conf file, containing information of each Redis instance; start the cluster, execute the create command to create a cluster and specify the number of replicas; log in to the cluster to execute the CLUSTER INFO command to verify the cluster status; make

How to clear Redis data: Use the FLUSHALL command to clear all key values. Use the FLUSHDB command to clear the key value of the currently selected database. Use SELECT to switch databases, and then use FLUSHDB to clear multiple databases. Use the DEL command to delete a specific key. Use the redis-cli tool to clear the data.

To read a queue from Redis, you need to get the queue name, read the elements using the LPOP command, and process the empty queue. The specific steps are as follows: Get the queue name: name it with the prefix of "queue:" such as "queue:my-queue". Use the LPOP command: Eject the element from the head of the queue and return its value, such as LPOP queue:my-queue. Processing empty queues: If the queue is empty, LPOP returns nil, and you can check whether the queue exists before reading the element.

To uninstall an Oracle database: stop the Oracle service, remove the Oracle instance, delete the Oracle home directory, clear the registry key (Windows only), and delete the environment variables (Windows only). Please back up the data before uninstalling.

Use the Redis command line tool (redis-cli) to manage and operate Redis through the following steps: Connect to the server, specify the address and port. Send commands to the server using the command name and parameters. Use the HELP command to view help information for a specific command. Use the QUIT command to exit the command line tool.

There are two types of Redis data expiration strategies: periodic deletion: periodic scan to delete the expired key, which can be set through expired-time-cap-remove-count and expired-time-cap-remove-delay parameters. Lazy Deletion: Check for deletion expired keys only when keys are read or written. They can be set through lazyfree-lazy-eviction, lazyfree-lazy-expire, lazyfree-lazy-user-del parameters.

To improve the performance of PostgreSQL database in Debian systems, it is necessary to comprehensively consider hardware, configuration, indexing, query and other aspects. The following strategies can effectively optimize database performance: 1. Hardware resource optimization memory expansion: Adequate memory is crucial to cache data and indexes. High-speed storage: Using SSD SSD drives can significantly improve I/O performance. Multi-core processor: Make full use of multi-core processors to implement parallel query processing. 2. Database parameter tuning shared_buffers: According to the system memory size setting, it is recommended to set it to 25%-40% of system memory. work_mem: Controls the memory of sorting and hashing operations, usually set to 64MB to 256M

Use of zset in Redis cluster: zset is an ordered collection that associates elements with scores. Sharding strategy: a. Hash sharding: Distribute the hash value according to the zset key. b. Range sharding: divide into ranges according to element scores, and assign each range to different nodes. Read and write operations: a. Read operations: If the zset key belongs to the shard of the current node, it will be processed locally; otherwise, it will be routed to the corresponding shard. b. Write operation: Always routed to shards holding the zset key.
