3

こんにちは、私はredisを初めて使用します。アプリケーションで、データベースの頻繁な挿入/更新と削除にredisを使用したいと思います。

私はpostgresにこのようなテーブルを持っています。

  testtbl                                                   

 unixtime   |   code    | flag1 |count1     |   count2  |   flag2
_________________________________________________________________
1353475056  |   1234    |  A    |60         |   8955    |     N   
1353475060  |   5248    |  B    |131        |   22500   |     F   
1353475056  |   7267    |  C    |36         |   10130   |     X   
1353475056  |   1908    |  B    |0          |       0   |     N   
1353475060  |   9290    |  E    |90         |   11905   |     X   
1353475056  |   6123    |  F    |1          |   702     |     F   
1353475060  |   4145    |  G    |117        |   47920   |     X   
1353475099  |   7000    |  L    |43         |   21720   |     F   
1353475099  |   3256    |  D    |40         |   3915    |     N   

次のようにredisハッシュを使用してこれらのレコードを保存しようとしました

hmset testtbl:1 unixtime 1353475056 code 1234 flag1 A count1  60 count2  8955 flag2 N
hmset testtbl:2 unixtime 1353475060 code 5248 flag1 B count1 131 count2 22500 flag2 F
hmset testtbl:3 unixtime 1353475056 code 7267 flag1 C count1  36 count2 10130 flag2 X
hmset testtbl:4 unixtime 1353475056 code 1908 flag1 B count1   0 count2     0 flag2 N
hmset testtbl:5 unixtime 1353475060 code 9290 flag1 E count1  90 count2 11905 flag2 X
hmset testtbl:6 unixtime 1353475056 code 6123 flag1 F count1   1 count2   702 flag2 F
hmset testtbl:7 unixtime 1353475060 code 4145 flag1 G count1 117 count2 47920 flag2 X
hmset testtbl:8 unixtime 1353475099 code 7000 flag1 L count1  43 count2 21720 flag2 F
hmset testtbl:9 unixtime 1353475099 code 3256 flag1 D count1  40 count2  3915 flag2 N

最初にレコードを取得するには、そのレコードのキーを見つける必要があります。次に、そのキーを使用して、特定のレコードを次のようにフェッチする必要があります。

redis 127.0.0.1:6379> hgetall testtbl:3
 1) "unixtime"
 2) "1353475056"
 3) "code"
 4) "7267"
 5) "flag1"
 6) "C"
 7) "count1"
 8) "36"
 9) "count2"
10) "10130"
11) "flag2"
12) "X"

今の質問は
1)どのようにして任意のキーの値を別のキーに割り当てたり、任意のコマンドの結果をkayに保存したりできますか?
例えば。「TIME」コマンドの結果をredisのキーtesttblに保存したい場合:この場合はunixtime
2)このデータを保存する他の効率的な方法はありますか?
3)unixtime=1353475056またはflag2="N"のすべてのレコードを取得するにはどうすれば
よいですか?4)redisに一括取得ユーティリティはありますか?

4

1 に答える 1

1

1)クライアント側でのみ実装できます。

2、3)シナリオによって異なります。3番目の質問では、ソートされたセットを使用してunixtimeを格納できます。

ZADD testtbl.unixtime 1353475056 testtbl:1 1353475060 testtbl:2 1353475056 testtbl:3 ...

unixtime = 1353475056のすべてのレコードを取得するには:

ZRANGEBYSCORE testtbl.unixtime 1353475056 1353475056
1) "testtbl:1"
2) "testtbl:3"

セットを使用してflag2を格納します。

SADD testtbl.flag2:N testtbl:1 testtbl:4 testtbl:9

flag2="N"であるすべてのレコードを取得するには

SMEMBERS testtbl.flag2:N
1) "testtbl:1"
2) "testtbl:4"
3) "testtbl:9"
于 2012-11-21T18:02:48.087 に答える