0
    template.setEnableTransactionSupport(true);
    template.multi();
    template.opsForValue().set("mykey", "Hello World");
    List<String> dataList = template.opsForList().range("mylist", 0, -1);
    template.exec();

こんにちは、みんな。redis に「mylist」というリストがあり、そのサイズは 50 です。

しかし、このコードを実行すると、必要なものが得られません。

フィールド「dataList」は null ですが、値「Hello World」を持つ「mykey」が私の redis に保持されています。

では、spring-data-redis トランザクションでリスト データを取得するにはどうすればよいでしょうか? どうもありがとう。

4

1 に答える 1

1

SD-Redis のトランザクション サポートは、進行中のトランザクションへの参加を支援し、自動コミット ( exec) / ロールバック ( discard) を許可するため、同じ接続を使用してコマンドをスレッド バインドされた複数の実行ブロックにラップするのに役立ちます。
より一般的には、redis トランザクションとトランザクション内のコマンドがサーバー側でキューに入れられ、結果のリストが に返されexecます。

template.multi();

// queue set command
template.opsForValue().set("mykey", "Hello World"); 

// queue range command
List<String> dataList = template.opsForList().range("mylist", 0, -1);

// execute queued commands
// result[0] = OK
// result[1] = {"item-1", "item-2", "item-", ...}
List<Object> result = template.exec();                                   
于 2016-04-25T13:19:28.407 に答える