redis / lettuce

Advanced Java Redis client for thread-safe sync, async, and reactive usage. Supports Cluster, Sentinel, Pipelining, and codecs.
https://lettuce.io
MIT License
5.35k stars 960 forks source link

Question/Feature Request: Transactions over keys with different codecs #2608

Open SHildebrandt opened 7 months ago

SHildebrandt commented 7 months ago

First of all, thanks a lot for this library. It's really fun to work with it, especially compared to Jedis.

I need to update several keys within one transaction, some of which are strings and some are compressed byte arrays. Is this possible?

As far as I understand, I usually have to create two different StatefulRedisConnections for the different codecs, but I cannot start a transaction over both of them.

Simplified Example:

RedisClient redisClient = RedisClient.create("...");
RedisCommands<String, String> stringCommands = redisClient.connect().sync();
RedisCommands<byte[], byte[]> byteArrayCommands = redisClient.connect(CompressionCodec.valueCompressor(ByteArrayCodec.INSTANCE, GZIP)).sync();

// problem begins here, where I need to start two transactions
stringCommands.multi();
byteArrayCommands.multi();
stringCommands.set("Hello", "World");
byteArrayCommands.set("Hello2".getBytes(StandardCharsets.UTF_8), "World2".getBytes(StandardCharsets.UTF_8));

// I would need one exec here, otherwise there is some period of time where the string keys are updated,
// but the byte array keys are not (or the other way round)
stringCommands.exec();
byteArrayCommands.exec();

Is there a dedicated way to deal with this problem in Lettuce? I tried to write my own RedisCodec implementation to combine StringCodec and ByteArrayCodec, but that does not seem to be trivial, since I don't know what kind of key I have in the decodeValue function.

SHildebrandt commented 7 months ago

Just realized that this is probably dependent on (i.e. would be solved with) this feature: https://github.com/lettuce-io/lettuce-core/issues/632

I suspect I will have to go back to Jedis for now. :(

vibbix commented 5 months ago

This would be great. The performance from Lettuce & Netty is amazing, but it gets pretty bogged down by workarounds for this. For Redis usages with many value types, it makes connection pooling impossible.

When everything has to cast from ByteBuffer / String into the target class, the huge amount of malloc & GC calls really bring performance down.