검색결과 리스트
redis test에 해당되는 글 1건
- 2016.07.12 [Redis-02] Redis 2.8 테스트 Java
글
1. 데이터 입력중 마스터 DB가 중지댈때 데이터 보장되는 지 확인
1.1 소스코드
import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import org.apache.commons.pool2.impl.GenericObjectPoolConfig; import org.springframework.data.redis.RedisConnectionFailureException; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisSentinelPool; import redis.clients.jedis.exceptions.JedisConnectionException; /** * @Auth Hong Seungkyun * @Description * <pre></pre> */ public class RedisTest { public static void main(String[] args) throws Exception { Set<String> sentinelIps = new HashSet<>(); sentinelIps.add("175.207.8.166:26379"); sentinelIps.add("175.207.8.167:26379"); sentinelIps.add("175.207.8.168:26379"); GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); JedisSentinelPool jedisSentinelPool = new JedisSentinelPool("mymaster", sentinelIps, poolConfig, 5000, "1020"); Jedis jedis1 = jedisSentinelPool.getResource(); String[] keys = new String[100]; //삭제처리 StringBuffer delkey = new StringBuffer(); for (int i = 0; i < 100; i++) { keys[i] ="Test_"+i; } jedis1.del(keys); for (int i = 0; i < 100; i++) { try { RedisTest.setData(jedisSentinelPool, "Test_"+i, "value_"+i); System.out.println("input > key : Test_"+i+" , value : value_"+i); } catch (Exception e) { System.out.println(e.getMessage()); System.out.println("에러 발생"); } Thread.sleep(500); } for (int i = 0; i < 100; i++) { Jedis jedis = jedisSentinelPool.getResource(); try { String value = jedis.get("Test_" + i); System.out.println("output > key : Test_"+i+" , value :"+value); } catch (RedisConnectionFailureException e) { e.printStackTrace(); jedisSentinelPool.returnBrokenResource(jedis); } finally { try { jedisSentinelPool.returnResource(jedis); } catch (JedisConnectionException e) { System.out.println(e); } } } /* * JedisPool jedisPool = new JedisPool(new JedisPoolConfig(), "175.207.8.166",6379,0,"1020"); * Jedis jedis = jedisPool.getResource(); * try { * jedis.set("foo", "client_test"); * } catch (Exception e) { * System.out.println(e.getMessage()); * } * System.out.println(">>>>> : "+jedis.get("foo")); */ } public static void setData(JedisSentinelPool jedisSentinelPool, String key , String value ){ Jedis jedis =null; try { jedis = jedisSentinelPool.getResource(); jedis.set(key, value); } catch (RedisConnectionFailureException e) { System.out.println(e); System.out.println("헐헐2!!"); jedisSentinelPool.returnBrokenResource(jedis); } finally { try { jedisSentinelPool.returnResource(jedis); } catch (JedisConnectionException e) { System.out.println(e); System.out.println("헐헐3!!"); } } } } |
1.2 서버 콘솔
입력 도중 # redis-cli -a 1020 shutdown 명령 입력 |
1.3 데이터 처리 로그
1월 27, 2015 11:16:22 오전 redis.clients.jedis.JedisSentinelPool initSentinels 정보: Trying to find master from available Sentinels... 1월 27, 2015 11:16:23 오전 redis.clients.jedis.JedisSentinelPool initSentinels 정보: Redis master running at 175.207.8.167:6379, starting Sentinel listeners... 1월 27, 2015 11:16:23 오전 redis.clients.jedis.JedisSentinelPool initPool 정보: Created JedisPool to master at 175.207.8.167:6379 input > key : Test_0 , value : value_0 ....... input > key : Test_16 , value : value_16 input > key : Test_17 , value : value_17 ==>> 에러 최초 발생 Unexpected end of stream. 에러 발생 redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketException: Software caused connection abort: socket write error 헐헐3!! java.net.SocketException: Software caused connection abort: socket write error 에러 발생 Could not get a resource from the pool 에러 발생 Could not get a resource from the pool 에러 발생 Could not get a resource from the pool 에러 발생 Could not get a resource from the pool 에러 발생 Could not get a resource from the pool 에러 발생 Could not get a resource from the pool 에러 발생 Could not get a resource from the pool 에러 발생 Could not get a resource from the pool 에러 발생 Could not get a resource from the pool 에러 발생 Could not get a resource from the pool 에러 발생 Could not get a resource from the pool 에러 발생 Could not get a resource from the pool 에러 발생 Could not get a resource from the pool 에러 발생 Could not get a resource from the pool 에러 발생 Could not get a resource from the pool 에러 발생 Could not get a resource from the pool 에러 발생 Could not get a resource from the pool 에러 발생 Could not get a resource from the pool 에러 발생 Could not get a resource from the pool 에러 발생 Could not get a resource from the pool 에러 발생 1월 27, 2015 11:17:03 오전 redis.clients.jedis.JedisSentinelPool initPool 정보: Created JedisPool to master at 175.207.8.168:6379 Could not get a resource from the pool 에러 발생 input > key : Test_41 , value : value_41 ==> 마스터 체이진 정상 입력 input > key : Test_42 , value : value_42 ........ input > key : Test_99 , value : value_99 //데이터 읽기 output > key : Test_0 , value :value_0 output > key : Test_1 , value :value_1 output > key : Test_2 , value :value_2 ........ output > key : Test_17 , value :value_17 output > key : Test_18 , value :null output > key : Test_19 , value :null output > key : Test_20 , value :null ...... output > key : Test_36 , value :null output > key : Test_37 , value :null output > key : Test_38 , value :null output > key : Test_39 , value :null output > key : Test_40 , value :null output > key : Test_41 , value :value_41 output > key : Test_42 , value :value_42 ........ output > key : Test_95 , value :value_95 output > key : Test_96 , value :value_96 output > key : Test_97 , value :value_97 output > key : Test_98 , value :value_98 output > key : Test_99 , value :value_99 |
결론
강제 셧다운시 10초 이후에 시스템이 정상 운영됨 1. 10 초 사이데이터 처리 방안이 필요함 ( 서버 체크 시간 8초로 설정해서 11초후에 정상 처리 시스템 설정 시간보다 다소 시간이 지연됨.) |
참고 싸이트
RECENT COMMENT