티스토리 뷰

1. build.gradle

compile "org.springframework.data:spring-data-redis:1.8.23.RELEASE"
compile "redis.clients:jedis:2.9.3"



2. 빈 설정 추가

<beans:bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
  <beans:property name="usePool" value="true"></beans:property>
  <beans:property name="hostName" value="123.45.0.67"></beans:property><!-- 레디스 호스트IP -->
  <beans:property name="password" value="password1234"></beans:property> <!-- 레디스 서버 비밀번호 -->
</beans:bean>
<beans:bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
  <beans:property name="connectionFactory" ref="jedisConnectionFactory"></beans:property>
</beans:bean>

 

 

3. Controller.java 사용 예제

import org.springframework.data.redis.core.RedisTemplate;

@Autowired
private RedisTemplate<String, Object> redisTemplate;


// 데이터 저장
HashMap<String, Object> dateMap = new HashMap<String, Object>();
dateMap.put("email", "aaa@abc.co.kr");
dateMap.put("mobile", "12341234");
redisTemplate.opsForHash().putAll("userInfo", dateMap);


// 데이터 조회
String email = (String) redisTemplate.opsForHash().get("userInfo", "email");
String mobile = (String) redisTemplate.opsForHash().get("userInfo", "mobile");

 

댓글
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함