当前位置:网站首页>redis连接idea
redis连接idea
2022-08-11 05:12:00 【匿名热心市民】
redis支持的语言

java连接redis的第三方依赖,常用前三个

新建maven工程

导入依赖

<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.8.0</version>
</dependency>单机连接
启动redis,确保redis的远程访问处于开启

测试
对string的操作测试


对hash的操作测试

使用连接池连接

public void Myjiqn(){
/*创建连接池配置类*/
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
/*最大空闲数*/
jedisPoolConfig.setMaxIdle(20);
/*最小空闲数*/
jedisPoolConfig.setMinIdle(5);
/*最大等待时间*/
jedisPoolConfig.setMaxWait(Duration.ofMillis(3000));
/*创建对象,连接集群*/
JedisPool jedisPool = new JedisPool(jedisPoolConfig,"192.168.92.241",6379);
/*耗时测试,获取当前时间*/
long start = System.currentTimeMillis();
for(int i=0;i<50;i++){
/*从连接池获取资源*/
Jedis jedis = jedisPool.getResource();
/*进行ping测试*/
String ping = jedis.ping();
/*关闭资源*/
jedis.close();
}
/*耗时测试,获取当前时间*/
long end = System.currentTimeMillis();
System.out.println("耗时"+(end-start));
}集群连接

public void Myjiqun(){
/*设置集群*/
Set<HostAndPort> nodes = new HashSet<>();
nodes.add(new HostAndPort("192.168.92.241",6001));
nodes.add(new HostAndPort("192.168.92.241",6002));
nodes.add(new HostAndPort("192.168.92.241",6003));
nodes.add(new HostAndPort("192.168.92.241",6004));
nodes.add(new HostAndPort("192.168.92.241",6005));
nodes.add(new HostAndPort("192.168.92.241",6006));
/*连接集群*/
JedisCluster jedisCluster = new JedisCluster(nodes);
/*调用方法*/
String set = jedisCluster.set("k1", "张三");
System.out.println(set);
/*关闭资源*/
jedisCluster.close();
}边栏推荐
- ARM Architecture 4: Embedded Hardware Platform Interface Development
- IDEA中配置checkstyle
- How IP-Guard prohibits running U disk programs
- MFC Interprocess Communication (Shared Memory)
- Paper Notes: BBN: Bilateral-Branch Network with Cumulative Learning for Long-Tailed Visual Recognition
- Switch and Router Technology-27-OSPF Route Redistribution
- Idea 2021.3.3版本文件目录展开
- C语句:数据存储
- ESP8266 教程3 — 通过TCP组建局域网并通信
- 报表控件Stimulsoft报告中的数据矩阵条形码介绍
猜你喜欢

ESP8266 教程3 — 通过TCP组建局域网并通信

IDEA中配置checkstyle

网络技能树

How IP-Guard prohibits running U disk programs

一个月闭关直接面进大厂,这份Android面试笔记是真的牛逼

Switch and Router Technology - 25 - OSPF Multi-Area Configuration

交换机和路由器技术-35-NAT转PAT

Switches and routers technologies - 30 - standard acls

Idea essential skills to improve work efficiency

交换机和路由器技术-24-OSPF单区域配置
随机推荐
The use of async (asynchronous) and await
交换机和路由器技术-32-命名ACL
Paper Notes: BBN: Bilateral-Branch Network with Cumulative Learning for Long-Tailed Visual Recognition
交换机和路由器技术-24-OSPF单区域配置
ARM结构体系4:嵌入式硬件平台接口开发
绿盾加密如何顺利切换成IP-Guard加密
async(异步)和await的使用
【无2022上海市安全员A证考试题库及模拟考试
ESP8266 教程3 — 通过TCP组建局域网并通信
Redis详解
[No 2022 Shanghai Security Officer A Certificate Exam Question Bank and Mock Exam
智能指针笔记
【嵌入式开源库】使用J-Link打印日志,让你节省一个打印串口
交换机和路由器技术-35-NAT转PAT
FPGA engineer interview questions collection 121~130
2.2 user manual] [QNX Hypervisor 10.15 vdev timer8254
[Embedded open source library] The use of cJSON, an efficient and streamlined json parsing library
@Resource和@Autowired的区别
Switch and Router Technology - 22/23 - OSPF Dynamic Routing Protocol/Link State Synchronization Process
Network Skill Tree