From d34e56280ebf85bb42f7f26f0322582870a04d45 Mon Sep 17 00:00:00 2001 From: leon Date: Sat, 29 Jul 2017 09:29:29 +0800 Subject: [PATCH] 2.3.1-release add 3 command ltrim rpoplpush sort fix reconnect bug --- README.md | 8 +++--- README.zh_CN.md | 8 +++--- .../replicator/RedisSocketReplicator.java | 28 ++++++++++++++----- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 233f70ce..83c60a37 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ The following I mentioned `Command` which means `Writable Command` in redis and ## 2.1. Requirements jdk 1.7+ maven-3.2.3+ -redis 2.4 - 4.0 +redis 2.6 - 4.0 ## 2.2. Maven dependency ```java @@ -98,9 +98,9 @@ redis 2.4 - 4.0 | **redis version** |**redis-replicator version** | | ---------------------------- | ---------------------------- | -| \[2.4, 4.0.0\] | \[2.3.0\] | -| \[2.4, 4.0-RC3\] | \[2.1.0, 2.2.0\] | -| \[2.4, 3.2.x\] | \[1.0.18\](not supported) | +| \[2.6, 4.0.0\] | \[2.3.0\] | +| \[2.6, 4.0-RC3\] | \[2.1.0, 2.2.0\] | +| \[2.6, 3.2.x\] | \[1.0.18\](not supported) | # 3. Simple usage diff --git a/README.zh_CN.md b/README.zh_CN.md index 42a18a00..57fe11cb 100644 --- a/README.zh_CN.md +++ b/README.zh_CN.md @@ -82,7 +82,7 @@ Redis Replicator是一款rdb解析以及命令解析的工具. 此工具完整 ## 2.1. 安装前置条件 jdk 1.7+ maven-3.2.3+ -redis 2.4 - 4.0 +redis 2.6 - 4.0 ## 2.2. Maven依赖 ```java @@ -103,9 +103,9 @@ redis 2.4 - 4.0 | **redis 版本** |**redis-replicator 版本** | | ------------------------- | ------------------------- | -| \[2.4, 4.0.0\] | \[2.3.0\] | -| \[2.4, 4.0-RC3\] | \[2.1.0, 2.2.0\] | -| \[2.4, 3.2.x\] | \[1.0.18\](不再提供支持) | +| \[2.6, 4.0.0\] | \[2.3.0\] | +| \[2.6, 4.0-RC3\] | \[2.1.0, 2.2.0\] | +| \[2.6, 3.2.x\] | \[1.0.18\](不再提供支持) | # 3. 简要用法 diff --git a/src/main/java/com/moilioncircle/redis/replicator/RedisSocketReplicator.java b/src/main/java/com/moilioncircle/redis/replicator/RedisSocketReplicator.java index 609a8274..705efd9d 100644 --- a/src/main/java/com/moilioncircle/redis/replicator/RedisSocketReplicator.java +++ b/src/main/java/com/moilioncircle/redis/replicator/RedisSocketReplicator.java @@ -220,16 +220,13 @@ public byte[] handle(long len, RedisInputStream in) throws IOException { //sync command String reply = new String(rawReply, UTF_8); if ("OK".equals(reply)) return; - //redis 2.8+ - if (reply.contains("NOAUTH")) throw new AssertionError(reply); - //redis 2.4 - 2.6 - if (reply.contains("operation not permitted")) throw new AssertionError(reply); throw new IOException("SYNC failed. reason : [" + reply + "]"); } protected void establishConnection() throws IOException { connect(); if (configuration.getAuthPassword() != null) auth(configuration.getAuthPassword()); + sendPing(); sendSlavePort(); sendSlaveIp(); sendSlaveCapa("eof"); @@ -245,10 +242,27 @@ protected void auth(String password) throws IOException { final String reply = new String((byte[]) reply(), UTF_8); logger.info(reply); if ("OK".equals(reply)) return; + if (reply.contains("no password")) { + logger.warn("[AUTH " + password + "] failed. " + reply); + return; + } throw new AssertionError("[AUTH " + password + "] failed. " + reply); } } + protected void sendPing() throws IOException { + if (logger.isInfoEnabled()) { + logger.info("PING"); + } + send("PING".getBytes()); + final String reply = new String((byte[]) reply(), UTF_8); + logger.info(reply); + if ("PONG".equalsIgnoreCase(reply)) return; + if (reply.contains("NOAUTH")) throw new AssertionError(reply); + if (reply.contains("operation not permitted")) throw new AssertionError("-NOAUTH Authentication required."); + logger.warn("[PING] failed. " + reply); + } + protected void sendSlavePort() throws IOException { //REPLCONF listening-prot ${port} if (logger.isInfoEnabled()) { @@ -259,7 +273,7 @@ protected void sendSlavePort() throws IOException { logger.info(reply); if ("OK".equals(reply)) return; if (logger.isWarnEnabled()) { - logger.warn("[REPLCONF listening-port " + socket.getLocalPort() + "] failed." + reply); + logger.warn("[REPLCONF listening-port " + socket.getLocalPort() + "] failed. " + reply); } } @@ -274,7 +288,7 @@ protected void sendSlaveIp() throws IOException { if ("OK".equals(reply)) return; //redis 3.2+ if (logger.isWarnEnabled()) { - logger.warn("[REPLCONF ip-address " + socket.getLocalAddress().getHostAddress() + "] failed." + reply); + logger.warn("[REPLCONF ip-address " + socket.getLocalAddress().getHostAddress() + "] failed. " + reply); } } @@ -288,7 +302,7 @@ protected void sendSlaveCapa(String cmd) throws IOException { logger.info(reply); if ("OK".equals(reply)) return; if (logger.isWarnEnabled()) { - logger.warn("[REPLCONF capa " + cmd + "] failed." + reply); + logger.warn("[REPLCONF capa " + cmd + "] failed. " + reply); } }