当前位置:网站首页>NoSQL數據庫之Redis(五):Redis_Jedis_測試
NoSQL數據庫之Redis(五):Redis_Jedis_測試
2022-06-29 06:58: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);
}
边栏推荐
- 2022.02.15 - 240. Lucky number in matrix
- try anbox (by quqi99)
- Print Yanghui triangle
- Daily question 1 - force deduction - there are three consecutive arrays of odd numbers
- Aging design guide for applets
- 大型化工企业数字化转型建议
- Li Kou daily question - day 30 -1281 Difference of sum of bit product of integer
- UVM authentication platform
- Illegal forward reference and enums
- How to do the performance pressure test of "Health Code"
猜你喜欢

Illustrate plug-in -- AI plug-in development -- creative plug-in -- astute graphics -- length and angle measurement function

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

JDBC connects to the database and socket sends the client.

Share 10 interview questions related to JS promise

RPC和RMI

Baidu applet automatically submits search

Qt 串口编程

Introduction to Ceres Quartet

Easy to understand TCP four waves (multi picture explanation)

Qt QLineEdit详解
随机推荐
JDBC | Chapter 6: simple use of database connection pool
Client and server working modes of JVM
QT qlineedit details
json tobean
Single application and microservice application
2022.02.14 - 239. A single element in an ordered array
大型化工企业数字化转型建议
Character pointer as function parameter
施工企业选择智慧工地的有效方法
JDBC连接数据库,socket发送客户端。
The annual technology inventory of cloud primitives was released, and it was the right time to ride the wind and waves
Chapter V online logic analyzer signaltap
QT (x): packaging and deployment
Open source 23 things shardingsphere and database mesh have to say
Qt 自定义位操作类
try anbox (by quqi99)
软件工程师与软件开发区别? Software Engineer和Software Developer区别?
Subtotal of C language -- basic data types and their representations
JDBC | Chapter 5: closing and releasing JDBC connection resources
It is the only one in China that Alibaba cloud container service has entered the Forrester leader quadrant