1. windows에 redis 설치
ㅇ 다운로드 (windows)
ㅇ 압축 해제 후 배치
C:\Redis
\redis-2.4.5-win32-win64\64bit\*.* -> C:\Redis
ㅇ 환경 파일 수정
https://raw.github.com/antirez/redis/2.6/redis.conf (2.6 config)
daemonize yes
bind 127.0.0.1
loglevel notice
dir C:\Redis\DB\
logfile C:\Redis\DB\log\redis.log
requirepass deweyhong
appendonly yes => 기록을 재 로딩
ㅇ 서버 실행 : redis-server redis.conf
ㅇ 테스트
redis-cli.exe -h 127.0.0.1 -p 6379
set redis "Hello, Redis!"
get redis
2. Spring redis Cache 설정
ㅇ 관련 jar
spring-data-redis
commons-logging
commons-pool
jackson-core-asl
jackson-mapper-asl
jedis
org.springframework.beans
org.springframework.context
org.springframework.core
org.springframework.expression
spring-tx
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:c="http://www.springframework.org/schema/c"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
<!-- turn on declarative caching -->
<cache:annotation-driven />
<!-- declare Redis Cache Manager -->
<bean id="cacheManager" class="org.springframework.data.redis.cache.RedisCacheManager"
c:template-ref="redisTemplate" />
<bean id="connectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="hostName" value="localhost" />
<property name="port" value="7379" />
<property name="password" value="deweyhong" />
</bean>
<bean id="stringRedisSerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer" />
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate" lazy-init="false">
<property name="connectionFactory" ref="connectionFactory" />
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
</bean>
@Autowired
private org.springframework.cache.CacheManager cacheManager;
Cache cache = cacheManager.getCache("codeCache");
cache.put(buildCodeCacheKey(KEY_COMM_GRP_CDS), groupValueList);
cache.get(cacheKey).get();
Comments
Post a Comment