Databases Reference
In-Depth Information
Regardless of the user's approach, we can implement a CRUD application with
Spring Data Redis by following these steps:
1. Configure the application context.
2.
Implement the CRUD functions.
Let's get started and find out how we can implement the CRUD functions for
contact information.
Using default serializers
This subsection describes how we can implement a CRUD application
by using the default serializers of the RedisTemplate class. This means
that StringRedisSerializer is used to serialize string values, and
JdkSerializationRedisSerializer serializes other objects.
Configuring the application context
We can configure the application context of our application by making the following
changes to the ApplicationContext class:
1. Configuring the Redis template bean.
2. Configuring the Redis atomic long bean.
Configuring the Redis template bean
We can configure the Redis template bean by adding a redisTemplate() method
to the ApplicationContext class and annotating this method with the @Bean
annotation. We can implement this method by following these steps:
1.
Create a new RedisTemplate object.
2.
Set the used connection factory to the created RedisTemplate object.
3.
Return the created object.
The source code of the redisTemplate() method is given as follows:
@Bean
public RedisTemplate redisTemplate() {
RedisTemplate<String, String> redis = new RedisTemplate<String,
String>();
redis.setConnectionFactory(redisConnectionFactory());
return redis;
}
 
Search WWH ::




Custom Search