我从 docker 设置了一个 Redis 主/从/哨兵,这是我的 docker-compose.yml
redis-master:
image: redis:3
ports:
- 6380:6379
redis-slave:
image: redis:3
ports:
- 6381:6379
command: redis-server --slaveof redis-master 6379
deploy:
replicas: 2
redis-sentinel:
image: mengli/redis-sentinel
ports:
- 26379:26379
deploy:
replicas: 3
environment:
- MASTER_HOST=redis-mater
- SENTINEL_PORT=26379
- SENTINEL_QUORUM=2
Run Code Online (Sandbox Code Playgroud)
我想用docker连接Redis,我用的是spring-data-redis,这是我的配置:
redis:
sentinel:
master: mymaster
nodes: 127.0.0.1:26379
Run Code Online (Sandbox Code Playgroud)
但是在连接Redis时,发现ip地址为10.0.0.*,是docker中的ip地址,所以抛出了连接异常。
Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
Run Code Online (Sandbox Code Playgroud)
请告诉我如何将 Redis 与 docker 中的哨兵连接起来。谢谢
我使用factory通过命令对象创建实体,但是当我想从命令对象更新实体时,我找不到合适的样式来执行此操作。我应该只使用工厂来更新实体,否则,什么是好的模式?
interface ProductFactory {
Product create(ProductCommand command);
Product update(Product product, ProductCommand command);
}
Run Code Online (Sandbox Code Playgroud)
我的服务?
class ProductServiceImpl {
public Product updateProduct(long productId, ProductCommand command) {
Product product = productRepository.findOne(productId);
product = productFactory.update(product, productCommand);
return productRepository.save(product);
}
}
Run Code Online (Sandbox Code Playgroud)