redis实现tryAcquire

编程

public static boolean tryAcquire(String key) {

String value = String.valueOf(System.currentTimeMillis());

String statusCode =

redisTemplate.execute(new RedisCallback<String>() {

@Override

public String doInRedis(RedisConnection connection) {

Jedis conn = (Jedis)connection.getNativeConnection();

return conn.set(key,

value,

"NX",

"EX",

TimeUnit.MINUTES.toSeconds(30));

}

}, true);

if ("OK".equals(statusCode)) {

return true;

}

return false;

}

以上是 redis实现tryAcquire 的全部内容, 来源链接: utcz.com/z/516950.html

回到顶部