0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Spring Data RedisのRedis Repositoriesの制約

Last updated at Posted at 2020-11-28

Redis Repositoriesとは

Working with Redis Repositories lets you seamlessly convert and store domain objects in Redis Hashes, apply custom mapping strategies, and use secondary indexes.

Sprint Data Redisの機能の1つで、JavaオブジェクトとRedis Hashをシームレスに出し入れ出来るのと、インデックスの管理をやってくれる便利なものです。

制約

保存するときにトランザクション無しにdelete & insertするので(上書き保存しないので)、タイミングによってキーが無いように見えます。保存と読み込みを高頻度でやると再現します。

ソースの該当箇所

L234-236

RedisKeyValueAdapter.java
			boolean isNew = connection.del(objectKey) == 0;

			connection.hMSet(objectKey, rdo.getBucket().rawMap());

結論

上記の制約を理解して使うか、Redis Repositoriesを使わないのいずれかと思います。

追記

13.9. Persisting Partial Updates
https://docs.spring.io/spring-data/data-redis/docs/current/reference/html/#redis.repositories.partial-updates
を使うといいよ、というアドバイスをいただいた。
https://jira.spring.io/browse/DATAREDIS-1253

”JavaオブジェクトとRedis Hashをシームレスに出し入れ”とは言えないが、インデックスは更新されるので、INSERTはsave、UPDATEはpartial updatesのように使い分けるといいかも知れない。

同じ問題でハマっている人を見つけて、同じアドバイスをもらってた。
https://stackoverflow.com/questions/48116466/update-entity-in-redis-with-spring-data-redis

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?