Databases Reference
In-Depth Information
The source code of our dummy implementation is given as follows:
@Service
public class RedisContactService implements ContactService {
@Resource
private RedisAtomicLong contactIdCounter;
@Resource
private RedisTemplate<String, String> redisTemplate;
//Add methods here.
}
The next step is to implement common methods that are used by the methods
declared by the ContactService interface. These private methods are described in
the following table:
Method
Description
String buildKey(Long contactId)
Returns a key for a contact.
Contact buildContact(String key)
Fetches the information of a contact and
returns the found contact.
Contact buildContact(Long id)
Fetches the information of a contact and
returns the found contact.
boolean contactDoesNotExist(Long
id)
Returns false if a contact is found with
the given ID and true otherwise.
String persist(Contact persisted)
Saves the contact information and
returns the key of the contact.
First, we have to implement the method that is used to build keys for our contacts.
Our implementation of the buildKey() method is quite simple. We build the key by
appending the contact ID given as a parameter to a string contact and returning the
resulting string. The source code of the buildKey() method is given as follows:
private String buildKey(Long contactId) {
return "contact" + contactId;
}
Search WWH ::




Custom Search