Redis Server Exceptions

**********************************************
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: Unexpected end of stream.
***************************************************

Solution 1: Need to Restart the server by using below command
ex: service redis-server restart

Integration Redis with spring boot

Steps for Gradle Project
========================
1) Add below dependencies for redis in build.gradle
compile(‘org.springframework.boot:spring-boot-starter-redis’)

2) In application.properties add below configurations
#Reis configuration
spring.redis.host=localhost
spring.redis.port=6379

3) Autowire RedisTemplate in your service or repository classes

@Autowired
RedisTemplate redisTemplate;

 

4) Set and get the values by using redis API

a) Set a value into redis ======= redisTemplate.opsForValue().set(“key name”, “value”)

b) Set a value with expire key ======== redisTemplate.opsForVlaue().set(“key name”, “value”, 30, TimeUnit.Seconds)

c) Get a value from redis ========= redisTemplate.opsForValue().get(“key name”);

d) Get and set a value from redis (update) ======== redisTemplate.opsForValue().getAndSet(“key name”, “new value”);

Simple Redis Commands

redis-cli ping === to check server is running or not
redis-cli ==== To enter into the redis command prompt
redis-cli -h ip address -p port number ===== To connect remote redis server

service redis-server restart ======= Restart redis server

redis-server monitor ============ monitoring the redis server

===========================
Commands for in the prompt
===========================
set key value ==== set value based on key
get key === get value based on key
keys * ==== Shows all keys in cache