dependencies { implementation 'io.vertx:vertx-redis-client:3.9.7' } <dependency> <groupId>io.vertx</groupId> <artifactId>vertx-redis-client</artifactId> <version>3.9.7</version> </dependency> import io.vertx.core.Vertx; import io.vertx.redis.client.Redis; import io.vertx.redis.client.RedisOptions; public class RedisClientExample { public static void main(String[] args) { Vertx vertx = Vertx.vertx(); RedisOptions options = new RedisOptions() Redis redis = Redis.createClient(vertx, options); } } import io.vertx.core.Vertx; import io.vertx.redis.client.Redis; import io.vertx.redis.client.RedisAPI; import io.vertx.redis.client.Response; import io.vertx.redis.client.ResponseType; public class RedisClientExample { public static void main(String[] args) { Vertx vertx = Vertx.vertx(); Redis redis = Redis.createClient(vertx, options); RedisAPI redisAPI = RedisAPI.api(redis); redisAPI.set(List.of("myKey", "myValue"), setResponse -> { if (setResponse != null && setResponse.type() == ResponseType.OK) { } else { } }); redisAPI.get(List.of("myKey"), getResponse -> { if (getResponse != null && getResponse.type() == ResponseType.BULK) { String value = getResponse.toString(); } else { } }); redisAPI.del(List.of("myKey"), delResponse -> { if (delResponse != null && delResponse.type() == ResponseType.INTEGER) { long deletedKeys = delResponse.toInteger(); } else { } }); } }


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