Redis 소개
Redis는 업계에서 가장 널리 사용되는 메모리 데이터 저장소입니다. Memcached와 비교하여 Redis는 해시, 목록, 세트 등과 같은 더 풍부한 데이터 구조를 지원하고 데이터 지속성을 지원합니다. 또한 Redis는 트랜잭션, HA 및 마스터 슬레이브 라이브러리와 같은 일부 데이터베이스와 같은 기능을 제공합니다. Redis는 캐싱 시스템과 데이터베이스의 특성을 가지고 있으므로 풍부한 응용 프로그램 시나리오가 있습니다.
소개
단위 테스트의 경우 테스트의 안정성과 객관성을 보장하기 위해 단일 환경을 유지하고 네트워크 리소스와 통신하지 않도록해야합니다. SpringBoot 프레임 워크의 경우 단위 테스트 Junit을 통합합니다. 동시에 프로젝트를 설계 할 때 MongoDB, Redis, MySQL 등과 같은 다양한 임베디드 스토리지 도구를 사용할 수 있습니다. 오늘날에는 주로 임베디드 레디의 사용에 대해 이야기 할 것입니다.
사용 방법은 다음과 같습니다.
패키지 참조 build.gradle을 추가하십시오
TestCompile ( 'com.github.kstyrc : Embedded-Redis : 0.6')
구성 분사를 추가하십시오
import org.springframework.bean.beans.annotation.autowired; import org.springframework.context.annotation.bean; import org.spramframework.context.annotation.configuration; import org.spramework.data.redis.connection.redisconnection.rediscontectory; import org.springframework.data.redis.core.hashoperations; import org.springframework.data.redis.core.listoperations; import org.springframework.data.redis.core.redistemplate; import org.springframework.data.redis.redis.core.setoperations; org.springframework.data.redis.core.valueoperations; import org.springframework.data.redis.core.zsetoperations; import org.springframework.data.redis.serializer.jdkserializationrediserializer; import org.springframework.data.redis.serializer.stringredisserializer; @configurationpublic class readisconfig { / ** * readisconnectionfactory * / @autowired readisconnection factory readisconnection factory; / ** * redistemplate 객체를 인스턴스화 * * @return */ @bean public redistemplate <string, object> function> functureDainRedistemplate () {redistemplate <string, object> redistemplate = new redistemplate <> (); initDomainRedistEmplate (redistemplate, readisconnectionfactory); redistemplate를 반환합니다. } / ** * 데이터 스토리지의 직렬화 방법을 redis로 설정 * * @param redistemplate * @param factory * / private void initdomainRedistemplate (redistemplate <string, object> redistemplate, readisconnection factory factory) {redistemplate.setKeysErializer (new StringSredisserializer ()); redistemplate.sethashkeyserializer (new StringRedisserializer ()); redistemplate.sethashValueserializer (new jdkserializationredisserializer ()); redistemplate.setValueserializer (new Jdkserializationredisserializer ()); redistemplate.setConnectionFactory (Factory); } / ** * Instanced HashoPerations 객체, 해시 유형 조작 * * @param redistemplate * @bean public hashoperations <string, string, object> hashoperations (redistemplate <string, Object> redistemplate) {return redistemplate.opsforhash (); } / ** * Instanct ValueOperations 객체, 문자열 작동 * * @param redistemplate * @return * / @bean public valueOperations <string, object> valueOperations (redistemplate <string, Object> redistemplate) {return redistemplate.opsOrvalue (); } / ** * ListOperations 개체를 인스턴스화하면 목록 작업을 사용할 수 있습니다 * @param redistemplate * @return * / @bean public listoperations <string, object> listOperations (redistemplate <string, object> redistemplate) {return redistemplate.opSforList (); } / ** * SetOperations 개체를 인스턴스화하면 설정 작업 * @param redistemplate * @return * / @bean public setoperations <string, object> setOperations (redistemplate <string, object> redistemplate) {return redistemplate.opsforset (); } / ** * ZSETOPERATIONS 객체를 인스턴스화하면 ZSET 작업 * * @Param RedistemPlate * @return * / @Bean Public ZSetOperations <String, Object> ZsetOperations (RedistemPlate <String, Object> RedistEmplate) {return redistemplate.opsforzset (); }}비즈니스 계층에서 Redis를 사용합니다
@autowired redistemplate <string, object> readiscachetemplate;
사용하는 동안 Redistemplate 객체는 Autowired에 의해 주입되었습니다.
요약
위는이 기사의 전체 내용입니다. 이 기사의 내용에 모든 사람의 연구 나 작업에 대한 특정 참조 가치가 있기를 바랍니다. 궁금한 점이 있으면 의사 소통을 위해 메시지를 남길 수 있습니다. Wulin.com을 지원 해주셔서 감사합니다.