SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.
SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.
Successfully reported this slideshow.
Activate your 14 day free trial to unlock unlimited reading.
Spring Framework / Boot / Data 徹底活用 〜Spring Data Redis 編〜
Spring Framework / Boot / Data 徹底活用 〜Spring Data Redis 編〜
1.
Spring Framework / Boot / Data 徹底活用
August 28, 2015
Spring in Summer 夏なのにSpring
!
Naohiro Yoshida
Recruit Technologies Co.,Ltd.
∼Spring Data Redis 編∼
3.
リクルートにおけるSpringへの取り組み
■ リクルートでは全社標準FWとしてSpringの採用を決定
■ 専門部隊で検証やサイトへの適用を進めている
学んだプラクティスについては随時ブログや勉強会等で公開予定
!
!
!
!
!
!
API/バックエンド
Spring Boot
Spring Framework
Spring XXX 独自LIB
!
フロントエンド
node.js
4.
!
!
!
!
!
!
!
!
!
API/バックエンド
本日の内容
Spring BootでのSpring Data Redisの使い方と
プラクティス
Spring Boot
Spring Framework
Spring Rabbit
Spring Boot
Autoconfigure
Spring JMS
Spring Boot
Actuator
Spring Data
Redis
Spring Data
Elasticsearch
Spring ・・・
5.
Spring Data Redis
■ SpringでRedisを操作するためのライブラリ
■ JedisのローレベルAPIを使うのではなく利用しやすいTemplateを提供している
!
@Autowired
private RedisTemplate<Object, Object> redisTemplate;
!
public void access() {
// value
redisTemplate.opsForValue().set(key, System.currentTimeMillis());
Object value = redisWriterTemplate.opsForValue().get(key);
// list
redisTemplate.opsForList().rightPush(key, value);
value = redisWriterTemplate.opsForList().leftPop(key);
// expire
Date expireAt = DateUtils.addHours(dateSupplier.get(), 1);
redisTemplate.expireAt(key, expireAt);
}!
6.
Spring Data Redis ∼Cache利用∼
■ RedisCacheManagerを利用することでspring-contextのCache機構と連携可
@Configuration
@EnableCaching
public class RedisConfiguration extends CachingConfigurerSupport {
!
@Bean
@Autowired
public CacheManager cacheManager(
RedisTemplate<Object,Object> redisTemplate){
RedisCacheManager manager = new RedisCacheManager(redisTemplate);
!
//有効期限設定 (not required)
Map<String, Long> expires = new HashMap<String, Long>();
expires.put("cache.expire.180", new Long(3 * 60));
manager.setExpires(expires);
return manager;
}
}