Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2e0abff

Browse files
committed
add atomic long function in redisson sample
1 parent 34babb4 commit 2e0abff

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

‎springboot-redisson-sample/src/main/java/com/ipman/springboot/redisson/sample/examples/RedissonExamples.java‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.ipman.springboot.redisson.sample.examples;
22

33
import lombok.SneakyThrows;
4+
import org.redisson.api.RAtomicLong;
45
import org.redisson.api.RLock;
56
import org.redisson.api.RedissonClient;
67
import org.springframework.stereotype.Component;
@@ -51,4 +52,20 @@ public void lock() {
5152
t.join();
5253
}
5354

55+
/**
56+
* 使用 RAtomicLong 实现 Redis 分布式原子操作
57+
*/
58+
@SneakyThrows
59+
public void atomicLong() {
60+
RAtomicLong atomicLong = redissonClient.getAtomicLong("atomicLong");
61+
62+
System.out.println("Init value: " + atomicLong.get());
63+
64+
atomicLong.incrementAndGet();
65+
System.out.println("Current value: " + atomicLong.get());
66+
67+
atomicLong.addAndGet(1L);
68+
System.out.println("Final value: " + atomicLong.get());
69+
}
70+
5471
}

‎springboot-redisson-sample/src/test/java/com/ipman/springboot/redisson/sample/examples/RedissonExamplesTest.java‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,17 @@ public class RedissonExamplesTest {
2222
* 使用 RLock 实现 Redis 分布式锁测试
2323
*/
2424
@Test
25-
public void testLock(){
25+
public void testLock(){
2626
redissonExamples.lock();
2727
}
28+
29+
/**
30+
* 使用 RAtomicLong 实现 Redis 分布式原子操作
31+
*/
32+
@Test
33+
public void testAtomicLong() {
34+
redissonExamples.atomicLong();
35+
}
36+
37+
2838
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /