lettuce--Advanced Redis client
redis官方提供的java client:
git地址:https://github.com/mp911de/lettuce
Advanced Redis client for thread-safe sync, async, and reactive usage. Supports Cluster, Sentinel, Pipelining, and codecs.http://redis.paluch.biz
Introduction
Lettuce is a scalable thread-safe Redis client for synchronous, asynchronous and reactive usage. Multiple threads may share one connection if they avoid blocking and transactional operations such as BLPOP and MULTI/EXEC. lettuce is built with netty. Supports advanced Redis features such as Sentinel, Cluster, Pipelining, Auto-Reconnect and Redis data models.
This version of lettuce has been tested against Redis and 3.0.
- lettuce 3.x works with Java 6, 7 and 8, lettuce 4.x requires Java 8
- synchronous, asynchronous and reactive usage
- Redis Sentinel
- Redis Cluster
- SSL and Unix Domain Socket connections
- Streaming API
- CDI and Spring integration
- Codecs (for UTF8/bit/JSON etc. representation of your data)
- multiple Command Interfaces
几个常见的使用方法:
1. 连接单机
package com.lambdaworks.examples;import com.lambdaworks.redis.RedisClient; import com.lambdaworks.redis.RedisConnection; import com.lambdaworks.redis.RedisURI;/*** @author <a href="mailto:mpaluch@paluch.biz">Mark Paluch</a>* @since 18.06.15 09:17*/ public class ConnectToRedis {public static void main(String[] args) {// Syntax: redis://[password@]host[:port][/databaseNumber]RedisClient redisClient = new RedisClient(RedisURI.create("redis://password@localhost:6379/0"));RedisConnection<String, String> connection = redisClient.connect();System.out.println("Connected to Redis");connection.close();redisClient.shutdown();} }
2. 连接集群
package com.lambdaworks.examples;import com.lambdaworks.redis.RedisURI; import com.lambdaworks.redis.cluster.RedisAdvancedClusterConnection; import com.lambdaworks.redis.cluster.RedisClusterClient;/*** @author <a href="mailto:mpaluch@paluch.biz">Mark Paluch</a>* @since 18.06.15 09:17*/ public class ConnectToRedisCluster {public static void main(String[] args) {// Syntax: redis://[password@]host[:port]RedisClusterClient redisClient = new RedisClusterClient(RedisURI.create("redis://password@localhost:7379"));RedisAdvancedClusterConnection<String, String> connection = redisClient.connectCluster();System.out.println("Connected to Redis");connection.close();redisClient.shutdown();} }
3. 连接sentinel
package com.lambdaworks.examples;import com.lambdaworks.redis.*;/*** @author <a href="mailto:mpaluch@paluch.biz">Mark Paluch</a>* @since 18.06.15 09:17*/ public class ConnectToRedisUsingRedisSentinel {public static void main(String[] args) {// Syntax: redis-sentinel://[password@]host[:port][,host2[:port2]][/databaseNumber]#sentinelMasterIdRedisClient redisClient = new RedisClient(RedisURI.create("redis-sentinel://localhost:26379,localhost:26380/0#mymaster"));RedisConnection<String, String> connection = redisClient.connect();System.out.println("Connected to Redis using Redis Sentinel");connection.close();redisClient.shutdown();} }
4.安全的连接
package com.lambdaworks.examples;import com.lambdaworks.redis.*;/*** @author <a href="mailto:mpaluch@paluch.biz">Mark Paluch</a>* @since 18.06.15 09:17*/ public class ConnectToRedisSSL {public static void main(String[] args) {// Syntax: rediss://[password@]host[:port][/databaseNumber]// Adopt the port to the stunnel port in front of your Redis instanceRedisClient redisClient = new RedisClient(RedisURI.create("rediss://password@localhost:6443/0"));RedisConnection<String, String> connection = redisClient.connect();System.out.println("Connected to Redis using SSL");connection.close();redisClient.shutdown();} }
5. spring集成
package com.lambdaworks.examples;import com.lambdaworks.redis.*; import org.springframework.beans.factory.annotation.Autowired;/*** @author <a href="mailto:mpaluch@paluch.biz">Mark Paluch</a>* @since 18.06.15 09:31*/ public class MySpringBean {private RedisClient redisClient;@Autowiredpublic void setRedisClient(RedisClient redisClient) {this.redisClient = redisClient;}public String ping() {RedisConnection<String, String> connection = redisClient.connect();String result = connection.ping();connection.close();return result;} }
使用代码如下:
package com.lambdaworks.examples;import org.springframework.context.support.ClassPathXmlApplicationContext;import com.lambdaworks.redis.RedisClient; import com.lambdaworks.redis.RedisConnection;/*** @author <a href="mailto:mpaluch@paluch.biz">Mark Paluch</a>* @since 18.06.15 09:17*/ public class SpringExample {public static void main(String[] args) {ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("com/lambdaworks/examples/SpringTest-context.xml");RedisClient client = context.getBean(RedisClient.class);RedisConnection<String, String> connection = client.connect();System.out.println("PING: " + connection.ping());connection.close();MySpringBean mySpringBean = context.getBean(MySpringBean.class);System.out.println("PING: " + mySpringBean.ping());context.close();}}
参考文献:
【1】https://github.com/mp911de/lettuce
【2】http://redis.paluch.biz
转载于:https://www.cnblogs.com/davidwang456/p/5089502.html
lettuce--Advanced Redis client相关推荐
- [工具类] 系列二 Lettuce 访问Redis 工具类 RedisUtil
最近公司Redis集群启用了ssl和密码校验,使用Jedis访问Redis Cluster的时候,支持不太好.看到spring-data-redis 2.x开始使用Lettuce访问Redis,于是开 ...
- Redis——Lettuce连接redis集群
Lettuce连接redis集群使用的都是集群专用类,像RedisClusterClient.StatefulRedisClusterConnection.RedisAdvancedClusterCo ...
- 深入浅出 Redis client/server交互流程
2019独角兽企业重金招聘Python工程师标准>>> 最近笔者阅读并研究redis源码,在redis客户端与服务器端交互这个内容点上,需要参考网上一些文章,但是遗憾的是发现大部分文 ...
- redis client 2.0.0 pipeline 的list的rpop bug
描写叙述: redis client 2.0.0 pipeline 的list的rpop 存在严重bug,rpop list的时候,假设list已经为空的时候,rpop出来的Response依旧不为n ...
- 谷歌浏览器怎么重发请求_Googel 浏览器 模拟发送请求工具--Advanced REST Client
Advanced REST Client是 Chrome 浏览器下的一个插件,通过它可以发送 http.https.WebSocket 请求.在 Chrome 商店下搜索 Advanced REST ...
- Redis Client UI工具
前言 使用Redis做缓存也有一段时间了,一款趁手的UI工具可以省下很多的开发时间.这里,便总结下我所使用的Redis UI 工具. Redis Client 原生工具 Redis Client (g ...
- Redis Client On Error: Error: write ECONNABORTED Config right
解决Redis Client On Error: Error: write ECONNABORTED Config rightwe-问题 问题描述: 解决方案: 1.首先检查Linux的防火墙是否开启 ...
- 安装谷歌浏览器——测试工具(Advanced REST client)
Extension Manager 一.下载插件:下载后解压 https://pan.baidu.com/s/1etL1tqPvNxUNHjSmy0CnEg 密码:c5p2 二.打开开发者模式 三.安 ...
- 【Rest API】Advanced REST Client浏览器插件rest api请求工具安装教程及使用说明
前言 开发工作中,经常会对rest api接口进行测试,大家肯定会想到postman,但是今天给大家推荐一个小容量更便捷的浏览器插件工具Advanced REST Client 安装说明 1.点击下载 ...
最新文章
- kali 解决Metasploit拿到shell后显示中文乱码问题
- antd 中table上加不同字体颜色_字体渲染系统!微软终于决定优化Win10字体模糊问题...
- ni软件可以卸载吗_黑科技 | 2020全新AI人工智能修图汉化版软件!这下可以放心卸载PS啦!...
- SQL Server分页查询存储过程
- linux 修改文件名_Linux常用命令
- .NET开发 程序员必备工具 -- Regulator:生成正则表达式工具
- 【论文阅读】Drug Similarity Integration Through Multi-view Graph Auto-Encoders | day4、5
- Pandas Index 转换排序联表选取
- 2021年最值得推荐的七款可视化工具,人人都能学会使用
- 用命令来操作vSphere:二十二 PowerCLI命令--虚拟主机操作(1)
- 湘潭大学计算机学院考研喜报,湘潭大学化学学院考研率连续七年在全校排名第一...
- 用计算机上初中英语课的方法,如何上好初中英语读写课
- Moya、RxMoya基本使用
- Professional Microsoft Office SharePoint Designer 2007
- mybatis 九大动态标签详解
- 理解optimizer.zero_grad(), loss.backward(), optimizer.step()的作用及原理
- android onkeydown()简介
- 实现一个 Spring Boot Starter 原来如此简单,读 Starter 源码也不在话下
- 黄飞130702010037第二次作业
- RPA不是“万灵丹”,需人机分工内控风险
热门文章
- php下dat函数e,PHP 常用函数记录 一
- vue 组件属性监听_Vue.js 监听属性
- apache tomcat下32还是64_JDK和Tomcat安装和配置的图文教程
- python测验4_python接口自动化测试四:代码发送HTTPS请求
- php序列化中文,详解之php反序列化
- 计算机网络 tcp 阻塞,读书笔记:计算机网络第7章:阻塞控制
- java request 原理_JavaWeb-seession原理
- 胡正是什么lisp_《亲爱的挚爱的》演员公开,吴白还是胡一天,grunt却换了人
- 《基于张量网络的机器学习入门》学习笔记2
- Pycharm 配置 Anaconda中解释器