redis springBoot中的使用 Sucha

redis springBoot中的使用 Sucha

1、使用RedisOperations对List(其实Object也可以)进行存取

  • 示例list操作
List weekMenuList = weekMenuService.getWxWeekMenuList();//把list放入redis
redisStringDao.saveOrUpdate(RedisConst.KEY_PREFIX_TYPE_STAFF_WEEK_MENU_LIST, currentOrgId(),weekMenuList, 1000);
//获取
redisStringDao.get(RedisConst.KEY_PREFIX_TYPE_STAFF_WEEK_MENU_LIST, currentOrgId())
  • RedisStringDaoImpl实现类,其中有saveOrUpdate方法
/*** 通用String型参数操作实现类** @author Kamisama* @date 2017/10/30*/
@Repository("redisStringDao")
public class RedisStringDaoImpl implements RedisStringDao {private static final String KEY_PREFIX = "husk:stringValue:";/*** Redis操作对象*/private RedisOperations redisOperations;public RedisStringDaoImpl() {}@Autowired(required = false)public RedisStringDaoImpl(RedisOperations redisTemplate) {this.redisOperations = redisTemplate;}@Overridepublic void saveOrUpdate(String type, String name, Object value, long timeoutMinutes) {redisOperations.boundValueOps(getKey(type, name)).set(value, timeoutMinutes, TimeUnit.MINUTES);}@Overridepublic Object get(String type, String name) {return redisOperations.boundValueOps(getKey(type, name)).get();}/*** 取得参数在Redis库里对应的键* @param type 参数类型* @param name 参数名* @return 键*/private String getKey(String type, String name) {return KEY_PREFIX + type + ":" + name;}}

Q.E.D.


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部