|
@@ -5,10 +5,14 @@ import com.sw.dao.SysUserDao;
|
|
import com.sw.dao.TMaskDao;
|
|
import com.sw.dao.TMaskDao;
|
|
import com.sw.dao.TOrderDao;
|
|
import com.sw.dao.TOrderDao;
|
|
import com.sw.service.TMaskService;
|
|
import com.sw.service.TMaskService;
|
|
|
|
+import io.lettuce.core.SetArgs;
|
|
|
|
+import io.lettuce.core.api.async.RedisAsyncCommands;
|
|
|
|
+import io.lettuce.core.cluster.api.async.RedisAdvancedClusterAsyncCommands;
|
|
import org.junit.Assert;
|
|
import org.junit.Assert;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
import org.junit.jupiter.api.Order;
|
|
import org.junit.jupiter.api.Order;
|
|
import org.junit.runner.RunWith;
|
|
import org.junit.runner.RunWith;
|
|
|
|
+import org.redisson.api.RedissonClient;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
@@ -75,7 +79,32 @@ public class RedisTest {
|
|
public void decr(){
|
|
public void decr(){
|
|
// Long res = redisTemplate.opsForHash().increment("usableMasks", "mask-1", -5l);
|
|
// Long res = redisTemplate.opsForHash().increment("usableMasks", "mask-1", -5l);
|
|
// System.out.println(res);
|
|
// System.out.println(res);
|
|
- redisTemplate.opsForValue().set("remain", 100);
|
|
|
|
|
|
+ byte[] key = redisTemplate.getKeySerializer().serialize("mask-setnx-mq");
|
|
|
|
+ byte[] value = redisTemplate.getValueSerializer().serialize(1);
|
|
|
|
+
|
|
|
|
+ Object nativeConnection = redisTemplate.getConnectionFactory().getConnection().getNativeConnection();
|
|
|
|
+ //lettuce连接下 redis单机setnx
|
|
|
|
+ if(nativeConnection instanceof RedisAsyncCommands){
|
|
|
|
+ RedisAsyncCommands commands = (RedisAsyncCommands) nativeConnection;
|
|
|
|
+ String res = commands.getStatefulConnection().sync()
|
|
|
|
+ .set(key, value, SetArgs.Builder.nx().ex(10));
|
|
|
|
+ System.out.println(res);
|
|
|
|
+ }
|
|
|
|
+ if(nativeConnection instanceof RedissonClient){
|
|
|
|
+ RedisAsyncCommands commands = (RedisAsyncCommands) nativeConnection;
|
|
|
|
+ String res = commands.getStatefulConnection().sync()
|
|
|
|
+ .set(key, value, SetArgs.Builder.nx().ex(10));
|
|
|
|
+ System.out.println(res);
|
|
|
|
+ }
|
|
|
|
+ //lettuce连接下 redis集群setnx
|
|
|
|
+ if(nativeConnection instanceof RedisAdvancedClusterAsyncCommands){
|
|
|
|
+ RedisAdvancedClusterAsyncCommands commands = (RedisAdvancedClusterAsyncCommands) nativeConnection;
|
|
|
|
+ String res = commands.getStatefulConnection().sync()
|
|
|
|
+ .set(key, value, SetArgs.Builder.nx().ex(10));
|
|
|
|
+ System.out.println(res);
|
|
|
|
+ }
|
|
|
|
+// racac.getStatefulConnection().async().setnx("")
|
|
|
|
+// redisTemplate.opsForValue().set("remain", 100);
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|