gpt4 book ai didi

Spring Data Redis 不会将日期保留为空值

转载 作者:IT王子 更新时间:2023-10-29 06:16:31 26 4
gpt4 key购买 nike

我是 Spring Data Redis 的新手,正在尝试将 deletedDate 保存为 null。当我在 Redis 中保留 deletedDate 时,它不会保留 null。我正在使用 Java8 LocalDateTime 格式化程序。

用户.java

@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@RedisHash("users")
public class User {
@Id @Indexed
private String userId;
private String name;
private LocalDate createdDate;
}

我的测试类:

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class UserGroupTest extends RepositoryTestSupport{
@Autowired private UserRepository userRepository;
@Autowired private GroupRepository groupRepository;
@Autowired private UserGroupRelRepository userGroupRelRepository;

@Before
public void setUp() throws JsonProcessingException {
User raj = User.builder().name("Raj Kumar").createdDate(null).build();
User parag = User.builder().name("Parag Rane").createdDate(null).build();
User sagar = User.builder().name("Sagar Parate").createdDate(null).build();

userRepository.saveAll(Arrays.asList(raj, parag, sagar));

Group hardware = Group.builder().name("Hardware").build();
Group software = Group.builder().name("Hardware").build();
Group machineLearning = Group.builder().name("Mchine Learning").build();
Group ai = Group.builder().name("Artificial Inteligence").build();

groupRepository.saveAll(Arrays.asList(hardware, software, machineLearning));


// Raj interested in Hardware and AI
UserGroupRel userGroupRel1 = UserGroupRel.builder().userId(raj.getUserId()).groupId(hardware.getGroupId()).build();
UserGroupRel userGroupRel2 = UserGroupRel.builder().userId(raj.getUserId()).groupId(ai.getGroupId()).build();

// Parag interested in hardware, software and ML
UserGroupRel userGroupRel_1 = UserGroupRel.builder().userId(parag.getUserId()).groupId(hardware.getGroupId()).build();
UserGroupRel userGroupRel_2 = UserGroupRel.builder().userId(parag.getUserId()).groupId(software.getGroupId()).build();
UserGroupRel userGroupRel_3 = UserGroupRel.builder().userId(parag.getUserId()).groupId(machineLearning.getGroupId()).build();

// Sagar intersted in AI and ML
UserGroupRel user_GroupRel1 = UserGroupRel.builder().userId(sagar.getUserId()).groupId(machineLearning.getGroupId()).build();
UserGroupRel user_GroupRel2 = UserGroupRel.builder().userId(sagar.getUserId()).groupId(ai.getGroupId()).build();

userGroupRelRepository.saveAll(Arrays.asList(userGroupRel1, userGroupRel2, userGroupRel_1, userGroupRel_2,
userGroupRel_3, user_GroupRel1, user_GroupRel2));


List<UserGroupRel> userGroupRels = userGroupRelRepository.findByGroupId(hardware.getGroupId());
System.out.println("USER GROUPS DETAILS SIZE :"+userGroupRels.size());
for (UserGroupRel userGroupRel : userGroupRels) {
System.out.println("USER_GROUP :"+new ObjectMapper().writeValueAsString(userGroupRel));
List<User> users = userRepository.getByUserId(userGroupRel.getUserId());
for(User u : users) {
System.out.println("Users interested in Hardwares are : "+u.getName());
}
}
}
}

日期另存为 enter image description here

问题已发布在这里:https://jira.spring.io/browse/DATAREDIS-912

我看到了https://github.com/facebook/hhvm/issues/6062 & https://github.com/NodeRedis/node_redis/issues/507 ,但就在 Spring Data Redis 中实现而言,事情还不清楚。

最佳答案

Spring Data Redis Repositories 将具有 null 值的属性表示为非写入的哈希条目。或者简化:null 属性不写入 Redis。

关于Spring Data Redis 不会将日期保留为空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53720836/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com