Databases Reference
In-Depth Information
We can customize the serialization process of the RedisTemplate class by using
the described serializers. The RedisTemplate class provides flexible configuration
options that can be used to set the serializers that are used to serialize value keys,
values, hash keys, hash values, and string values.
The default serializer of the RedisTemplate class is
JdkSerializationRedisSerializer . However, the string serializer is
an exception to this rule. StringRedisSerializer is the serializer that is
by default used to serialize string values.
Implementing a CRUD application
This section describes two different ways for implementing a CRUD application that
is used to manage contact information. First, we will learn how we can implement
a CRUD application by using the default serializer of the RedisTemplate class.
Second, we will learn how we can use value serializers and implement a CRUD
application that stores our data in JSON format.
Both of these applications will also share the same domain model. This domain
model consists of two classes: Contact and Address . The information content of
these classes has already been described in Chapter 2 , Getting Started with Spring Data
JPA . However, we have made the following changes to these classes:
• We removed the JPA specific annotations from them
• We use these classes in our web layer as form objects and they no longer
have any other methods than getters and setters
The domain model is not the only thing that is shared by these examples. They
also share the interface that declares the service methods for the Contact class. The
source code of the ContactService interface is given as follows:
public interface ContactService {
public Contact add(Contact added);
public Contact deleteById(Long id) throws NotFoundException;
public List<Contact> findAll();
public Contact findById(Long id) throws NotFoundException;
public Contact update(Contact updated) throws NotFoundException;
}
Both of these applications will communicate with the used Redis instance by
using the Jedis connector that was described in Chapter 5 , Getting Started with
Spring Data Redis .
 
Search WWH ::




Custom Search