Spring RedisTemplate操作-全注解操作
2017-09-20 09:08
671 查看
package com.panku.web.redis;
import java.util.HashMap;
import java.util.Map;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import com.panku.web.entity.User;
/**
* Spring RedisTemplate操作-全注解操作
* @author ccx
*
*/
@Service
@CacheConfig(cacheNames="user")
public class RedisTemplateAnnotation {
public Map<Integer, User> map = new HashMap<Integer,User>();
public void insert(User user){
map.put(user.getId(), user);
}
@Cacheable(key = "'id_'+#id")
public User get(String id){
System.out.println("get被调用了");
return map.get(id);
}
@CacheEvict(key = "'id_'+#id")
public User del(String id){
return map.remove(id);
}
@CacheEvict(allEntries=true)
public void delAll(){
}
public Map<Integer, User> getMap() {
return map;
}
public void setMap(Map<Integer, User> map) {
this.map = map;
}
}
import java.util.HashMap;
import java.util.Map;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import com.panku.web.entity.User;
/**
* Spring RedisTemplate操作-全注解操作
* @author ccx
*
*/
@Service
@CacheConfig(cacheNames="user")
public class RedisTemplateAnnotation {
public Map<Integer, User> map = new HashMap<Integer,User>();
public void insert(User user){
map.put(user.getId(), user);
}
@Cacheable(key = "'id_'+#id")
public User get(String id){
System.out.println("get被调用了");
return map.get(id);
}
@CacheEvict(key = "'id_'+#id")
public User del(String id){
return map.remove(id);
}
@CacheEvict(allEntries=true)
public void delAll(){
}
public Map<Integer, User> getMap() {
return map;
}
public void setMap(Map<Integer, User> map) {
this.map = map;
}
}
相关文章推荐
- Spring RedisTemplate操作-注解缓存操作(11)
- Spring RedisTemplate操作-注解缓存操作(11)
- Spring RedisTemplate操作-List操作(4)
- 关于springboot整合redis(使用RedisTemplate操作redis)
- Spring RedisTemplate操作-发布订阅操作(8)
- Spring RedisTemplate操作-事务操作(9)
- jedis与spring整合及简单的使用RedisTemplate操作
- Spring RedisTemplate操作-ZSet操作(6)
- Spring RedisTemplate操作-List操作
- Spring RedisTemplate操作-Set操作(5)
- spring data redis RedisTemplate操作redis相关用法
- Spring RedisTemplate操作-Set操作
- jedis与spring整合及简单的使用RedisTemplate操作
- Spring RedisTemplate操作-HyperLogLog操作(7)
- Spring中使用RedisTemplate操作Redis(spring-data-redis)
- Spring RedisTemplate操作-ZSet操作
- Spring RedisTemplate操作-发布订阅操作(8)
- Spring RedisTemplate操作-HyperLogLog操作
- Spring RedisTemplate操作-通道操作(10)
- Spring RedisTemplate操作-序列化操作