1

This answer doesn't work for me

I run this command to find the number of keys that I want

SCAN 0 MATCH "test_user:*"

so I got a (very long) list of hashes that I want to export to CSV.

I tried

SCAN 0 MATCH "test_user:*" > list.csv

or simply

SCAN 0 MATCH "test_user:*" > list.txt

but always with syntax error response.

Any idea?

Sergio Gandrus
  • 139
  • 1
  • 12

1 Answers1

2

The only way I found is this (creating a sh script)

redis-cli --scan --pattern test_user:* |\
grep -e "^test_users:[^:]*$" |\
awk '{print "hmget " $0 " id display_name reputation location"}' |\
redis-cli --csv > test_user.csv

It works very well scanning for pattern, you can use regex for better accuracy. Then you use a awk script to run the redis command 'hmget'. Finally the output is printed in a csv file with the --csv utility

https://rdbtools.com/blog/redis-export-hashes-as-csv-using-cli/

Sergio Gandrus
  • 139
  • 1
  • 12