Sometimes we would like to store our class object to Redis as cache for further process for quick lookup or restore purposes like below screen shot. Assume we have a class called: Member, and we have created data structure dictionary inside the Redis as contract book.
The benefit of choose hash/dictionary for storing our data was we could have O(1) to operate (Get/Update) specific record(s) if you got proper key for it😉.
Here was the sample code in that we could achieve to drop our class collection into Redis with hash/dictionary structure:
You might wonder that why we using batch way for operating with Redis server? Below was simple benchmark for dealing 5000 records:
You could find out that batch insert would take advantage of reduce amount of I/O (networking) so each round for processing 5000 records almost less than 2 seconds comparing to traditional iterator way that cost more than 20 seconds per round. The batch method proceed with 10 times faster👍
If you got interested with benchmark source, see below:
If you got interested in how to do it via lua script, please refer to this story😉.
Reference