Redis connection is not working with my spring boot application

2,886 views
Skip to first unread message

surajt...@gmail.com

unread,
Sep 3, 2018, 5:19:38 PM9/3/18
to Redis DB
Hi all I am trying to connet to my redis local server. But the connection is failing . I am using <version>1.5.10.RELEASE</version> .
and <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId> jump-boot-starter-data-redis </ artifactId>
</dependency>

public class RedisConfig {

@Autowired
private JedisConnectionFactory jedisConnectionFactory;

@Bean
public RedisTemplate <Object, Object> redisTemplate () {

    System.out.println("localhost")
    System.out.println("6379");
    jedisConnectionFactory.getHostName();
    jedisConnectionFactory.getPort();

    RedisTemplate<Object, Object> template = new RedisTemplate<>();
    template.setConnectionFactory(jedisConnectionFactory);
    template.setValueSerializer(new GenericToStringSerializer<Object>(Object.class));
    return template;
}

@Bean
public CacheManager cacheManager (RedisTemplate redisTemplate) {
    RedisCacheManager cacheManager = new RedisCacheManager(redisTemplate);
    // Number of seconds before expiration. Defaults to unlimited (0)
    cacheManager.setDefaultExpiration (60);
    cacheManager.setUsePrefix (true);
    return cacheManager;
}
}
@Cacheable(value="sgcode" , cacheManager ="cacheManager")
public String getSegmentCode (String aname) {
System.out.println("get Segment cache is trigger"+ aname);
return segmentCodeMap.get(aname);
}

Logger line will be printed only once after that it should fetch from cache.

Error:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.redis.core.RedisTemplate]: Factory method 'redisTemplate' threw exception; nested exception is org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
... 23 common frames omitted
Caused by: org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool

I have checked the redis server is up 

redis_1 | _.- `` `. `_. '' -._ Redis 4.0.9 (00000000/0) 64 bit
redis_1 | .-``. -```` `` `\ / _., _ '' -._
redis_1 | (',.-`|`,) Running in standalone mode
redis_1 | | `-._` -...- `__...-.` `-._ | '` _.-' | Port: 6379
redis_1 | | -._ `` ._ / _.- '| PID: 1
Reply all
Reply to author
Forward
0 new messages