Reputation:
I have a redis
server running on my local machine and I'm facing an issue when getting all keys and reading their values (hashes). let's say I have 100000 accounts, is there any way I can find the one I want by "uuid" or "email" and "password" without lagging out the whole database (current case).
I have already tried getting keys using "ACCOUNT_*" and then reading all fields to find what I want, but as I said it causes a lot of lag when there's many accounts
any help would be appreciated.
Upvotes: 1
Views: 438
Reputation: 4052
Seems like a perfect use case for RediSearch. It will automatically create and maintain secondary indices for your hashes or JSON documents and allow for SQL-like search.
FT.CREATE accounts ON HASH PREFIX 1 acct: SCHEMA uuid TAG SORTABLE
OK
HSET acct:1 uuid a1 key1 val11 key2 val12
(integer) 1
HSET acct:2 uuid a2 key1 val21 key2 val22
(integer) 1
HSET acct:3 uuid a3 key1 val31 key2 val32
(integer) 1
FT.SEARCH accounts "@uuid:{a1}"
1) (integer) 1
2) "acct:1"
3) 1) "uuid"
2) "a1"
3) "key1"
4) "val11"
5) "key2"
6) "val12"
Upvotes: 1