@GetMapping("/string")
public String stringTest(){
redisTemplate.opsForValue().set("str","Hello World");
String str = (String)redisTemplate.opsForValue().get("str");
return str;
}
@GetMapping("/list")
public List<String> listTest(){
ListOperations<String,String> listOperations= redisTemplate.opsForList();
listOperations.leftPush("list","Hello");
listOperations.leftPush("list","World");
listOperations.leftPush("list","java");
List<String> list = listOperations.range("list",0,2);
return list;
}
@GetMapping("/set")
public Set<String> setTest(){
SetOperations<String,String> setOperations = redisTemplate.opsForSet();
setOperations.add("set","Hello");
setOperations.add("set","Hello");
setOperations.add("set","Java");
Set<String> set =setOperations.members("set");
return set;
}
@GetMapping("/zset")
public Set<String> zsetTest(){
ZSetOperations<String,String> zSetOperations = redisTemplate.opsForZSet();
zSetOperations.add("zset","Hello",3);
zSetOperations.add("zset","World",2);
zSetOperations.add("zset","Python",1);
Set<String> set = zSetOperations.range("zset",0,2);
return set;
}
@GetMapping("/hashTest")
public void hashTest(){
HashOperations<String,String,String> hashOperations = redisTemplate.opsForHash();
hashOperations.put("key","hashkey","hello");
System.out.println(hashOperations.get("key","hashkey"));
}