admin 管理员组

文章数量: 1086019


2024年1月17日发(作者:disty什么意思)

jediscluster集群配置文件写法

JedisCluster是Redis官方提供的Java客户端,用于连接Redis集群。JedisCluster的配置文件可以使用properties或者yaml格式,以下是两种格式的示例:

1. properties格式

```

# Redis集群节点列表

=192.168.1.1:6379,192.168.1.2:6379,192.168.1.3:6379,192.168.1.4:6379,192.168.1.5:6379,192.168.1.6:6379

# 连接池最大连接数

al=100

# 连接池最大空闲连接数

e=50

# 连接池最小空闲连接数

e=10

# 连接超时时间

t=5000

# Redis密码

rd=123456

```

2. yaml格式

```

redis:

cluster:

nodes:

192.168.1.1:6379,192.168.1.2:6379,192.168.1.3:6379,192.168.1.4:6379,192.168.1.5:6379,192.168.1.6:6379

pool:

maxTotal: 100

maxIdle: 50

minIdle: 10

timeout: 5000

password: 123456

```

以上两种格式的配置文件都可以通过JedisCluster的构造方法进行加载:

```

JedisPoolConfig poolConfig = new JedisPoolConfig();

Total(nt(perty("al")));

Idle(nt(perty("e")));

Idle(nt(perty("e")));

String[] nodes =

perty("").split(",");

Set jedisClusterNodes = new HashSet<>();

for (String node : nodes) {

String[] parts = (":");

(new

nt(parts[1])));

}

HostAndPort(parts[0],

JedisCluster jedisCluster = new

JedisCluster(jedisClusterNodes,

nt(perty("t")),

nt(perty("t")),

3, perty("rd"), poolConfig);

```


本文标签: 集群 配置文件 客户端