How to do it...

In the previous recipe, we assumed each user has a balance. To show how to write a Spark job for Redis, in this example, we are going to compute the sum of the balances of all users in Relp:

  1. The first step we're going to take is to prepare the 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" 4) "user:0000004" 5) "user:0000003" 6) "user:0000002" 7) "user:0000007" 8) "user:0000001" 9) "user:0000009" 10) ...

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.