I am working on a Spring-MVC application in which I am inserting a Person object in Redis. Now When inserting the object, I also need to provide the hashCode value for Person retrieved. Is there any way, I can retrieve the Person object without passing the hashCode, just the key part. Kindly let me know. Here is the insert code :
Insert code :
Person person = // person retrieved from DB.
this.userAppRegistration.getRedisTemplate().opsForHash().put(String.valueOf(person.getId()),person.hashCode(),person);
Retrieval code :
this.userAppRegistration.getRedisTemplate().opsForHash().get("Key_Available",)
I don't have access to hashcode of the Person I inserted at this point. How can I still retrieve the Person object using only key. Thanks a lot. :-)
Redis is a key-value store. You put there a value with a key, and you retrieve it with the same key.
You've decided to make your key a combination of person's ID, hashcode and the person itself (or rather its toString()
most likely). Don't do that. It makes no sense whatsoever, and as you're now noticing it makes it impossible for you to retrieve the value.