Skip to content

Commit a3de5df

Browse files
committed
xmemcached incr decr
1 parent 45988b8 commit a3de5df

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

springboot-memcached/src/test/java/com/secbro/MemcachedTest.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,44 @@ public void testAppend() throws InterruptedException, MemcachedException, Timeou
7272
System.out.println((String) memcachedClient.get("hello"));
7373
}
7474

75+
/**
76+
* incr和decr错误使用示例
77+
*/
78+
@Test
79+
public void testIncreaseError() throws InterruptedException, MemcachedException, TimeoutException {
80+
81+
// 设置count初始化值为1
82+
String key = "visitCount";
83+
memcachedClient.delete(key);
84+
memcachedClient.set(key,0,1);
85+
System.out.println("初始化:" + memcachedClient.get(key));
86+
memcachedClient.incr(key,5);
87+
System.out.println("加5之后:" + memcachedClient.get(key));
88+
memcachedClient.decr(key,1);
89+
System.out.println("减1之后:" + memcachedClient.get(key));
90+
}
91+
92+
/**
93+
* incr和decr使用示例,功能类似于AtomicInteger,具有原子操作特性。
94+
*/
95+
@Test
96+
public void testIncrease() throws InterruptedException, MemcachedException, TimeoutException {
97+
98+
// 设置count初始化值为1
99+
String key = "visitCountKey";
100+
memcachedClient.delete(key);
101+
102+
memcachedClient.incr(key,1,1);
103+
System.out.println("初始化之后:" + memcachedClient.get(key));
104+
memcachedClient.incr(key,5);
105+
System.out.println("加5之后:" + memcachedClient.get(key));
106+
memcachedClient.decr(key,1);
107+
System.out.println("减1之后:" + memcachedClient.get(key));
108+
109+
memcachedClient.decr(key,6);
110+
System.out.println("减6之后:" + memcachedClient.get(key));
111+
}
112+
113+
75114

76115
}

springboot-mybatis-xml/src/main/java/com/secbro/SpringBootMainApplication.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.secbro;
22

3-
43
import org.mybatis.spring.annotation.MapperScan;
54
import org.springframework.boot.SpringApplication;
65
import org.springframework.boot.autoconfigure.SpringBootApplication;

0 commit comments

Comments
 (0)