1.製品モジュールに依存関係を追加します
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
2.関連する構成を追加します
上記の依存関係を追加すると、RedisAutoConfigurationクラスを受け取ることができ、注釈で、構成がRedisPropertiesクラスに配置されていることがわかります。
redisデプロイメントマシンは仮想マシンであり、ポートのデフォルトは6379です。
3.Redisは使いやすいです
RedisAutoConfigurationに2つのBeanがあります。1つはkとvの汎用タイプを柔軟に設定でき、もう1つは文字列専用です。なぜ次の図を見てください。
k、vはすべて文字列型のシリアル化メカニズムで実行されます
テストクラスのコード
@Autowired
StringRedisTemplate stringRedisTemplate;
@Test
public void testStringRedisTemplate(){
ValueOperations<String, String> opsForValue = stringRedisTemplate.opsForValue();
opsForValue.set("hello","World"+ UUID.randomUUID().toString());
System.out.println("hello键的值为:"+opsForValue.get("hello"));
}
通常の印刷テスト結果を見ることができます
それはredisクライアントでも見ることができます