Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration of Lettuce with Spring data redis and master slave strategy [DATAREDIS-752] #1333

Closed
spring-projects-issues opened this issue Jan 9, 2018 · 3 comments
Assignees
Labels
status: duplicate A duplicate of another issue type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link

spring-projects-issues commented Jan 9, 2018

HIMANSHU KANSAL opened DATAREDIS-752 and commented

I am trying to use lettuce with spring data redis and elasticCache with slave read strategy.

I have an elasticache redis with 1 master and 4 slaves. I want to read from slaves instead of master node. I am trying to use lettuce with spring data redis. Following is my code:

@bean
RedisConnectionFactory redicConnectionFactory() {
LettuceConnectionFactory factory = new LettuceConnectionFactory("localhost", 6379);
factory.afterPropertiesSet();
return factory;
}

@Bean
RedisTemplate<Object, Object> redisTemplate() {
    RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<>();
    redisTemplate.setKeySerializer(new GenericToStringSerializer<>(Object.class));
    redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
    redisTemplate.setConnectionFactory(redicConnectionFactory());
    redisTemplate.afterPropertiesSet();
    return redisTemplate;
}

private Map<String, Long> getExpiryTime() {
    Map<String, Long> cacheExpiryTime = new HashMap<>();
    //Set the ttl in seconds
    cacheExpiryTime.put(CACHE_NAME_RELEASE, 1 * 60 * 60L);
    return cacheExpiryTime;
}

@Bean
public CacheManager cacheManager() {
    RedisCacheManager cacheManager = new RedisCacheManager(redisTemplate());
    cacheManager.setExpires(getExpiryTime());
    //Will create the key in format "cachename ~ keyname"
    cacheManager.setUsePrefix(true);
    cacheManager.afterPropertiesSet();
    return new CustomTransactionAwareCacheProxy(cacheManager);
}

I want to know how can I pass the urls of my master and all slave nodes to LettuceConnectionFactory and set the ReadFrom strategy so that my read queries are redirected to slaves instead of master.

Lettuce:

<dependency>
            <groupId>biz.paluch.redis</groupId>
            <artifactId>lettuce</artifactId>
            <version>4.4.2.Final</version>
</dependency>
Spring-data-redis: 
<dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-redis</artifactId>
            <version>1.8.9.RELEASE</version>
</dependency>

Issue Links:

@spring-projects-issues
Copy link
Author

spring-projects-issues commented Jan 9, 2018

Mark Paluch commented

This is not a forum for general programming questions, please use StackOverflow. Master/Slave is not supported by Spring Data Redis 1.x, it was implemented with DATAREDIS-580 for Spring Data Redis 2.1

@spring-projects-issues
Copy link
Author

spring-projects-issues commented Jan 9, 2018

HIMANSHU KANSAL commented

Could you tell me when is Spring data redis 2.1 is going to be released.

Thanks

@spring-projects-issues
Copy link
Author

spring-projects-issues commented Jan 9, 2018

Mark Paluch commented

We plan to do a release in April. Check out our wiki to stay updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants