How to do it...

To show how to write a MapReduce job for Redis, suppose every user in Relp has some credit that can be used to pay for services in the application. As a promotion, we are going to add $10 to the credit balance of each user in Relp to encourage the user to use Relp. We would like to make it in a distributed way using the MapReduce framework.

  1. First, we prepare sample data using the shell script, preparedata_mr.sh:
$ bash preparedata_mr.sh 
OK 
unix2dos: converting file mr.data to DOS format ... 
All data transferred. Waiting for the last reply... 
Last reply received from server. 
errors: 0, replies: 10000 
  1. We can explore the data with redis-cli:
127.0.0.1:6379> SCAN 0 1) "7" 2) 1) "user:0000006" 2) "user:0000000" 3) "user:0000008" ...

Get Redis 4.x Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.