Because of some errors, Our redis mixes some different serialized data.
Ex:
Some data use StringCodec. Some Data use JsonJacksonCodec.
In this case, when using mget get data, if the getStringValue("test3") return test3 getStringValue("test3") return test1 4.0.10 3.10.7Expected behavior
Actual behavior
Steps to reproduce or test case
private Redisson redissonClient;
@Before
public void setUp() {
Config config = new Config();
config.setThreads(1);
config.setNettyThreads(1);
config.useSingleServer()
.setConnectionMinimumIdleSize(1)
.setConnectionPoolSize(1)
.setAddress("redis://127.0.0.1:6379");
redissonClient = (Redisson) Redisson.create(config);
}
@Test
public void test_sanity_data() throws Exception {
setJSONValue("test1", new Foo("test1"));
setStringValue("test2", new Foo("test2"));
setJSONValue("test3", new Foo("test3"));
try {
RBuckets buckets = redissonClient.getBuckets(new JsonJacksonCodec());
buckets.get("test2", "test1");
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(getStringValue("test3")); // will result test1
}
public void setJSONValue(String key, Object t) {
RBucket<Object> test1 = redissonClient.getBucket(key, new JsonJacksonCodec());
test1.set(t);
}
public void setStringValue(String key, Object t) {
RBucket<Object> test1 = redissonClient.getBucket(key, new StringCodec());
test1.set(t);
}
public Object getStringValue(String key) {
RBucket<Object> test1 = redissonClient.getBucket(key, new JsonJacksonCodec());
return test1.get();
}
@AllArgsConstructor
@NoArgsConstructor
@Data
static class Foo {
String bar;
}
@After
public void clear() {
redissonClient.shutdown();
}
Redis version
Redisson version
Redisson configuration
config.setThreads(1);
config.setNettyThreads(1);
config.useSingleServer()
.setConnectionMinimumIdleSize(1)
.setConnectionPoolSize(1)
.setAddress("redis://127.0.0.1:6379");
private void decodeList(ByteBuf in, CommandData<Object, Object> data, List<Object> parts,
Channel channel, long size, List<Object> respParts, boolean skipConvertor, List<CommandData<?, ?>> commandsData)
throws IOException {
...
// when error take place , shall we skip the data or catch the exception?
for (int i = respParts.size(); i < size; i++) {
decode(in, data, respParts, channel, skipConvertor, null);
}
...
Fixed! Thanks for report
@mm23504570 The best way to deal with mixed codec is to use RBatch to fetch data instead of mget. As a matter of fact, in most cases, RBatch is preferred than mget unless atomicity is required.
@jackygurui Thanks.
馃槪 Our program does not allow mixed codec. This encoding problem occurs because of bugs in our program.
Most helpful comment
Fixed! Thanks for report