10

「レコード」を作成するために Redis を使用する場合、複数のフィールドを持つハッシュを作成できます。例えば:

HMSET myhash field1 "Hello" field2 "World"
HMSET myhash2 field1 "Goodbye" field2 "World"

キー値を知ることでこれを取得できますが、フィールド 2 に「World」が含まれるすべてのハッシュを取得する方法はありますか?

4

2 に答える 2

23

There are no indexes in redis, and it doesn't implement SQL. It's a key-value store. You provide a key, it gets you a value.

That said, you can implement this by maintaining secondary indexes yourself. For example:

create a record and an index entry

HMSET myhash field1 Hello field2 World
SADD field2_world myhash

update a record, delete old index entry, create new one

SREM field2_world myhash
HMSET myhash field2 Mundo
SADD field2_mundo myhash

find all records which have "World" in field2

SMEMBERS field2_world

I hope you get the idea.

于 2012-06-26T14:36:00.290 に答える
0

次の読者のために、SORTコマンドはおそらく「BYパターン」引数の使用に役立つでしょう

HMSET myhash field1 Hello field2 World
SORT myhash BY World

パターンの例 (w3resource)

于 2021-01-12T16:09:56.583 に答える