eleme / corvus

A fast and lightweight Redis Cluster Proxy for Redis 3.0
MIT License
790 stars 143 forks source link

Can I use Lettuce with corvus? Maybe there are some bugs! #155

Open AuroraTwinkle opened 2 years ago

AuroraTwinkle commented 2 years ago

client : Lettuce,a aync client base netty nio

corvus version : a Secondary development version base eleme/corvus master(update to date) redis: redis cluster

problem: when run my code some time, i got some exceptions like this:

image

tcpdump:

I find some things wrong by tcpdump.

  1. the corvus response do not follow the RESP. like *2 $-1 should be *2 $-1 $-1
  2. the response order is incorrect , so cannot be matched (request) one by one

just like this photos: image image

reproducer code:


public class RedisOptionV2 {
    private static RedisAsyncCommands<String, String> ASYNC;
    private static boolean flag = false;
    private static AtomicLong index = new AtomicLong(0);

    static {
        RedisURI redisURI = RedisURI.create("corvus ip",  6666);
        RedisClient redisClient = RedisClient.create(redisURI);
        StatefulRedisConnection<String, String> connection = redisClient.connect();
        ASYNC = connection.async();
    }

    @PostConstruct
    void init() {
        MyExecutorService.schedule(this::lettuceTestTask, 30, TimeUnit.SECONDS);
    }

    private void lettuceTestTask() {
        for (long i = 0; i < Long.MAX_VALUE; i++) {
            try {
                MyExecutorService.submit(this::lettuceDemo);
            } catch (Throwable t) {
                t.printStackTrace();
            }
        }
    }

    public void lettuceDemo() {
        try {
            List<String> keys = new ArrayList<>();
            keys.add("debugLettuceKey" + index.getAndIncrement());
            if (flag) {
                keys.add("debugLettuceKey2");
                flag = false;
            } else {
                flag = true;
            }

            //core code
            RedisFuture<List<KeyValue<String, String>>> future = ASYNC.mget(keys.toArray(new String[0]));
            future.whenCompleteAsync((e, t) -> {
                if (t == null) {
                    log.info("{} res: {}", keys, e);
                } else {
                    log.error("调用redis失败, {} res : {}", keys, e, t);
                }
            }, MyExecutorService.getExecutorService());

        } catch (Throwable t) {
            log.error("fail to execute task", t);
        }
    }
}

Looking forward to reply!Thanks

caojiajun commented 1 year ago

you can try camellia-redis-proxy