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.
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.Code:JacksonJsonRedisSerializer<MyUser> jsonSerializer = new JacksonJsonRedisSerializer<MyUser>(MyUser.class); redisTemplate.setValueSerializer(jsonSerializer); 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 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.Code:Set<String> keys = redisTemplate.opsForZSet().rangeByScore(key, course.getId(), course.getId()); return redisTemplate.opsForValue().multiGet(keys);
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?Code:public MyUser(String json) { JacksonJsonRedisSerializer<MyUser> jsonSerializer = new JacksonJsonRedisSerializer<MyUser>(MyUser.class); jsonSerializer.deserialize(json.getBytes()); }


Reply With Quote