Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis hash vs key hierarchy

Tags:

redis

What's the practical difference between keeping data in multiple hashes (HSET foo oof 1, HSET bar rab 2) and using plain keys in a hierarchy (SET foo:oof 1, SET bar:rab 2)?

like image 871
Vanadium Avatar asked Oct 23 '18 09:10

Vanadium


1 Answers

According to the manual, you'd use hashes to represent a single object.

Also, it's not that efficient to iterate over Redis keys, so if you need to get all the data from a single object, HGETALL is your friend, not a KEYS thing:10:*/multiget fiasco.

However, you can't e.g. set expiry for only one key of a hash, so if you need that functionality, you'll want to use regular keys.

like image 129
AKX Avatar answered Oct 12 '22 12:10

AKX