Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

select db will have a error #62

Open
robben009 opened this issue Dec 23, 2021 · 1 comment
Open

select db will have a error #62

robben009 opened this issue Dec 23, 2021 · 1 comment

Comments

@robben009
Copy link

robben009 commented Dec 23, 2021

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 robben009 changed the title Unable to switch DB select db will have a error Dec 23, 2021
@sazzad16
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants