-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Migration from 3.x to 4.x
lettuce 4.0 introduces a few breaking changes. If you want to upgrade to 4.x you need to adopt these changes.
The result type of readOnly and readWrite were changed from String to RedisFuture<String>. The state within the connection updates as soon as the commands complete. You are now able to subscribe to the futures to listen for completion.
lettuce introduces Stateful Connections to separate connections from API’s. With 4.0 all Redis…Connection interfaces are deprecated and will be removed in future versions. Stateful connections provide access to sync, async and reactive API’s by providing sync(), async() and reactive() methods. The following connect() methods changed in order to provide access to stateful connections:
-
RedisClient.connectprovides aStatefulRedisConnection -
RedisClient.connectPubSubprovides aStatefulRedisPubSubConnection
You can find more about all new API including the advanced Redis Cluster API in the release notes.
lettuce 3.x Code for obtaining a sync API
RedisClient client = new RedisClient("host");
RedisConnection<String, String> syncConnection = client.connect();lettuce 4.0 Code for obtaining a sync API
RedisClient client = new RedisClient("host");
StatefulRedisConnection<String, String> connection = client.connect();
// deprecated API
RedisConnection<String, String> syncConnection = connection.sync();
// commands API
RedisCommands<String, String> syncApi = connection.sync();lettuce 3.x Code for obtaining an async pub/sub API
RedisClient client = new RedisClient("host");
RedisPubSubConnection<String, String> syncConnection = client.connectPubSub();lettuce 4.0 Code for obtaining an async pub/sub API
RedisClient client = new RedisClient("host");
StatefulRedisPubSubConnection<String, String> connection = client.connectPubSub();
// deprecated API
RedisPubSubConnection<String, String> asyncConnection = connection.async();
// commands API
RedisPubSubAsyncCommands<String, String> asyncApi = connection.sync();RedisCodec was in 3.x, an abstract class. This changed with 4.0 to an interface and a consistent return type. The RedisCodec interface accepts and returns ByteBuffer`s instead of `byte[]. A ByteBuffer is not opinionated about the source of the underlying bytes. The byte[] interface required the user to provide an array with the exact data for interchange. So if you have an array where you want to use only a subset, you’re required to create a new instance of a byte array and copy the data. The same applies if you have a different byte source (e.g. netty’s ByteBuf or an NIO ByteBuffer). The `ByteBuffer`s for decoding are pointers to the underlying data. `ByteBuffer`s for encoding data can be either pure pointers or allocated memory. lettuce does not free any memory (such as pooled buffers).
Code example for a byte[] codec with lettuce 3.x:
public byte[] encodeKey(byte[] key) {
return key;
}Code example for a byte[] codec with lettuce 4.x:
public ByteBuffer encodeKey(byte[] key) {
return ByteBuffer.wrap(value);
}CommandOutput is relocated from com.lambdaworks.redis.protocol to com.lambdaworks.redis.output. Update your imports.
SetArgs is relocated from com.lambdaworks.redis.protocol to com.lambdaworks.redis Update your imports.
RedisFuture`s are based on `CompleteableFuture and throw exceptions when accessing the value using get() if any exceptions occurred. The future is now compatible, and Exceptions walk down the `CompletionStage`s.
These changes are optional and can help to improve your code.
All connections are AutoCloseable so you can handle connections using try-with-resources.
-
All
Redis…Connectioninterfaces are deprecated and will be removed in future versions. TheRedisCommandsinterface extendsRedisConnectionuntil the connection interfaces will be removed. -
3.x package:
com.lambdaworks.redis -
4.x package:
com.lambdaworks.redis.api.sync
New command interfaces:
-
RedisCommands
-
RedisClusterCommands
-
BaseRedisComands
-
RedisHashCommands
-
RedisHLLCommands
-
RedisKeyCommands
-
RedisListCommands
-
RedisScriptingCommands
-
RedisServerCommands
-
RedisSetCommands
-
RedisSortedSetCommands
-
RedisStringsCommands
-
RedisTransactionalCommands
-
RedisPubSubCommands
-
All
Redis…AsyncConnectioninterfaces are deprecated and will be removed in future versions. TheRedisAsyncCommandsinterface extendsRedisAsyncConnectionuntil the connection interfaces will be removed. -
3.x package:
com.lambdaworks.redis -
4.x package:
com.lambdaworks.redis.api.async
New command interfaces:
-
RedisAsyncCommands
-
RedisClusterAsyncCommands
-
BaseRedisAsyncCommands
-
RedisHashAsyncCommands
-
RedisHLLAsyncCommands
-
RedisKeyAsyncCommands
-
RedisListAsyncCommands
-
RedisScriptingAsyncCommands
-
RedisSentinelAsyncCommands
-
RedisServerAsyncCommands
-
RedisSetAsyncCommands
-
RedisSortedSetAsyncCommands
-
RedisStringAsyncCommands
-
RedisTransactionalAsyncCommands
-
RedisPubSubAsyncCommands
Lettuce documentation was moved to https://redis.github.io/lettuce/overview/
Intro
Getting started
- Getting started
- Redis URI and connection details
- Basic usage
- Asynchronous API
- Reactive API
- Publish/Subscribe
- Transactions/Multi
- Scripting and Functions
- Redis Command Interfaces
- FAQ
HA and Sharding
Advanced usage
- Configuring Client resources
- Client Options
- Dynamic Command Interfaces
- SSL Connections
- Native Transports
- Unix Domain Sockets
- Streaming API
- Events
- Command Latency Metrics
- Tracing
- Stateful Connections
- Pipelining/Flushing
- Connection Pooling
- Graal Native Image
- Custom commands
Integration and Extension
Internals