Databases Reference
In-Depth Information
The source code of the persist() method is given as follows:
private String persist(Contact persisted) {
Long id = persisted.getId();
if (id == null) {
id = contactIdCounter.incrementAndGet();
persisted.setId(id);
}
String contactKey = buildKey(id);
BoundHashops ops = redisTemplate.boundHashOps(contactKey);
ops.put("id", persisted.getId());
ops.put("emailAddress", persisted.getEmailAddress());
ops.put("firstName", persisted.getFirstName());
ops.put("lastName", persisted.getLastName());
ops.put("phoneNumber", persisted.getPhoneNumber());
Address address = persisted.getAddress();
ops.put("streetAddress", address.getStreetAddress());
ops.put("postCode", address.getPostCode());
ops.put("postOffice", address.getPostOffice());
ops.put("state", address.getState());
ops.put("country", address.getCountry());
return contactKey;
}
We have now implemented the common methods of the RedisContactService
class. Let's move on and find out how we can provide the CRUD operations for the
contact information.
Create
We can create a new contact by following these steps:
1.
Save the added contact to the hash.
2.
Add the key of the contact to our contact set.
3.
Return the added contact.
 
Search WWH ::




Custom Search