org.redisson.Redisson.getLock()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(5.2k)|赞(0)|评价(0)|浏览(255)

本文整理了Java中org.redisson.Redisson.getLock方法的一些代码示例,展示了Redisson.getLock的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Redisson.getLock方法的具体详情如下:
包路径:org.redisson.Redisson
类名称:Redisson
方法名:getLock

Redisson.getLock介绍

暂无

代码示例

代码示例来源:origin: redisson/redisson

private RLock getLockedLock(K key) {
  if (atomicExecution) {
    return DUMMY_LOCK;
  }
  
  String lockName = getLockName(key);
  RLock lock = redisson.getLock(lockName);
  try {
    lock.lock();
  } catch (Exception e) {
    throw new CacheException(e);
  }
  return lock;
}

代码示例来源:origin: redisson/redisson

private RLock getLockedLock(K key) {
  if (atomicExecution) {
    return DUMMY_LOCK;
  }
  
  String lockName = getLockName(key);
  RLock lock = redisson.getLock(lockName);
  try {
    lock.lock();
  } catch (Exception e) {
    throw new CacheException(e);
  }
  return lock;
}

代码示例来源:origin: redisson/redisson

public RedissonSortedSet(Codec codec, CommandExecutor commandExecutor, String name, Redisson redisson) {
  super(codec, commandExecutor, name);
  this.commandExecutor = commandExecutor;
  comparatorHolder = redisson.getBucket(getComparatorKeyName(), StringCodec.INSTANCE);
  lock = redisson.getLock("redisson_sortedset_lock:{" + getName() + "}");
  list = (RedissonList<V>) redisson.getList(getName(), codec);
  loadComparator();
}

代码示例来源:origin: redisson/redisson

public RedissonSortedSet(Codec codec, CommandExecutor commandExecutor, String name, Redisson redisson) {
  super(codec, commandExecutor, name);
  this.commandExecutor = commandExecutor;
  comparatorHolder = redisson.getBucket(getComparatorKeyName(), StringCodec.INSTANCE);
  lock = redisson.getLock("redisson_sortedset_lock:{" + getName() + "}");
  list = (RedissonList<V>) redisson.getList(getName(), codec);
  loadComparator();
}

代码示例来源:origin: stackoverflow.com

Redisson redisson = Redisson.create(config);

Lock lock = redisson.getLock("anyLock");
try {
  // unlock automatically after 10 seconds of hold
  lock.lock(10, TimeUnit.SECONDS);

} finally {
  lock.unlock();
}

...

redisson.shutdown();

代码示例来源:origin: dufyun/learn-tech-collection

/**
 * 根据name对进行上锁操作,redissonLock 阻塞事的,采用的机制发布/订阅
 * @param lockname
 */
public static void lock(String lockname){
  String key = LOCK_FLAG + lockname;
  RLock lock = redisson.getLock(key);
  //lock提供带timeout参数,timeout结束强制解锁,防止死锁 :1分钟
  lock.lock(1, TimeUnit.MINUTES);
}

代码示例来源:origin: dufyun/learn-tech-collection

/**
 * 根据name对进行解锁操作
 * @param lockname
 */
public static void unlock(String lockname){
  String key = LOCK_FLAG + lockname;
  RLock lock = redisson.getLock(key);
  lock.unlock();
}

代码示例来源:origin: TaXueWWL/redis-distributed-lock

/**
 * 解锁
 * @param lockName
 */
public void release(String lockName) {
  redissonManager.getRedisson().getLock(lockName).unlock();
}

代码示例来源:origin: stackoverflow.com

Config config = new Config();
config.addAddress("some.server.com:8291");
Redisson redisson = Redisson.create(config);

Lock lock = redisson.getLock("anyLock");
lock.lock();
try {
  ...
} finally {
  lock.unlock();
}

redisson.shutdown();

代码示例来源:origin: TaXueWWL/redis-distributed-lock

/**
 * 加锁操作
 * @return
 */
public boolean lock(String lockName, long expireSeconds) {
  RLock rLock = redissonManager.getRedisson().getLock(lockName);
  boolean getLock = false;
  try {
    getLock = rLock.tryLock(0, expireSeconds, TimeUnit.SECONDS);
    if (getLock) {
      LOGGER.info("获取Redisson分布式锁[成功],lockName={}", lockName);
    } else {
      LOGGER.info("获取Redisson分布式锁[失败],lockName={}", lockName);
    }
  } catch (InterruptedException e) {
    LOGGER.error("获取Redisson分布式锁[异常],lockName=" + lockName, e);
    e.printStackTrace();
  }
  return getLock;
}

代码示例来源:origin: TaXueWWL/redis-distributed-lock

/**
 * 加锁操作
 * @return
 */
public boolean lock(String lockName, long expireSeconds) {
  RLock rLock = redissonManager.getRedisson().getLock(lockName);
  boolean getLock = false;
  try {
    getLock = rLock.tryLock(0, expireSeconds, TimeUnit.SECONDS);
    if (getLock) {
      LOGGER.info("获取Redisson分布式锁[成功],lockName={}", lockName);
    } else {
      LOGGER.info("获取Redisson分布式锁[失败],lockName={}", lockName);
    }
  } catch (InterruptedException e) {
    LOGGER.error("获取Redisson分布式锁[异常],lockName=" + lockName, e);
    e.printStackTrace();
    return false;
  }
  return getLock;
}

代码示例来源:origin: TaXueWWL/redis-distributed-lock

/**
 * 解锁
 * @param lockName
 */
public void release(String lockName) {
  redissonManager.getRedisson().getLock(lockName).unlock();
}

代码示例来源:origin: org.redisson/redisson

private RLock getLockedLock(K key) {
  if (atomicExecution) {
    return DUMMY_LOCK;
  }
  
  String lockName = getLockName(key);
  RLock lock = redisson.getLock(lockName);
  try {
    lock.lock();
  } catch (Exception e) {
    throw new CacheException(e);
  }
  return lock;
}

代码示例来源:origin: stackoverflow.com

Config config = new Config();
// for single server
config.useSingleServer()
   .setAddress("127.0.0.1:6379");
// or 
// for master/slave servers
config.useSentinelConnection()
   .setMasterName("mymaster")
   .addSentinelAddress("127.0.0.1:26389", "127.0.0.1:26379");

Redisson redisson = Redisson.create(config);

Lock lock = redisson.getLock("anyLock");
try {
  // unlock automatically after 10 seconds of hold
  lock.lock(10, TimeUnit.SECONDS);

} finally {
  lock.unlock();
}

...

redisson.shutdown();

代码示例来源:origin: org.redisson/redisson

public RedissonSortedSet(Codec codec, CommandExecutor commandExecutor, String name, Redisson redisson) {
  super(codec, commandExecutor, name);
  this.commandExecutor = commandExecutor;
  comparatorHolder = redisson.getBucket(getComparatorKeyName(), StringCodec.INSTANCE);
  lock = redisson.getLock("redisson_sortedset_lock:{" + getName() + "}");
  list = (RedissonList<V>) redisson.getList(getName(), codec);
  loadComparator();
}

相关文章