当前位置:网站首页>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();
}边栏推荐
- 智能指针笔记
- About CC Attacks
- 优化是一种习惯●出发点是“站在靠近临界“的地方
- [QNX Hypervisor 2.2 User Manual] 10.16 vdev virtio-blk
- 交换机和路由器技术-27-OSPF路由重分发
- BitLocker的解密
- Switches and routers technology - 24 - configure OSPF single area
- Switch and Router Technology - 32 - Named ACL
- 论文笔记:BBN: Bilateral-Branch Network with Cumulative Learningfor Long-Tailed Visual Recognition
- Switch and Router Technology-27-OSPF Route Redistribution
猜你喜欢

Zabbix builds enterprise-level monitoring and alarm platform

HAVE FUN | “SOFA 星球”飞船计划、源码解析活动最新进展

Sub-database sub-table ShardingSphere-JDBC notes arrangement

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

交换机和路由器技术-26-OSPF末梢区域配置

Switch and Router Technology - 28 - NSSA Areas for OSPF

宝塔Linux环境下redis开启多端口

Prometheus :(一)基本概念

C statement: data storage

BGP综合实验
随机推荐
[QNX Hypervisor 2.2 User Manual] 10.16 vdev virtio-blk
MySQL must know and must know (primary articles)
[FPGA tutorial case 49] Control case 1 - FPGA-based PID controller verilog implementation
报表控件Stimulsoft报告中的数据矩阵条形码介绍
About CC Attacks
Switch and Router Technology - 25 - OSPF Multi-Area Configuration
Golden Warehouse Database KingbaseGIS User Manual (6.8. Geometry Object Input Function)
Switches and routers technology - 24 - configure OSPF single area
02. Fold hidden text
Idea 2021.3.3版本文件目录展开
How to use svg-icon (svg-sprite-loader plugin)
Switches and routers technologies - 30 - standard acls
Optimization is a kind of habit low starting point is the "standing near the critical"
关于ie下href有中文出现RFC 7230 and RFC 3986问题的研究
2022 building welder (building a special type of work) examination questions and simulation test
Switch and Router Technology - 32 - Named ACL
oracle表空间与用户的创建
Golden Warehouse Database KingbaseGIS User Manual (6.10. Geometric Object Operation Operator)
一些常见mysql入门练习
交换机和路由器技术-34-动态NAT