Redis данных Spring не сохраняется Дата как нулевое значение - PullRequest
0 голосов
/ 11 декабря 2018

Я новичок в Spring Data Redis и пытаюсь сохранить deletedDate как ноль.Когда я сохраняю deletedDate в Redis, его значение не равно нулю.Я использую форматер Java8 LocalDateTime.

User.java

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

MyTestclasses:

@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.

1 Ответ

0 голосов
/ 13 декабря 2018

Репозитории данных Red Spring представляют свойства со значениями null как неписанные хэш-записи.Или упрощенно: null свойства не записываются в Redis.

...