问题
I have saved lists in following format in my Redis database.
key:inner-key1:inner-key2:inner-key3
For example my database looks like this:
A:B:X:val1
A:B:Y:val2
A:C:X:val3
A:C:Y:val4
How can I get inner keys for key B? I was trying to get it using KEYS A:B:*, but result of this are whole lines "A:B:X:val1" and "A:B:X:val2". All I need is to get only first inner key of "A:B" in format for example [X, Y].
回答1:
You can use Redis Hash to acheive the same:
Your Keys are
A:B:X:val1
A:B:Y:val2
A:C:X:val3
A:C:Y:val4
you can save your keys as
HSET A:B X val1
HSET A:B Y val2
HSET A:C X val1
HSET A:C Y val2
Now to get all keys for A:B you can do like
HKEYS A:B this will return [X Y]
来源:https://stackoverflow.com/questions/20271372/redis-list-of-nested-keys