@Autowired
@Resource(name="redisTemplate")
private RedisTemplate<String, String> rt;
public void flushdb(){
rt.execute(new RedisCallback<Object>() {
public String doInRedis(RedisConnection connection) throws DataAccessException {
connection.flushDb();
return "ok";
}
});
}
public void set(){
flushdb();
HashOperations<String, String, String> vo = rt.opsForHash();
vo.put("book", "wzg", "dsg");
Map<String, String> map = new HashMap<String, String>();
map.put("cff", "xsg");
map.put("cl", "xxsg");
vo.putAll("book", map);
vo.putIfAbsent("book", "mc", "www");
vo.increment("book", "yw", 1l);
vo.delete("book", "cl","yw");
}
public void get(){
HashOperations<String, String, String> vo = rt.opsForHash();
out(vo.get("book", "wzg"));
out(String.valueOf(vo.get("book", "yw")));
out(vo.multiGet("book", Arrays.asList("wzg","cff","cl","mc")));
out(vo.hasKey("book", "wzg"));
out(vo.entries("book"));
out(vo.keys("book"));
out(vo.values("book"));
out(vo.size("book"));
}
public void out(String str){
System.out.println(str);
}
public void out(Collection list){
System.out.println(list);
}
public void out(long num){
System.out.println(num);
}
public void out(Integer num){
System.out.println(num);
}
public void out(boolean num){
System.out.println(num);
}
public void out(Map num){
System.out.println(num);
}