Announcement Announcement Module
No announcement yet.
Basic Spring Redis Data Retrieval Question Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Basic Spring Redis Data Retrieval Question

    I'm able to push the data to Redis as I'm able to see the serialized data in the Redis CLI, but I'm having a little trouble understanding how to get it out.

    JacksonJsonRedisSerializer<MyUser> jsonSerializer = new JacksonJsonRedisSerializer<MyUser>(MyUser.class);
    String key = "course:" + course.getId() + ":registrants";
    for(MyUser student : users) {
        byte[] bytes = jsonSerializer.serialize(student);
        redisTemplate.opsForValue().set(userKey + student.getId(), bytes);
        redisTemplate.opsForZSet().add(key, bytes, course.getId());
    I created another method where I try to retrieve the data from Redis. The exception I get is on the line where I get the keys.

    Set<String> keys = redisTemplate.opsForZSet().rangeByScore(key, course.getId(), course.getId());
    return redisTemplate.opsForValue().multiGet(keys);
    I was initially getting an InvocationTargetException where Jackson was complaining that there was no single string arg constructor for the MyUser class. I created that and added a line using JacksonJsonRedisSerializer and had it deserialize the string in the constructor by calling getBytes on it.

    public MyUser(String json) {
        JacksonJsonRedisSerializer<MyUser> jsonSerializer = new JacksonJsonRedisSerializer<MyUser>(MyUser.class);
    The JSON parser didn't like that and I am at a loss as to where I should proceed next. Is there something I am missing or doing incorrectly?
    Last edited by cowtowndeveloper; Oct 26th, 2012, 04:00 PM. Reason: Better formatting