Redis - How the key HASH and SET and ZSET are related on the CrudRepository save?

一曲冷凌霜 提交于 2019-12-04 20:55:18

Before answering, do you mind sharing your RedisTemplate implementation code? (Or this is generated by @RedisHash annotation?) I am new to Spring-Data-Redis myself and didn't know of the @RedisHash annotation and want to check it out.

Anyways, essentially what is happening here is that Spring-Data-Redis repository is inserting the Person object in different data structures natively supported by Redis for different purposes.

Redis supports different data structures such as:

  1. Hash Redis creates a map of string fields and string values to represent your entire Person object. If you do HGETALL persons:{your person id} it will show all the different fields and values associated with your person Object

    HASH holding property values for id "c5cfd49d-6688-4b83-a9b7-be55dd1c36ad" in keyspace "persons"

  2. Set Redis inserts the basic raw string and indexes entities based on their field. Hence there were a lot SET operations in your Redis DB. You can see indexes of firstName and lastName in your data set

    SET holding all ids known in the keyspace "persons"

  3. ZSet This is Redis operation for Sorted Sets data structure. Which is an ordered collections of strings. From Redis Documentations

    In short with sorted sets you can do a lot of tasks with great performance that are really hard to model in other kind of databases.

Seems like Spring Data automatically inserts the location data as a sorted set to optimize CRUD operations.

You can read more here:

https://github.com/spring-projects/spring-data-examples/blob/master/redis/repositories/README.md

https://redis.io/topics/data-types

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!