私は、Javaのシリーズを愛する--- [springboot統合Redisの]

SpringBoot集成春データのRedis

実装手順:

1. [追加]は、依存のRedisを開始します
<! -春のデータが依赖Redisの- > 
<依存> 
<groupIdを> org.springframework.boot </ groupIdを> 
<たartifactId>春・ブート・スターター・データのRedis </たartifactId> 
</依存関係>
application.propertiesにRedisのポートアドレスを設定します
#Redisの構成(可能も記入しない)
spring.redis.host = localhostを
spring.redis.port = 6379
Redisのキャッシュクエリすべてのユーザーデータを操作する3.塗りつぶしRedisTemplate
@Autowired
 プライベートRedisTemplete redisTemplete 

@Test 
公共 ボイド testRedis()スローJsonProcessingException { 
文字列のユーザー =(文字列)redisTemplate.boundValueOps( "user.findAll" に.getを();
もし(ユーザ== NULL ){ 
リスト <ユーザー> USERLIST = userMapper.queryUserList()。
ObjectMapper jsonFormat = 新しいObjectMapper(); 
ユーザー = jsonFormat.writeValueAsString(ユーザーリスト)。
redisTemplate.boundValueOps( "user.findAll" ).SET(ユーザー); 
System.out.printlnは(「==============データベースから取得したユーザデータを===================」); 
} { 
のSystem.out。 println( "============== Redisの===================バッファのユーザデータから得られた");
 } 
のSystem.out .println(ユーザ); 
}
 

おすすめ

転載: www.cnblogs.com/hujunwei/p/11879649.html