-
Notifications
You must be signed in to change notification settings - Fork 60
Integrate with Redis
Wuyi Chen edited this page May 10, 2019
·
12 revisions
For integrating microservices with Redis, you need to do several things:
- Install Redis
- Set dependencies
- Set configuration
- Build connection
- Define and implement basic operations with Redis
Redis is an in-memory data structure project implementing a distributed, in-memory key-value database with optional durability.
dependencies {
compile group: 'org.springframework.data', name: 'spring-data-redis', version: '1.8.4.RELEASE'
compile group: 'redis.clients', name: 'jedis', version: '2.9.0'
compile group: 'org.apache.commons', name: 'commons-pool2', version: '2.4.3'
}
You need to add the configuration parameters for connecting Redis. Currently, the configuration of services/server has been centralized into the config server. So you need to add 2 more parameters into the configuration YAML file of the target service which needs to integrate with Redis.
# Omit other parameters
redis.server: "127.0.0.1"
redis.port: "6379"
Also, you need to change the corresponding config class for loading those 2 new parameters into the service.
@Component
public class ServiceConfig{
// Omit other fields and methods
@Value("${redis.server}")
private String redisServer="";
@Value("${redis.port}")
private String redisPort="";
public String getRedisServer(){
return redisServer;
}
public Integer getRedisPort(){
return new Integer(redisPort).intValue();
}
}
- Overview
- Getting Started
-
Technical Essentials
- Autowired
- SpringData JPA
- Configuration File Auto-loading
- Configuration Encryption
- Service Discovery with Eureka
- Resiliency Patterns with Hystrix
- Configure Hystrix
- Service Gateway with Zuul
- Zuul Filters
- Protect Service with Spring Security and OAuth2
- Use JWT as Access Token
- Store Clients and Users' Credentials to DB
- Integrate with Message Queue (Kafka)
- Integrate with Redis
- Tune Logging
- Log Aggregation
- Send Trace to Zipkin
- Build Runnable Jar
- Core Application Logic
- Components