Professional Documents
Culture Documents
W7D2 - Redis POC with AWS Setup & Spring [18June]
W7D2 - Redis POC with AWS Setup & Spring [18June]
W7D2 - Redis POC with AWS Setup & Spring [18June]
Cache is a temporary data storage areas. Used for faster access of data.
UI - Server
Instead of calling server everything, take data which was previously saved
Cache only that data, which will not change that frequently.
2 types of cache:
In memory
You store the data internally in service memory
java class, some datastructure
- when restart happens, then its all deleted.
all cache is empty.. and starts filling slow. till all data is again in cache..
system will perform slowly.
- shares same memory as your application..
which might impact the execution of your functional system.
- Autoscaled nodes will not have cache data.. so its needs to be somehow
populated.. till that time, service will work slowly..
- Out of sync issue.. needs to be handled in all instances..
External Cache
You dont save data in your spring boot service.
Rather keep it externally.
Database MySQL.
Install MySQL
Some tool to connect to mysql
CLI -
(DBeaver/MySQL workbench) - GUI
Write SQL queries - to operate on that DB.
How data is stored in DB
how to work with that DB.
Some special coding, for java application to talk to DB.
Git
SourceTree - GUI
git bash - CLI
yum update -y
2 yum install redis -y
3 amazon-linux-extras install redis6
4 systemctl start redis
5 systemctl enable redis
6 systemctl status redis
9 vi /etc/redis/redis.conf
10 systemctl restart redis
CLI: redis-cli
GUI
List operation
RPUSH mylist "first"
RPUSH mylist "second"
RPUSH mylist "third"
LRANGE mylist 0 -1 # Returns all elements in the list
Hash operations
HSET myhash name "John Doe"
HSET myhash phone "123123" email "john@doe.com"
HGETALL myhash
HGET myhash email
== Coding:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
package com.cpt.payments.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
@Configuration
public class RedisConfig {
@Bean
public RedisConnectionFactory redisConnectionFactory() {
RedisStandaloneConfiguration redisStandaloneConfiguration = new
RedisStandaloneConfiguration();
redisStandaloneConfiguration.setHostName("13.126.88.92");
redisStandaloneConfiguration.setPort(6379);
redisStandaloneConfiguration.setDatabase(0);
@Bean
public RedisTemplate<String, String> redisTemplate() {
RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(redisConnectionFactory());
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new StringRedisSerializer());
return redisTemplate;
}
}