【问题标题】:Autoincrement with Long in Redis using Spring Data Repository?使用 Spring Data Repository 在 Redis 中使用 Long 进行自动增量?
【发布时间】:2018-11-13 17:28:15
【问题描述】:

我浏览了链接:Spring Data + Redis with Auto increment Key,但我在Redis 中使用PK 作为Long。我们如何在 Redis 中实现 Autoincrement of ids

Group.java

@RedisHash("groups")
public class Group {
    @Id
    private Long groupId;
    private String name;
}

用户.java

@RedisHash("users")
public class User {
    @Id
    private Long userId;
    private String name;
    private LocalDate createdDate;
}

这里推荐的方法是什么?有什么快速的指示吗?

【问题讨论】:

    标签: redis spring-data-redis


    【解决方案1】:

    即使您将Long 用作Id,Redis 中也没有auto-increment 功能。只需将字符串用作Id 并用org.springframework.data.annotation.Id 注释它,即@Id 并在模型类中应用@Indexed,您应该能够简单地在redis 中获取或搜索哈希。

    它工作得很好,你不需要照顾自动增量等。只需让 Redis 为你创建它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-06
      • 1970-01-01
      • 2018-09-05
      • 2017-05-06
      • 2018-01-09
      • 2012-03-19
      • 2018-05-08
      • 2020-06-03
      相关资源
      最近更新 更多