如何创建 Redisson 客户端以连接到 redis
How can I create Redisson Client to connect to a redis
我不确定如何在应用程序中创建 RedissonClient 对象。
1- 是否应该为每笔交易创建此对象或
2- 每个 JVM 对象应该是单例的吗?
3- 所有服务只有一个对象?
目前,我的设置是一个嵌入式 Jetty,带有用于 3 个服务的 Jersey APIs 运行 在不同的 Kubernetes pods 集上,Redis 设置是 3 + 3 master 和 slave 配置。
当前配置如下所示。
public class RedisTemplate {
public static final RedissonClient REDISCLIENT;
private static final Logger logger = LogManager.getLogger(RedisTemplate.class);
public static final String redisMaster = "redis-cluster";
static {
Config config = new Config();
logger.info("redis config for server");
config.useClusterServers().addNodeAddress("redis://" + redisMaster + ":6379");
REDISCLIENT = Redisson.create(config);
}
}
正如他们FAQ中所述,redisson应该是单例的:
Q: When do I need to shut down a Redisson instance, at the end of each request or the end of the life of a thread?
A : Redisson instance requires manual shutdown only if you want to stop using all of its features. It is a common pattern that Redisson starts and stops along with the application. Since it is completely thread safe, you may treat a Redisson instance as a singleton. The shutdown sequence will disconnect all the active connections held in each connection pool, and it will clean up certain types of Redisson objects require a manual destroy action upon disposal, it will then stop the event loops. Please be advised, the entire shutdown process is not instant.
我不确定如何在应用程序中创建 RedissonClient 对象。 1- 是否应该为每笔交易创建此对象或 2- 每个 JVM 对象应该是单例的吗? 3- 所有服务只有一个对象?
目前,我的设置是一个嵌入式 Jetty,带有用于 3 个服务的 Jersey APIs 运行 在不同的 Kubernetes pods 集上,Redis 设置是 3 + 3 master 和 slave 配置。
当前配置如下所示。
public class RedisTemplate {
public static final RedissonClient REDISCLIENT;
private static final Logger logger = LogManager.getLogger(RedisTemplate.class);
public static final String redisMaster = "redis-cluster";
static {
Config config = new Config();
logger.info("redis config for server");
config.useClusterServers().addNodeAddress("redis://" + redisMaster + ":6379");
REDISCLIENT = Redisson.create(config);
}
}
正如他们FAQ中所述,redisson应该是单例的:
Q: When do I need to shut down a Redisson instance, at the end of each request or the end of the life of a thread?
A : Redisson instance requires manual shutdown only if you want to stop using all of its features. It is a common pattern that Redisson starts and stops along with the application. Since it is completely thread safe, you may treat a Redisson instance as a singleton. The shutdown sequence will disconnect all the active connections held in each connection pool, and it will clean up certain types of Redisson objects require a manual destroy action upon disposal, it will then stop the event loops. Please be advised, the entire shutdown process is not instant.