0

I have a scenario where I need to sync my MySQL data into redis cache every 2 minutes.

Basically I have 2 tables categories and articles table. Every article belongs to some particular category. Retrieval : I need to fetch articles of particular section and sometimes limiting it.

I saw the 5 data structures available in Redis but getting confused to choose one of them which will be the appropriate for these requirements.

Every 2 minutes the entire data as to be removed and inserted.

So what is the best way I can go on with it.

4

1 に答える 1

2

シナリオに役立つ1つの提案は、次のとおりです。

  • 記事とカテゴリを格納するハッシュ テーブル。

  • Sorted カテゴリごとの最新記事のインデックスとして機能するように設定します。

上記から、次のようになります。

  • カテゴリと記事の Redis 内のハッシュ テーブルにオブジェクトを追加します。これにより、ここで述べたように、平均して一定の時間の複雑さを持つデータ構造の恩恵を受けることができます。

    HMSET article_with_id_{1234} field1 value1 .. etc

    HMSET category_with_id_{567} field1 value1 .. etc

  • 次に、それらを接続するための構造が必要になります。次のように並べ替えられたセットの作成を開始しますone category -> many articles。以下に例を示します。

    ZADD category_{category_id} {Sorting Score - it could be the article_id in descending order or the timestamp as you mentioned} {article ID}

これで、カテゴリごとに参照できるインデックスが作成されました。したがって、データのプルは次のようになります。

ZREVRANGE category_{category_id} 0 10

そのカテゴリから最高得点の 10 件の記事の並べ替えられたセットを引き出します。これはページネーションにも役立ちます。

収集した記事 ID から、ハッシュから記事の詳細情報を取得できます。HGET

于 2015-11-24T17:20:44.060 に答える