Skip to content

select db will have a error #62

@robben009

Description

@robben009

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?

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