[toc]
[toc]
本系列文章整理摘抄自
客户端怎么和 Redis 服务器连接?
客户端和 Redis 服务器的通信是 建立在 TCP 连接的基础上的。
并且 Redis 制定了 RESP 序列化协议,是一个简单地通信约定。
Resp序列化协议
*<参数数量>\r\n$<参数1的字节数量>\r\n<参数1>\r\n$<参数2的字节数量>\r\n<参数2>\r\n
来给可视化一下:
1 2 3 4 5
|
*<参数数量>\r\n $<参数1的字节数量>\r\n <参数1>\r\n $<参数2的字节数量>\r\n <参数2>\r\n
|
其他可以参考该书章节。
Jedis 连接池的使用
简单的API 介绍
获取 jedis连接
1 2 3 4 5 6 7 8 9 10 11 12 13
|
Jedis jedis = new Jedis("127.0.0.1", 6379);
Jedis jedis = null; try {
jedis = new Jedis("127.0.0.1", 6379); } catch (Exception e) {
logger.error(e.getMessage(),e); } finally {
if (jedis != null) {
jedis.close(); } }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
// String jedis.set("key", "value"); jedis.get("key")
// hset -字典 jedis.set("hash", "key1", "value1"); jedis.set("hash", "key2", "value2"); jedis.get("key1")
// list -列表 jedis.rpush("mylist", "1");
// set -集合 jedis.sadd("set", "aaa");
....
|
springboot 环境下的使用
1. maven 依赖
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
|