Skip to content

Commit

Permalink
3.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Baoyi Chen committed Mar 14, 2021
1 parent 20f3f57 commit 6439524
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 27 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### 3.6.0
### 3.5.3

`DumpRdbValueVisitor` support downgrade from redis 6.2 to 2.8.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ redis 2.6 - 6.2
<dependency>
<groupId>com.moilioncircle</groupId>
<artifactId>redis-replicator</artifactId>
<version>3.6.0</version>
<version>3.5.3</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion README.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ redis 2.6 - 6.2
<dependency>
<groupId>com.moilioncircle</groupId>
<artifactId>redis-replicator</artifactId>
<version>3.6.0</version>
<version>3.5.3</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<groupId>com.moilioncircle</groupId>
<artifactId>redis-replicator</artifactId>
<version>3.6.0</version>
<version>3.5.3</version>

<name>redis-replicator</name>
<description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,39 +36,39 @@

/**
* @author Leon Chen
* @since 3.6.0
* @since 3.5.3
*/
public class BaseRdbEncoder {

/**
* @since 3.6.0
* @param time time
* @param out out
* @throws IOException IOException
* @see BaseRdbParser#rdbLoadTime()
* @see BaseRdbParser#rdbLoadTime()
* @since 3.5.3
*/
public void rdbSaveTime(int time, OutputStream out) throws IOException {
out.write(ByteBuffer.allocate(Integer.BYTES).order(LITTLE_ENDIAN).putInt(time).array());
}

/**
* @since 3.6.0
* @since 3.5.3
* @param timestamp timestamp
* @param out out
* @throws IOException IOException
* @see BaseRdbParser#rdbLoadMillisecondTime()
* @see BaseRdbParser#rdbLoadMillisecondTime()
*/
public void rdbSaveMillisecondTime(long timestamp, OutputStream out) throws IOException {
out.write(ByteBuffer.allocate(Long.BYTES).order(LITTLE_ENDIAN).putLong(timestamp).array());
}

/**
* @since 3.6.0
* @since 3.5.3
* @param len len
* @param out out
* @return length
* @throws IOException IOException
* @see BaseRdbParser#rdbLoadLen()
* @see BaseRdbParser#rdbLoadLen()
*/
public int rdbSaveLen(long len, OutputStream out) throws IOException {
if (len < (1 << 6)) {
Expand All @@ -93,7 +93,7 @@ public int rdbSaveLen(long len, OutputStream out) throws IOException {
}

/**
* @since 3.6.0
* @since 3.5.3
* @param len len
* @return byte array
* @throws IOException IOException
Expand All @@ -115,11 +115,11 @@ public byte[] rdbSaveLen(long len) throws IOException {
}

/**
* @since 3.6.0
* @since 3.5.3
* @param value value
* @param out out
* @throws IOException IOException
* @see BaseRdbParser#rdbLoadDoubleValue()
* @see BaseRdbParser#rdbLoadDoubleValue()
*/
public void rdbSaveDoubleValue(double value, OutputStream out) throws IOException {
if (value == Double.NEGATIVE_INFINITY) {
Expand All @@ -141,33 +141,33 @@ public void rdbSaveDoubleValue(double value, OutputStream out) throws IOExceptio
}

/**
* @since 3.6.0
* @since 3.5.3
* @param value value
* @param out out
* @throws IOException IOException
* @see BaseRdbParser#rdbLoadBinaryFloatValue()
* @see BaseRdbParser#rdbLoadBinaryFloatValue()
*/
public void rdbSaveBinaryFloatValue(float value, OutputStream out) throws IOException {
out.write(ByteBuffer.allocate(Long.BYTES).order(LITTLE_ENDIAN).putLong(floatToIntBits(value)).array());
}

/**
* @since 3.6.0
* @since 3.5.3
* @param value value
* @param out out
* @throws IOException IOException
* @see BaseRdbParser#rdbLoadBinaryDoubleValue()
* @see BaseRdbParser#rdbLoadBinaryDoubleValue()
*/
public void rdbSaveBinaryDoubleValue(double value, OutputStream out) throws IOException {
out.write(ByteBuffer.allocate(Long.BYTES).order(LITTLE_ENDIAN).putLong(doubleToLongBits(value)).array());
}

/**
* @since 3.6.0
* @since 3.5.3
* @param bytes input
* @param out out
* @throws IOException IOException
* @see BaseRdbParser#rdbLoadEncodedStringObject()
* @see BaseRdbParser#rdbLoadEncodedStringObject()
*/
public void rdbSaveEncodedStringObject(ByteArray bytes, OutputStream out) throws IOException {
int type = (RDB_ENCVAL << 6) | RDB_ENC_LZF;
Expand All @@ -180,11 +180,11 @@ public void rdbSaveEncodedStringObject(ByteArray bytes, OutputStream out) throws
}

/**
* @since 3.6.0
* @since 3.5.3
* @param bytes bytes
* @param out out
* @throws IOException IOException
* @see BaseRdbParser#rdbGenericLoadStringObject(int)
* @see BaseRdbParser#rdbGenericLoadStringObject(int)
*/
public void rdbGenericSaveStringObject(ByteArray bytes, OutputStream out) throws IOException {
if (bytes.length() > 20) {
Expand All @@ -195,11 +195,11 @@ public void rdbGenericSaveStringObject(ByteArray bytes, OutputStream out) throws
}

/**
* @since 3.6.0
* @since 3.5.3
* @param bytes bytes
* @param out out
* @throws IOException IOException
* @see BaseRdbParser#rdbLoadPlainStringObject()
* @see BaseRdbParser#rdbLoadPlainStringObject()
*/
public void rdbSavePlainStringObject(ByteArray bytes, OutputStream out) throws IOException {
rdbSaveLen(bytes.length(), out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
import static com.moilioncircle.redis.replicator.Constants.RDB_LOAD_ENC;
import static java.lang.Double.NEGATIVE_INFINITY;
import static java.lang.Double.POSITIVE_INFINITY;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand All @@ -32,7 +33,7 @@

/**
* @author Leon Chen
* @since 3.6.0
* @since 3.5.3
*/
public class BaseRdbEncoderTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,69 @@ public void onEvent(Replicator replicator, Event event) {
}
});
replicator.open();

assertEquals(expected.size(), actual.size());
for (int i = 0; i < expected.size(); i++) {
assertArrayEquals(expected.get(i).getElement(), actual.get(i).getElement());
assertEquals(expected.get(i).getScore(), actual.get(i).getScore(), 0.000000001);
}
}

@Test
@SuppressWarnings("resource")
public void test5() throws IOException {
Replicator replicator = new RedisReplicator(DumpRdbVisitorTest.class.
getClassLoader().getResourceAsStream("dumpV9.rdb")
, FileType.RDB, Configuration.defaultSetting());
List<byte[]> expected = new ArrayList<>();
replicator.addEventListener(new EventListener() {
@Override
public void onEvent(Replicator replicator, Event event) {
if (event instanceof KeyStringValueList) {
KeyStringValueList kv = (KeyStringValueList) event;
if (kv.getValueRdbType() == RDB_TYPE_LIST_QUICKLIST) {
for (byte[] element : kv.getValue()) {
expected.add(element);
}
}
}
}
});
replicator.open();

replicator = new RedisReplicator(DumpRdbVisitorTest.class.
getClassLoader().getResourceAsStream("dumpV9.rdb")
, FileType.RDB, Configuration.defaultSetting());
List<byte[]> actual = new ArrayList<>();
replicator.setRdbVisitor(new DumpRdbVisitor(replicator, 6));
replicator.addEventListener(new EventListener() {
@Override
public void onEvent(Replicator replicator, Event event) {
if (!(event instanceof DumpKeyValuePair)) return;
DumpKeyValuePair kv = (DumpKeyValuePair) event;
String key = new String(kv.getKey());
if (key.equals("list1") && kv.getValueRdbType() == RDB_TYPE_LIST) {
DumpValueParser parser = new DefaultDumpValueParser(replicator);
parser.parse(kv, new EventListener() {
@Override
public void onEvent(Replicator replicator, Event event) {
KeyStringValueList kv = (KeyStringValueList) event;
for (byte[] element : kv.getValue()) {
actual.add(element);
}
}
});
}
}
});
replicator.open();

assertEquals(expected.size(), actual.size());
for (int i = 0; i < expected.size(); i++) {
assertArrayEquals(expected.get(i), actual.get(i));
}
}

public void template(String filename) {
try {
@SuppressWarnings("resource")
Expand Down
Binary file added src/test/resources/dumpV9.rdb
Binary file not shown.

0 comments on commit 6439524

Please sign in to comment.