当前位置:网站首页>Redis and jedis
Redis and jedis
2022-06-25 01:20:00 【Lutrra】
thing
#redis A single command is atomic, but things don't
#redis The essence of things : A collection of commands , All commands in a thing are serialized , During the execution of things , Execute in order
#reids Things have no isolation level
# All commands are in things , Not directly executed , Only when you initiate an execution command will you execute
# Opening things
multi
# Order to join the team
# Execute things
exec
# Normal things
multi
set k1 v1
set k2 v2
exec
# Execute sequentially End of execution
# Cancel something
DISCARD
# Once you give up , All will not be executed
# error
#1. Compile exception
# Will not execute
multi
set k1 v1
set k2 v2
getset k3
set k4 v4
exec
#2. Abnormal operation
# There is a grammatical error , Other commands can be used
multi
set k1 "v1"
incr k1
set k2 v2
get k2
exec
monitor
Pessimistic locking
# I think there will be problems all the time , It will be locked at any time
Optimism lock
# Think there will be no problem at all , So it won't lock , Judge when updating data , Has anyone modified the data during this period
# obtain version
set money 100
set out 0
watch money # Monitored object
multi # Things end normally , There was no change during the data period , This time, the implementation will be successful
DECRBY money
INCRBY out 20
exec
# Thread one
watch money
multi
decrby money 10
incrby out 10
# Threads 2 Make changes
set money 1000
# Thread one
exec # error
unwatch
watch money
multi
decrby money 10
incrby out 10
jedis
<!-- redis Recommended by the official website java Connect development tools ! Use java Middleware for operation Import corresponding dependency -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.7.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.75</version>
</dependency>
Test local connection
pulic class TestPing{
public static void main(string[] args){
Jedis jedis= new Jedis("127.0.0.1",6379);
//jedis All commands are redis All the orders of
system.out.println(jedis.ping())
}
}
adopt jedis Understand things
pulic class TestPing{
public static void main(string[] args){
Jedis jedis= new Jedis("127.0.0.1",6379);
//jedis All commands are redis All the orders of
JSONObject jsaonobject =new JSONObject();
jsonobject.put("hello","world");
Transation multi=jedis.multi();
String result=jsonobject.toJSONString();
try{
multi.set("user1",result);
multi.exec();
}
catch{
multi.discard();
e.printStackTrace();
}finally{
jedis.close();// Close the connection
}
}
}
springboot Integrate
#springboot Do not use jedis Connect , use lettuce
spring.redis.host="127.0.0.1"
spring.redis.port=6379
@Autowired
private RedisTemplate redisTemplate;
void contextLoads(){
redis.opForValue().set("mykey","lutrra");
system.out.println(redisTemplate.opForValue.get("mykey"));
}
边栏推荐
- Assembly language (4) function transfer parameters
- 扎克伯格上手演示四款VR头显原型机,Meta透露元宇宙「家底」
- Tianshu night reading notes -- disassembly engine xde32
- JVM指令
- 脱氧核糖核酸酶I中英文说明书
- 论文翻译 | RandLA-Net: Efficient Semantic Segmentation of Large-Scale Point Clouds
- Bi-sql - different join
- 新手看过来,带你一次性了解“软考”
- 对技术的乐观,正让戴尔取得比想象中更多的成就
- 图片旋转移动缩放渐变
猜你喜欢

Tianshu night reading notes -- memory paging mechanism

Bi-sql delete

Assembly language (3) 16 bit assembly basic framework and addition and subtraction loop

JVM directive

Bi-sql select into

Ideas and examples of divide and conquer

LLVM TargetPassConfig

重磅:国产IDE发布,由阿里研发,完全开源!(高性能+高定制性)

Première application de l'informatique quantique à la modélisation des flux de puissance dans les systèmes énergétiques à l'Université technique danoise

Abnova丨CSV 磁珠中英文说明
随机推荐
Cloud development technology summit · public welfare programming challenge [hot registration]!
Cobalt Strike安装教程
Expectation and variance
Audio PCM data calculates sound decibel value to realize simple VAD function
Bi-sql top
void* 指针
新一代可级联的以太网远程I/O数据采集模块
Activity lifecycle
bindservice方法实现音乐播放暂停
百度语音合成语音文件并在网站中展示
ImageView展示网络图片
胰蛋白酶中英文说明书
修身励学篇
"One good programmer is worth five ordinary programmers!"
腾讯云WeCity解决方案
Distinguish between i++ and ++i seconds
Danish Technical University pioneered the application of quantum computing to power flow modeling of energy system
Ideas and examples of divide and conquer
Mysql database Chapter 1 Summary
Basic knowledge of assembly language (2) -debug