当前位置:网站首页>Redis (V) of NoSQL database: redis_ Jedis_ test
Redis (V) of NoSQL database: redis_ Jedis_ test
2022-06-29 06:59:00 【Tina-Deng】
Catalog
Jedis The required jar package
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.2.0</version>
</dependency>
Connect Redis matters needing attention
Ban Linux The firewall of :Linux(CentOS7) To carry out an order
systemctl stop/disable firewalld.service
redis.conf Note out bind 127.0.0.1 , then protected-mode no
Jedis Common operations
1、 Create a dynamic project
2、 Create a test program
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(" Successful connection :"+pong);
jedis.close();
}
}
Test related data types
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);
}
边栏推荐
猜你喜欢

力扣今日题-324. 摆动排序 II

QT qlineedit details

开源二三事|ShardingSphere 与 Database Mesh 之间不得不说的那些事

QT serial port programming

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

Li Kou today's question -324 Swing sort II

Message queue batch processing refund order through queue

2022.02.14 - 239. A single element in an ordered array

多模态 —— Learnable pooling with Context Gating for video classification

分享 10 个 JS Promise 相关的面试题
随机推荐
Unity ar shadow shadow
存token获取token刷新token发送header头
Ribbon 服务调用与负载均衡
C language pointer to function
IDEA常用插件
QT qframe details
package. Are you familiar with all configuration items and their usage of JSON
Flutter is configured with a domestic image and connected to the real machine
大型化工企业数字化转型建议
Ribbon service invocation and load balancing
Some thoughts on port forwarding program
Small program large screen adaptation Guide
解析学习幼儿机器人教育的浪潮
Go basic data types: characters and strings
QT (x): control operation
How to fix Error: Failed to download metadata for repo ‘appstream‘: Cannot prepare internal mirrorli
二叉树的迭代法前序遍历的两种方法
Class differences of QT processing image data (qpixmap, qimage, qpicture)
JDBC connects to the database and socket sends the client.
Analysis comp122 the Caesar cipher