当前位置:网站首页>Redis测试
Redis测试
2022-08-11 05:37:00 【程程呀是小白】
目录
本文是本人以前笔记,如果说是在掘金上看到的话没错,还是本人程程呀 的个人主页 - 动态 - 掘金目前只有这一个。如果有哪里不对的话欢迎各位大佬指出问题,本人是一个小白。
上一篇文章链接为:Redis发布订阅和数据类型_程程呀是小白的博客-CSDN博客 ,本篇是连接Redis发布订阅和数据类型_程程呀是小白的博客-CSDN博客的。
如果是springboot的话请看springboot创建项目_程程呀是小白的博客-CSDN博客_springboot创建项目创建项目 ,这个是从头开始的还没有学完springboot,一起学习呀!!!!
测试
1.jedis所需要的jar包
<dependencies>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.2.0</version>
</dependency>
</dependencies>
2.模拟测试
public static void main(String[] args) {
//创建jedis对象
Jedis jedis=new Jedis("192.168.1.6",6379);
//测试
String value= jedis.ping();
System.out.println(value);
}
运行错误(解决办法为3和4)connect timed out
能够正确运行
PONG
3. 查看/关闭防火墙
[[email protected] ccy]# Systemctl status firewalld 查看是否关闭
[[email protected] ccy]# systemctl stop firewalld 关闭
4. 将保护模式protected-mode 为no
[[email protected] ccy]# /usr/local/bin
bash: /usr/local/bin: 是一个目录
[[email protected] ccy]# cd /usr/local/bin
[[email protected] bin]# ./redis-cli
127.0.0.1:6379> config get protected-mode
1) "protected-mode"
2) "yes"
127.0.0.1:6379> config set protected-mode no
OK
127.0.0.1:6379> config get protected-mode
1) "protected-mode"
2) "no"
测试相关数据类型
1 Jedis-API: key 执行添加
//操作key
@Test
public void demo1(){
//创建jedis对象
Jedis jedis=new Jedis("192.168.1.6",6379);
//添加
jedis.set("name","ccy");
//获取
String name=jedis.get("name");
System.out.println(name);
Set<String>keys=jedis.keys("*");
for (String key :keys){
System.out.println(key);
}
}
2 .Jedis-API :String
//设置多个key-value
jedis.mset("s1","v1","s2","v2");
List<String>mget=jedis.mget("s1","s2");
System.out.println(mget);
3. Jedis-API :List
//操作list
@Test
public void demo2(){
//创建jedis对象
Jedis jedis=new Jedis("192.168.1.6",6379);
jedis.lpush("key1","lucy","maet","java");
List<String>values=jedis.lrange("key1",0,-1);
System.out.println(values);
}
4. Jedis-API :set
@Test
public void demo3(){
//创建jedis对象
Jedis jedis=new Jedis("192.168.1.6",6379);
jedis.sadd("names","lucy");
jedis.sadd("names","mary");
Set<String> names =jedis.smembers("names");
System.out.println(names);
}
5.Jedis-API :hash
//操作hash
@Test
public void demo4(){
//创建jedis对象
Jedis jedis=new Jedis("192.168.1.6",6379);
jedis.hset("users","age","20");
String hget=jedis.hget("users","age");
System.out.println(hget);
}
}
6. Jedis-API :zshe
///操作zshe
@Test
public void demo5(){
//创建jedis对象
Jedis jedis=new Jedis("192.168.1.6",6379);
jedis.zadd("china",100d,"shanghai");
Set<String>china=jedis.zrange("china",0,-1);
System.out.println(china);
jedis.close();
}
本文是本人以前笔记,如果说是在掘金上看到的话没错,还是本人程程呀 的个人主页 - 动态 - 掘金目前只有这一个。如果有哪里不对的话欢迎各位大佬指出问题,本人是一个小白。
上一篇文章链接为:Redis发布订阅和数据类型_程程呀是小白的博客-CSDN博客 ,本篇是连接Redis发布订阅和数据类型_程程呀是小白的博客-CSDN博客的。
如果是springboot的话请看springboot创建项目_程程呀是小白的博客-CSDN博客_springboot创建项目创建项目 ,这个是从头开始的还没有学完springboot,一起学习呀!!!!
边栏推荐
- maxwell 概念
- 阿里巴巴规范之POJO类中布尔类型的变量都不要加is前缀详解
- OA项目之我的会议(会议排座&送审)
- 损失函数——负对数似然
- 技能在赛题解析:交换机防环路设置
- 核方法 Kernel method
- HCIP-生成树(802.1D ,标准生成树/802.1W : RSTP 快速生成树/802.1S : MST 多生成树)
- Resolved EROR 1064 (42000): You have an error in. your SOL syntax. check the manual that corresponds to yo
- Find the shops that have sold more than 1,000 yuan per day for more than 30 consecutive days in the past six months
- 空间金字塔池化 -Spatial Pyramid Pooling(含源码)
猜你喜欢
随机推荐
Coordinate system in navigation and positioning
HCIP OSPF/MGRE综合实验
My meeting of the OA project (meeting seating & review)
《Generative Adversarial Networks》
unable to extend table xxx by 1024 in tablespace xxxx
矩阵分析——矩阵分解
Redis + lua implements distributed interface current limiting implementation scheme
OA项目之我的审批(查询&会议签字)
每日sql -查询至少有5名下属的经理和选举
知识蒸馏Knownledge Distillation
Get Pinduoduo product information operation details
Class definition, class inheritance, and the use of super
Eight-legged text jvm
unable to extend table xxx by 1024 in tablespace xxxx
HCIP Republish/Routing Policy Experiment
Xshell如何连接虚拟机
快速了解集成学习
概念名词解释
淘宝商品详情API接口
每日sql--统计员工近三个月的总薪水(不包括最新一个月)