当前位置:网站首页>NoSQL数据库之Redis(五):Redis_Jedis_测试
NoSQL数据库之Redis(五):Redis_Jedis_测试
2022-06-29 06:37:00 【Tina-Deng】
目录
Jedis所需要的jar包
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.2.0</version>
</dependency>
连接Redis注意事项
禁用Linux的防火墙:Linux(CentOS7)里执行命令
systemctl stop/disable firewalld.service
redis.conf中注释掉bind 127.0.0.1 ,然后 protected-mode no
Jedis常用操作
1、创建动态的工程
2、创建测试程序
package com.atguigu.jedis;
import redis.clients.jedis.Jedis;
public class Demo01 {
public static void main(String[] args) {
Jedis jedis = new Jedis("192.168.137.3",6379);
String pong = jedis.ping();
System.out.println("连接成功:"+pong);
jedis.close();
}
}
测试相关数据类型
Jedis-API: Key
jedis.set("k1", "v1");
jedis.set("k2", "v2");
jedis.set("k3", "v3");
Set<String> keys = jedis.keys("*");
System.out.println(keys.size());
for (String key : keys) {
System.out.println(key);
}
System.out.println(jedis.exists("k1"));
System.out.println(jedis.ttl("k1"));
System.out.println(jedis.get("k1"));
Jedis-API: String
jedis.mset("str1","v1","str2","v2","str3","v3");
System.out.println(jedis.mget("str1","str2","str3"));
Jedis-API: List
List<String> list = jedis.lrange("mylist",0,-1);
for (String element : list) {
System.out.println(element);
}
Jedis-API: set
jedis.sadd("orders", "order01");
jedis.sadd("orders", "order02");
jedis.sadd("orders", "order03");
jedis.sadd("orders", "order04");
Set<String> smembers = jedis.smembers("orders");
for (String order : smembers) {
System.out.println(order);
}
jedis.srem("orders", "order02");
Jedis-API: hash
jedis.hset("hash1","userName","lisi");
System.out.println(jedis.hget("hash1","userName"));
Map<String,String> map = new HashMap<String,String>();
map.put("telphone","13810169999");
map.put("address","atguigu");
map.put("email","[email protected]");
jedis.hmset("hash2",map);
List<String> result = jedis.hmget("hash2", "telphone","email");
for (String element : result) {
System.out.println(element);
}
Jedis-API: zset
jedis.zadd("zset01", 100d, "z3");
jedis.zadd("zset01", 90d, "l4");
jedis.zadd("zset01", 80d, "w5");
jedis.zadd("zset01", 70d, "z6");
Set<String> zrange = jedis.zrange("zset01", 0, -1);
for (String e : zrange) {
System.out.println(e);
}
边栏推荐
- 多线程工具类 CompletableFuture
- RedisTemplate处理hash整数类型的问题解析
- package. Are you familiar with all configuration items and their usage of JSON
- [c language] [sword finger offer article] - print linked list from end to end
- 融入STEAM教育的劳动技能课程
- package.json的所有配置项及其用法,你都熟悉么
- QT qframe details
- UVM authentication platform
- Ribbon 服务调用与负载均衡
- [MySQL technology topic] technical analysis and guide for analyzing the high availability architecture of MySQL
猜你喜欢
![[when OSPF introduces direct connection routes, it makes a summary by using static black hole routes]](/img/a8/f77cc5e43e1885171e73f8ab543ee4.png)
[when OSPF introduces direct connection routes, it makes a summary by using static black hole routes]

QT qlineedit details

作为一名合格的网工,你必须掌握的 DHCP Snooping 知识!

RPC和RMI

Delete tag

二叉树的迭代法前序遍历的两种方法

Service grid ASM year end summary: how do end users use the service grid?

施工企业选择智慧工地的有效方法

mongostat性能分析

Share 10 interview questions related to JS promise
随机推荐
Open source 23 things shardingsphere and database mesh have to say
消息队列之通过幂等设计和原子锁避免重复退款
WDCP访问不存在的路径全部跳转到首页不返回404的解决办法
Exclusive download. Alibaba cloud native brings 10+ technical experts to bring new possibilities of cloud native and cloud future
Easy to understand TCP four waves (multi picture explanation)
Aging design guide for applets
Client and server working modes of JVM
关于 localStorage 的一些高阶用法
层次分析法
RPC和RMI
关于端口转发程序的一点思考
Json对象和Json字符串的区别
Where is the Gcov symbol- Where are the gcov symbols?
Redistemplate handles hash integer type problem resolution
idea使用
百度小程序自动提交搜索
力扣每日一题-第30天-1281.整数的各位积和之差
Analytic hierarchy process
Qt QLineEdit详解
Li Kou today's question -324 Swing sort II