Maven: <dependency> <groupId>io.lettuce</groupId> <artifactId>lettuce-core</artifactId> </dependency> Gradle: groovy RedisURI redisUri = RedisURI.builder() .withHost("hostname") .withPort(6379) .withPassword("password") .build(); RedisClient redisClient = RedisClient.create(redisUri); StatefulRedisConnection<String, String> connection = redisClient.connect(); RedisCommands<String, String> syncCommands = connection.sync(); syncCommands.set("key", "value"); String value = syncCommands.get("key"); System.out.println("Value: " + value); RedisAsyncCommands<String, String> asyncCommands = connection.async(); RedisFuture<String> future = asyncCommands.get("key"); future.thenAccept(value -> System.out.println("Value: " + value)); RedisReactiveCommands<String, String> reactiveCommands = connection.reactive(); Mono<String> valueMono = reactiveCommands.get("key"); valueMono.subscribe(value -> System.out.println("Value: " + value)); connection.close(); redisClient.shutdown();


上一篇:
下一篇:
切换中文