你如何搜索有价值的键?例如,获取值为"somevalue"的所有KEYS

Gou*_*Pal 3 php redis phpredis

   redis> SMEMBERS CO:1:A
    1) "1"
    2) "2"

   redis> SMEMBERS CO:2:A
    1) "1"
    2) "5"
    3) "6"

   redis> SMEMBERS CO:3:A
    1) "5"

   redis> SMEMBERS CO:4:A
    1) "1"
Run Code Online (Sandbox Code Playgroud)

现在我想找到值1存在的键

如果我使用值1搜索,则结果键将为CO:1:A, CO:2:ACO:4:A

怎么弄这个?

Did*_*zia 5

Redis不是关系数据库.您需要预测此访问路径,并维护反向索引.

# This is your index
SADD CO:1:A 1 2
SADD CO:2:A 1 5 6
SADD CO:3:A 5
SADD CO:4:A 1

# Here is the reverse index
SADD REV:1 1 2 4
SADD REV:2 1
SADD REV:5 2 3
SADD REV:6 2
Run Code Online (Sandbox Code Playgroud)

现在您可以以相反的方式查询:

SMEMBERS REV:1
1) "1"
2) "2"
3) "4"
... meaning CO:1:A. CO:2:A, CO:4:A
Run Code Online (Sandbox Code Playgroud)