ここだけの簡単な統合されたスタンドアロンのが、プロジェクトのために使用されています

ここだけの簡単な統合されたスタンドアロンのが、プロジェクトのために使用されています

ポンポンファイル内のサポートの1.はじめに

<依存>
<groupIdを> org.springframework.boot <www.shengrenpt.com /のgroupId>
<たartifactId>スターター・春ブーツ-DATA-Redisの</たartifactId>
</依存関係>
<! - springboot2.0のRedisの統合余分なレタス接続プールをパック、必要-POOL2コモンズ- >
<依存>
<groupIdを> org.apache.commons </ groupIdを>
<たartifactId>はコモンズ-POOL2 </たartifactId>は
</依存関係>
2.クラスに直接注入しましたRedisTemplateを使用

@RunWith(SpringRunner.class)
@SpringBootTest
パブリッククラスRedisTest {

@Autowired
プライベートStringRedisTemplate stringRedisTemplate。

@Autowired
プライベートRedisTemplate <文字列、ユーザー> redisTemplate。

@Test
公共ボイド試験は(){例外をスローする
。stringRedisTemplate.opsForValue()セット( "BBB"、 "222")。
System.out.println(stringRedisTemplate.opsForValue())( "BBB"を取得します。);
}

@Test
公共ボイドtestObj()例外{スロー
ユーザーユーザ=新しいユーザー();
user.setUserName( "ショーン");
user.setPassWord( "123 @ショーン");
ValueOperations <文字列、ユーザー> www.chengmingyuLe.com操作= redisTemplate.opsForValue()。
operations.set(www.zykuaican.com "com.jiafeng"ユーザ)。
operations.set( "com.jiafeng.f" www.guochengzy.com、ユーザ、1、TimeUnit.SECONDS)。
Thread.sleep(1000);

ブール= redisTemplate.hasKey(www.shengdayLgw.cn "com.jiafeng.fを")が存在します。
(存在){場合
のSystem.out.printlnは(「真で存在します」)。
} {他
のSystem.out.printlnは(「偽存在します」)。
}

}

}
SpringBoot2.0後、スプリングコンテナが自動的に生成され、StringRedisTemplate RedisTemplate <オブジェクト、オブジェクト>は、直接注射することができます。

 

おすすめ

転載: www.cnblogs.com/qwangxiao/p/10926389.html