0

I am trying to execute multiGet function in Spring on Redis. It throws me an error. I have implemented get function successfully but while implementing multiGet it asks me for a Collection as second parameter. I am not sure what to enter? Can someone please guide me here.

Here is my code for multiGet()

Method definition:

@Override
 public User findById_MultiGet(String id) {
    return (User)hashOperations.multiGet("USER", id);
 }

Code In Controller :

@GetMapping("Map/MultiGet/{id}")
 public User allMultiGet(@PathVariable("id") final String id)    {
    // MultiGet function
    return userRepository.findById_MultiGet(id);
}

Error for above multiget method is multiget(Object, Collection) type not (String,String) type

Below code for Get function is working.

public User findById(String id) {
    return (User)hashOperations.get("USER", id);
 }

Code In Controller for Get function :

@GetMapping("Map/Get/{id}")
public User allGet(@PathVariable("id") final String id) {
 // Get function
    return userRepository.findById(id);
}
asgs
  • 3,928
  • 6
  • 39
  • 54
Ruchita J
  • 23
  • 7

1 Answers1

1

For multiGet the second parameter should be a Collection like a List (in case you want the values of the list returned as result on the same positions as their belonging keys in the input list) or a Set.

In your example this would be something like this:

List<Object> values = hashOperations.multiGet("USER", Arrays.asList("id", "name")); 
Object id = values.get(0);
Object name = values.get(1);
Sascha
  • 241
  • 1
  • 3
  • 9