I went through the link : Spring Data + Redis with Auto increment Key, but I am using PK as Long
in Redis
. How we can do Autoincrement
of ids
in Redis ?
Group.java
@RedisHash("groups")
public class Group {
@Id
private Long groupId;
private String name;
}
User.java
@RedisHash("users")
public class User {
@Id
private Long userId;
private String name;
private LocalDate createdDate;
}
What's the recommanded approach here? Any quick pointers?
There is not auto-increment
features in Redis even if you used Long
as Id
. Simply used the String as Id
and annotate it with org.springframework.data.annotation.Id
i.e @Id
and apply @Indexed
at the Model class and you should be simply able to get or search the hash in redis.
It works well and you dont need to take care of Auto-increment etc. Just leave upto Redis to create it for you.