Skip to content

Encoding gets lost in read-after-write #37

@sangupta

Description

@sangupta

The Java driver for RedisJSON corrupts encoding when writing a value and then reading it again. Below is the code to reproduce the issue.

// the encoded string
String input = "Commodore’s Assemblers: Part 1: MOS Cross-Assembler";

// test with JReJSON
JReJSON jj = new JReJSON("localhost", 6379);
jj.set("test-json", input);
String o1 = jj.get("test-json");

System.out.println(o1.equals(input)); // prints false on OpenJDK 11

Note the issue is not exhibited when using Spring's RedisTemplate:

// initialize connection factory
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration("localhost", 6379);
JedisConnectionFactory jcf = new JedisConnectionFactory(redisStandaloneConfiguration);

// initialize redis template
RedisTemplate<String, Object> template = new RedisTemplate<>();

template.setConnectionFactory(this.redisConnectionFactory());
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new StringRedisSerializer());

// test
template.opsForValue().set("test-val", input);
String o2 = template.opsForValue().get("test-val");

System.out.println(o2.equals(input)); // prints true 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions