2022-10-29 20:02:09 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013-present RedisBungee contributors
|
|
|
|
*
|
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
* are made available under the terms of the Eclipse Public License v1.0
|
|
|
|
* which accompanies this distribution, and is available at
|
|
|
|
*
|
|
|
|
* http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
*/
|
|
|
|
|
2022-07-16 12:50:09 +00:00
|
|
|
package com.imaginarycode.minecraft.redisbungee.api.summoners;
|
2022-07-16 05:18:33 +00:00
|
|
|
|
|
|
|
import redis.clients.jedis.JedisCluster;
|
2022-10-25 11:52:50 +00:00
|
|
|
import redis.clients.jedis.providers.ClusterConnectionProvider;
|
2022-07-16 05:18:33 +00:00
|
|
|
|
|
|
|
import java.io.IOException;
|
2022-10-25 11:52:50 +00:00
|
|
|
import java.time.Duration;
|
2022-07-16 05:18:33 +00:00
|
|
|
|
2022-07-25 15:13:25 +00:00
|
|
|
public class JedisClusterSummoner implements Summoner<JedisCluster> {
|
2022-10-25 11:52:50 +00:00
|
|
|
public final ClusterConnectionProvider clusterConnectionProvider;
|
2022-07-16 05:18:33 +00:00
|
|
|
|
2022-10-25 11:52:50 +00:00
|
|
|
public JedisClusterSummoner(ClusterConnectionProvider clusterConnectionProvider) {
|
|
|
|
this.clusterConnectionProvider = clusterConnectionProvider;
|
2022-07-17 01:40:32 +00:00
|
|
|
// test the connection
|
2022-10-25 11:52:50 +00:00
|
|
|
JedisCluster jedisCluster = obtainResource();
|
2022-07-17 01:40:32 +00:00
|
|
|
jedisCluster.set("random_data", "0");
|
|
|
|
jedisCluster.del("random_data");
|
2022-07-16 05:18:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-07-26 13:47:18 +00:00
|
|
|
public void close() throws IOException {
|
2022-10-25 11:52:50 +00:00
|
|
|
this.clusterConnectionProvider.close();
|
2022-07-16 05:18:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-07-26 13:47:18 +00:00
|
|
|
public JedisCluster obtainResource() {
|
2022-10-25 11:52:50 +00:00
|
|
|
return new NotClosableJedisCluster(this.clusterConnectionProvider, 60, Duration.ofSeconds(30000));
|
2022-07-16 05:18:33 +00:00
|
|
|
}
|
|
|
|
}
|