-1

I user a CRUDRepository in my spring data redis project to persist a redis hash in my redis cluster. i have rest api written to persist and get thte values of the data. this works fine.

however my entity annotated with RedisHash is being saved as a set / and i am not able to look inside the value using redis cli.

how do i look inside a set data type(without popping) in redis cli

i looked at redis commands page https://redis.io/commands#set i only get operations which can pop value . i neeed to simply peek

EDIT: to make things clearer, i am using spring crudrepo to save the user entity into redis data store. the user entity gets saved as a set data type.

when i query back the user details, i can see entire details of the user

{ userName: "somak", userSurName: "dattta", age: 23, zipCode: "ah56h" }

i essentially want to do the same using redis cli... but all i get is 127.0.0.1:6379> smembers user 1) "somak" how do i look inside the somak object.

@RestController
@RequestMapping("/immem/core/user")
public class UserController {

    @Autowired
    private UserRepository userRepository;


    @RequestMapping(path = "/save", method = RequestMethod.GET, produces = "application/json")
    @ResponseStatus(HttpStatus.OK)
    public void saveUserDetails() {

        User user = new User();
        user.setAge(23);
        user.setUserName("somak");
        user.setUserSurName("dattta");
        user.setZipCode("ah56h");
        userRepository.save(user);
    }

    @RequestMapping(path="/get/{username}", method = RequestMethod.GET, produces = "application/json")
    public User getUserDetails(@PathVariable("username") String userName) {

        return userRepository.findById(userName).get();
    }
}




@Repository
public interface UserRepository extends CrudRepository<User, String>{

}



@RedisHash("user")
public class User {

    private @Id String userName;

    private @Indexed String userSurName;

    private @Indexed int age;

    private String zipCode;

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getUserSurName() {
        return userSurName;
    }

    public void setUserSurName(String userSurName) {
        this.userSurName = userSurName;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getZipCode() {
        return zipCode;
    }

    public void setZipCode(String zipCode) {
        this.zipCode = zipCode;
    }


}
user1906450
  • 517
  • 1
  • 6
  • 19

1 Answers1

0

I don't understant your descr with your problem, but I understand your title.

In redis set, the member is always string type.

I hope you can offer more info about UserRepository.save:

    User user = new User();
    user.setAge(23);
    user.setUserName("somak");
    user.setUserSurName("dattta");
    user.setZipCode("ah56h");
    userRepository.save(user);

And you can check your redis data and check data type when rest api invoked.

Ryoma
  • 64
  • 1
  • 9
  • edited my question for more details and to make it clear – user1906450 May 05 '19 at 06:36
  • I think your data maybe not all in set struct. I hope your can do in your test env: - 1: exec flushdb command( flush redis ) - 2: invoke your api - 3: exec keys * - 4: exec type key_name(3 exec keys * get all key name) – Ryoma May 05 '19 at 06:44
  • 127.0.0.1:6379> type user set – user1906450 May 05 '19 at 06:49
  • 127.0.0.1:6379> keys u* 1) "user:somak" 2) "user:userSurName:dattta" 3) "user:age:23" 4) "user" 5) "user:somak:idx" – user1906450 May 05 '19 at 06:49
  • i am not able to understand what exactly i am doing wrong?? the type of user is set bt the keys are coming as user:somak, user:userSurName – user1906450 May 05 '19 at 06:50
  • yes agreeed...its in hash structure 127.0.0.1:6379> hget user:somak age "23" 127.0.0.1:6379> hget user:somak userName "somak" 127.0.0.1:6379> hget user:somak zipCode "ah56h" – user1906450 May 05 '19 at 06:55
  • @user1906450 I think you get and you know what is reason. – Ryoma May 05 '19 at 09:21