Installing Redis
Begin by installing Redis on your system.
Installling Ruby
Install Ruby to utilize the required tools for cluster management.
Configuring RubyGems Sources
Remove the default RubyGems source:
gem sources --remove https://rubygems.org/
Attempt to add the new source:
gem sources --add https://gems.ruby-china.org/
Encounter an SSL certificate verification error:
ERROR: SSL verification error at depth 1: unable to get local issuer certificate (20)
ERROR: You must add /O=Digital Signature Trust Co./CN=DST Root CA X3 to your local trusted store
Error fetching https://gems.ruby-china.org/:
SSL_connect returned=1 errno=0 state=error: certificate verify failed (https://gems.ruby-china.org/specs.4.8.gz)
Resolve the SSL error by setting the SSL_CERT_FILE environment variable to point too the certificate bundle:
set SSL_CERT_FILE=D:\software\ruby\cacert.pem
Attempting to add the source again results in a version error:
gem sources --add https://gems.ruby-china.org/
Error fetching https://gems.ruby-china.org/:
bad response Not Found 404 (https://gems.ruby-china.org/specs.4.8.gz)
Update the source URL to the current domain:
gem sources --add https://gems.ruby-china.com/
Creating the Redis Cluster
Use the redis-trib.rb script to create a Redis cluster with six nodes and replication:
ruby redis-trib.rb create --replicas 1 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384 127.0.0.1:6385
The script allocates hash slots and configures master-replica relationships. Confirm the configuration by typing yes.
Note: Starting with Redis 5.0, redis-trib.rb is deprecated. Use redis-cli --cluster instead:
redis-cli --cluster create --cluster-replicas 1 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384 127.0.0.1:6385
Interacting with the Cluster
Connect to the cluster using redis-cli in cluster mode:
redis-cli -h 127.0.0.1 -p 6380 -c
Set and retrieve keys:
127.0.0.1:6380> SET greeting "Hello, World!"
OK
127.0.0.1:6380> GET greeting
"Hello, World!"
127.0.0.1:6380> SET item "Sample data"
-> Redirected to slot [12539] located at 127.0.0.1:6381
OK
Key operations may redirect to the appropriate node based on hash slot distribution.