lis_springboot red">
赞
踩
@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(){
redisTemplate.opsForList().leftPush("list", "Java");
redisTemplate.opsForList().leftPush("list", "Python");
redisTemplate.opsForList().leftPush("list", "C++");
List<String> list = redisTemplate.opsForList().range("list",0, -1);
return list;
}
@GetMapping("/set")
public Set<String> setTest(){
redisTemplate.opsForSet().add("set", "aaa","bab", "jsp");
Set<String> set = redisTemplate.opsForSet().members("set");
return set;
}
@GetMapping("/zSet")
public Set<String> zSetTest(){
redisTemplate.opsForZSet().add("zSet", "aaa", 10);
redisTemplate.opsForZSet().add("zSet", "bbb", 2);
redisTemplate.opsForZSet().add("zSet", "aba", 30);
Set<String> zSet = redisTemplate.opsForZSet().range("zSet", 0, -1);
return zSet;
}
HashMap:key-value
HashOperations:key-hashKey-value
key是每一组数据的ID,hashKey和value是一组完整的HashMap数据,通过key来区分不同的HashMap。
HashMap hashMap1 = new HashMap();
hashMap1.put(key1, value1);
HashMap hashMap2 = new HashMap();
hashMap2.put(key1, value1);
HashMap hashMap3 = new HashMap();
hashMap3.put(key1, value1);
HashOperations<String, String, String> hashOperations = redisTemplate.opsForHash();
hashOperations.put(hashMap1, key1, value1);
hashOperations.put(hashMap2, key1, value1);
hashOperations.put(hashMap2, key1, value1);
@GetMapping("/hash")
public HashMap<String, Integer> hashTest(){
redisTemplate.opsForHash().put("millingForce", "xForce", 10);
redisTemplate.opsForHash().put("millingForce", "yForce", 20);
redisTemplate.opsForHash().put("millingForce", "zForce", 80);
HashMap<String, Integer> map = (HashMap<String, Integer>) redisTemplate.opsForHash().entries("millingForce");
return map;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。