项目地址: https://github.com/redis/jedis
Jedis is a blazingly small and sane Redis java client.
Jedis was conceived to be EASY to use.
Jedis is fully compatible with redis 2.8.x, 3.x.x and above*.
Jedis 是Redis的Java实现的客户端。支持基本的数据类型如:String、Hash、List、Set、Sorted Set。
特点:使用阻塞的I/O,方法调用同步,程序流需要等到socket处理完I/O才能执行,不支持异步操作。Jedis客户端实例不是线程安全的,需要通过连接池来使用Jedis。
Jedis使用JedisPool pool = new JedisPool(new JedisPoolConfig(), "localhost");
/// Jedis implements Closeable. Hence, the jedis instance will be auto-closed after the last statement.try (Jedis jedis = pool.getResource()) {
/// ... do stuff here ... for example
jedis.set("foo", "bar"); String foobar = jedis.get("foo");
jedis.zadd("sose", 0, "car"); jedis.zadd("sose", 0, "bike");
Set sose = jedis.zrange("sose", 0, -1);
}/// ... when closing your application:pool.close();
//Pipeline使用方式
Jedis jedis = new Jedis();
Pipeline pipeline = jedis.pipelined();
int count = 5000;
for (int i = 0; i < count; i++) {
String key = "key-" + (i + 1);
String value = "value-" + (i + 1);
pipeline.set(key, value);
pipeline.expire(key, 2);
}
long start = System.currentTimeMillis();
pipeline.syncAndReturnAll();
log.info("Jedis cost:{} ms", System.currentTimeMillis() - start);
更详细的用法可以参照: https://github.com/redis/jedis/wiki/Getting-started
Redissson
项目地址: https://github.com/redisson/redisson
优点点:分布式锁,分布式集合,可通过Redis支持延迟队列。
Redissson使用Lettuce// 1. Create config objectConfig config = new Config(); config.useClusterServers() // use "rediss://" for SSL connection .addNodeAddress("redis://127.0.0.1:7181");// or read config from fileconfig = Config.fromYAML(new File("config-file.yaml")); // 2. Create Redisson instance// Sync and Async APIRedissonClient redisson = Redisson.create(config); // Reactive APIRedissonReactiveClient redissonReactive = redisson.reactive(); // RxJava3 APIRedissonRxClient redissonRx = redisson.rxJava(); // 3. Get Redis based implementation of java.util.concurrent.ConcurrentMap RMap org.redisson redisson 3.16.2 map = redisson.getMap("myMap"); RMapReactive mapReactive = redissonReactive.getMap("myMap"); RMapRx mapRx = redissonRx.getMap("myMap"); // 4. Get Redis based implementation of java.util.concurrent.locks.Lock RLock lock = redisson.getLock("myLock"); RLockReactive lockReactive = redissonReactive.getLock("myLock"); RLockRx lockRx = redissonRx.getLock("myLock");
https://lettuce.io/
用于线程安全同步,异步和响应使用,支持集群,Sentinel,管道和编码器。
基于Netty框架的事件驱动的通信层,其方法调用是异步的。Lettuce的API是线程安全的,所以可以操作单个Lettuce连接来完成各种操作。
lettuce使用 https://github.com/lettuce-io/lettuce-core/tree/6.1.4.RELEASE附录// 使用 RedisClient redisClient = RedisClient.create("redis://password@localhost:6379/0"); StatefulRedisConnection io.lettuce lettuce-core 6.1.4.RELEASE connection = redisClient.connect(); RedisCommands syncCommands = connection.sync(); syncCommands.set("key", "Hello, Redis!"); connection.close(); redisClient.shutdown();
https://www.cnblogs.com/throwable/p/11601538.html



