当前位置:网站首页>Basic use cases for jedis
Basic use cases for jedis
2022-06-10 16:31:00 【€ € - flying - ~ £】
Jedis yes java Use in Redis A large class of commands , Each method in its class is associated with Redis Corresponding to the command of , The following cases help us understand Java In the operation Redis cache .
package com.wxl;
import com.alibaba.fastjson.JSONObject;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Transaction;
import java.util.Set;
public class TestPing {
public static void main(String[] args) {
normalOperation();
System.out.println();
transactionOperation();
}
/*
The transaction operations
*/
private static void transactionOperation() {
Jedis jedis = new Jedis("127.0.0.1", 6379);
jedis.flushAll();
JSONObject jsonObject = new JSONObject();
jsonObject.put("hello", "world");
jsonObject.put("name", "Jack");
// Open transaction
Transaction multi = jedis.multi();
String result = jsonObject.toJSONString();
try {
multi.set("user1", result);
multi.set("user2", result);
multi.exec();// Perform transactions
} catch (Exception e) {
multi.discard();// Give up the business
} finally {
System.out.println(jedis.get("user1"));
System.out.println(jedis.get("user2"));
jedis.close();
}
}
private static void normalOperation() {
//1、new Jedis Object can
Jedis jedis = new Jedis("127.0.0.1", 6379);
//jedis all redis Command method corresponding to class
System.out.println(jedis.ping());
// Common command tests
System.out.println(" Empty data " + jedis.flushDB());
System.out.println(" Determine whether a key exists " + jedis.exists("username"));
System.out.println(" New user name " + jedis.set("username", "Jack"));
System.out.println(" New password " + jedis.set("password", "123456"));
System.out.println(" All keys in the system are as follows :");
Set<String> keys = jedis.keys("*");
System.out.println(keys);
System.out.println(" Delete key password" + jedis.del("password"));
System.out.println(" Judgment key password Whether there is " + jedis.exists("password"));
System.out.println(" View key username The type of value stored :" + jedis.type("username"));
System.out.println(" Random return key One of the spaces " + jedis.randomKey());
System.out.println(" rename key:" + jedis.rename("username", "name"));
System.out.println(" Take out the modified name:" + jedis.get("name"));
System.out.println(" Search by index :" + jedis.select(0));
System.out.println(" Delete all... In the currently selected database key:" + jedis.flushDB());
System.out.println(" Return to the current database key Number of :" + jedis.flushDB());
System.out.println(" Returns the key Number of :" + jedis.dbSize());
System.out.println(" Delete all in all databases key:" + jedis.flushAll());
jedis.close();// Close links
}
}
The operation effect is as follows :

边栏推荐
- 直播预告 | 解构OLAP!新型多维分析架构范式全公开!Apache Doris 将带来五个重磅议题!
- Digital image processing: graying
- Nerf: the popularity of using deep learning to complete 3D rendering tasks
- 运行mapreduce任务缺失setJarByClass()报错找不到类
- 袋鼠云数栈基于CBO在Spark SQL优化上的探索
- Come with me to understand gaussdb (for opengauss) [Gauss is not a mathematician this time]
- Analysis report on marketing status and demand potential of China's acetate starch industry 2022-2028
- When visual studio 2019 is installed, vs installer cannot download files. The progress bar is 0. It shows the solutions to network problems
- Common sense: the number of neurons in the brain of mice is about 70million and that of humans is about 86billion
- Rk3308 key and LED light
猜你喜欢

RK3308--固件编译

Duyuan outdoor sprint to Shenzhen Stock Exchange: the annual revenue is 350million, and the color of Lin Xizhen family is obvious

Why do I need a thread pool? What is pooling technology?

Code implementation of partition case of MapReduce

leetcode:730. 统计不同回文子序列【由点及面区间dp + 三维dp + 对角线遍历】
![[today in history] June 10: Apple II came out; Microsoft acquires gecad; The scientific and technological pioneer who invented the word](/img/0d/9f99eb3dcb73c912987b81fba71890.png)
[today in history] June 10: Apple II came out; Microsoft acquires gecad; The scientific and technological pioneer who invented the word "software engineering" was born

Introduction to postmangrpc function

Research Report on the application field of Chinese antirust oil market and the prospect planning of the 14th five year plan (2022-2028)

MapReduce案例之多Map阶段求共同好友

硬件仪器的使用
随机推荐
Query-Convert QuickView是灰掉的解决办法(转)_SAP刘梦
Common sense: the number of neurons in the brain of mice is about 70million and that of humans is about 86billion
Research Report on development potential analysis and investment development strategy of global and Chinese hydraulic oil industry (2022-2028)
2D pose estimation for pose estimation - (openpose) realtime multi person 2D pose estimation using part affinity fields
Software College of Shandong University Project Training - Innovation Training - network security range experimental platform (16)
MapReduce案例之排序
Nanomq newsletter 2022-05 | release of V0.8.0, new webhook extension interface and connection authentication API
[untitled] audio Bluetooth voice chip, wt2605c-32n real-time recording upload technical scheme introduction
Opencv 4 handwriting recognition: perfect self built training set
MapReduce之Word Count案例代码实现
硬件仪器的使用
Exploration of kangaroo cloud data stack on spark SQL optimization based on CBO
Why do I need a thread pool? What is pooling technology?
MapReduce之分区案例的代码实现
RK3308 按键Key与LED灯
STOP在屏幕程序的应用_SAP刘梦_
SQL language
Anba cv2fs/cv22fs obtained ASIL C chip function safety certification, surpassing the level of similar chips in the market
[section 6 functions]
NanoMQ Newsletter 2022-05|v0.8.0 发布,新增 WebHook 拓展接口和连接认证 API