mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-26 13:23:19 +01:00
Use a custom redis pubsub implementation rather than Jedis.
// FREEBIE
This commit is contained in:
@@ -16,8 +16,14 @@
|
||||
*/
|
||||
package org.whispersystems.textsecuregcm.providers;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.whispersystems.dispatch.io.RedisPubSubConnectionFactory;
|
||||
import org.whispersystems.dispatch.redis.PubSubConnection;
|
||||
import org.whispersystems.textsecuregcm.util.Util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
@@ -25,29 +31,40 @@ import redis.clients.jedis.JedisPool;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
import redis.clients.jedis.Protocol;
|
||||
|
||||
public class RedisClientFactory {
|
||||
public class RedisClientFactory implements RedisPubSubConnectionFactory {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(RedisClientFactory.class);
|
||||
|
||||
private final String host;
|
||||
private final int port;
|
||||
private final JedisPool jedisPool;
|
||||
|
||||
public RedisClientFactory(String url) throws URISyntaxException {
|
||||
JedisPoolConfig poolConfig = new JedisPoolConfig();
|
||||
poolConfig.setTestOnBorrow(true);
|
||||
|
||||
URI redisURI = new URI(url);
|
||||
String redisHost = redisURI.getHost();
|
||||
int redisPort = redisURI.getPort();
|
||||
String redisPassword = null;
|
||||
URI redisURI = new URI(url);
|
||||
|
||||
if (!Util.isEmpty(redisURI.getUserInfo())) {
|
||||
redisPassword = redisURI.getUserInfo().split(":",2)[1];
|
||||
}
|
||||
|
||||
this.jedisPool = new JedisPool(poolConfig, redisHost, redisPort,
|
||||
Protocol.DEFAULT_TIMEOUT, redisPassword);
|
||||
this.host = redisURI.getHost();
|
||||
this.port = redisURI.getPort();
|
||||
this.jedisPool = new JedisPool(poolConfig, host, port,
|
||||
Protocol.DEFAULT_TIMEOUT, null);
|
||||
}
|
||||
|
||||
public JedisPool getRedisClientPool() {
|
||||
return jedisPool;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PubSubConnection connect() {
|
||||
while (true) {
|
||||
try {
|
||||
Socket socket = new Socket(host, port);
|
||||
return new PubSubConnection(socket);
|
||||
} catch (IOException e) {
|
||||
logger.warn("Error connecting", e);
|
||||
Util.sleep(200);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user