JRedisJSON icon indicating copy to clipboard operation
JRedisJSON copied to clipboard

select db will have a error

Open robben009 opened this issue 2 years ago • 1 comments

config:

spring:
  redis:
    database: 6
    host: ${extraEnvHost}
    port: 6379
    password: ${redis.pwd}
    pool:
      minIdle: 1
      maxIdle: 10
      maxWait: 3
      maxActive: 8

@Component
public class JedisCompent {
    @Autowired
    private RedisConnectionFactory connectionFactory;
    @Autowired
    private Jedis jedis;

    @Bean
    public Jedis jedis(){
        Field jedisField = ReflectionUtils.findField(JedisConnection.class, "jedis");
        ReflectionUtils.makeAccessible(jedisField);
        Jedis jedis = (Jedis) ReflectionUtils.getField(jedisField, connectionFactory.getConnection());
        return jedis;
    }

    @Bean
    public JReJSON jReJSON(){
        return new JReJSON(jedis);
    }
}

@Slf4j
@RestController
@RequestMapping("/redis")
public class ExController {
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private JReJSON jReJSON;
    @Autowired
    private Jedis jedis;

    @GetMapping(value = "/useRedisJSON")
    public int useRedisJSON(){
        long stime = SystemClock.now();

        jedis.set("kkkk","asdfasdf");

        String testJsonObjectName = "robben";
        jReJSON.set(testJsonObjectName,new Object());  //success in db6
        jReJSON.set(testJsonObjectName,21,new Path(".age"));   //error:   ERR new objects must be created at the root
        return 0;
    }
}

As shown in the figure above,Sometimes it fails!

Sometimes in db6 have a "robben" object is "{}" ,but After multiple executions,in db0 will get a right result({"age":21}). why?

if my don't set db in application.yml,All correct!

Is it because the jedis I created did not use the connection pool?

robben009 avatar Dec 23 '21 08:12 robben009

@robben009 Your jedis connections are being managed by spring-data-redis. That may be a better place to ask.

sazzad16 avatar Dec 23 '21 09:12 sazzad16