无非就是提高性能
就以三台为 不用主从结构
同样的redis复制三份
里面的redis.conf
我这个redis.conf是复制redis.window.conf的
里面的配置 除了改端口外 就下面复制复制 就成
cluster-enabled yes
cluster-config-file nodes-6379.conf
cluster-node-timeout 5000
appendonly yes
然后挨个启动 发现直接点redis-server.exe 配置文件并不生效 提示什么用默认的 所以 记得 拖动redis.conf 到redis-server.exe打开 另外 可以在cmd窗口 ./redis-cli -h 127.0.0.1 -p 6380 来链接不同主机不同端口
ok然后开始下载 rubby
下载地址
http://dl.bintray.com/oneclick/rubyinstaller/rubyinstaller-2.2.4-x64.exe
下载驱动
https://rubygems.org/gems/redis/versions/3.2.2
就是一个gem文件
到这个放的目录
gem install --local .\redis-3.2.2.gem
安装这个驱动
然后下载
https://raw.githubusercontent.com/MSOpenTech/redis/3.0/src/redis-trib.rb
这个脚本文件
但是这个网站一直链接不上 于是就在github搜索一下这个脚本文件
下载好 后同样是到这个文件这里
cmd
redis-trib.rb create --replicas 0 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6379
会提示输入yes啥的 输入yes 有提示 slot 0 is already busy
这说明 redis有数据 到命令行窗口 挨个清空
先flushall 在cluster reset
然后在重复上面的
最后可以 ./redis-trib.rb check 127.0.0.1:6380 检查下嗯 就完了
在spring boot项目
根本就不需要什么多余的配置
只需要 一句
spring.redis.cluster.nodes=127.0.0.1:6380,127.0.0.1:6381,127.0.0.1:6379
在测试类里
package com.example.demo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class YanjunGatewayApplicationTests {
@Autowired
private StringRedisTemplate redisTemplate;
@Test
public void contextLoads() {
for(int i=0; i<10;i++){
redisTemplate.opsForValue().set("a"+i,"哈哈哈"+i);
}
System.out.println("success");
}
@Test
public void contextLoads1() {
for(int i=0; i<10;i++){
String a =redisTemplate.opsForValue().get("a"+i);
System.out.println(a);
}
System.out.println("success");
}
}
就是这么简单