use of org.redisson.api.RKeys in project redisson by redisson.
the class DeleteOperation method commit.
@Override
public void commit(CommandAsyncExecutor commandExecutor) {
RKeys keys = new RedissonKeys(commandExecutor);
keys.deleteAsync(getName());
if (lockName != null) {
RedissonLock lock = new RedissonTransactionalLock(commandExecutor, lockName, transactionId);
lock.unlockAsync();
}
}
use of org.redisson.api.RKeys in project redisson by redisson.
the class RedissonTransactionalBuckets method trySetAsync.
// Add RKeys.deleteAsync support
//
// public RFuture<Long> deleteAsync(String... keys) {
// checkState();
// RPromise<Long> result = new RedissonPromise<>();
// long threadId = Thread.currentThread().getId();
// executeLocked(result, new Runnable() {
// @Override
// public void run() {
// AtomicLong counter = new AtomicLong();
// AtomicLong executions = new AtomicLong(keys.length);
// for (String key : keys) {
// Object st = state.get(key);
// if (st != null) {
// operations.add(new DeleteOperation(key, getLockName(key), transactionId, threadId));
// if (st != NULL) {
// state.put(key, NULL);
// counter.incrementAndGet();
// }
// if (executions.decrementAndGet() == 0) {
// result.trySuccess(counter.get());
// }
// continue;
// }
//
// RedissonKeys ks = new RedissonKeys(commandExecutor);
// ks.countExistsAsync(key).onComplete((res, e) -> {
// if (e != null) {
// result.tryFailure(e);
// return;
// }
//
// if (res > 0) {
// operations.add(new DeleteOperation(key, getLockName(key), transactionId, threadId));
// state.put(key, NULL);
// counter.incrementAndGet();
// }
//
// if (executions.decrementAndGet() == 0) {
// result.trySuccess(counter.get());
// }
// });
// }
// }
// }, Arrays.asList(keys));
// return result;
// }
@Override
public RFuture<Boolean> trySetAsync(Map<String, ?> buckets) {
checkState();
RPromise<Boolean> result = new RedissonPromise<>();
executeLocked(result, () -> {
Set<String> keysToSet = new HashSet<>();
for (String key : buckets.keySet()) {
Object value = state.get(key);
if (value != null) {
if (value != NULL) {
operations.add(new BucketsTrySetOperation(codec, (Map<String, Object>) buckets, transactionId));
result.trySuccess(false);
return;
}
} else {
keysToSet.add(key);
}
}
if (keysToSet.isEmpty()) {
operations.add(new BucketsTrySetOperation(codec, (Map<String, Object>) buckets, transactionId));
state.putAll(buckets);
result.trySuccess(true);
return;
}
RKeys keys = new RedissonKeys(commandExecutor);
String[] ks = keysToSet.toArray(new String[keysToSet.size()]);
keys.countExistsAsync(ks).onComplete((res, e) -> {
if (e != null) {
result.tryFailure(e);
return;
}
operations.add(new BucketsTrySetOperation(codec, (Map<String, Object>) buckets, transactionId));
if (res == 0) {
state.putAll(buckets);
result.trySuccess(true);
} else {
result.trySuccess(false);
}
});
}, buckets.keySet());
return result;
}
use of org.redisson.api.RKeys in project redisson by redisson.
the class TouchOperation method commit.
@Override
public void commit(CommandAsyncExecutor commandExecutor) {
RKeys keys = new RedissonKeys(commandExecutor);
keys.touchAsync(getName());
RedissonLock lock = new RedissonLock(commandExecutor, lockName);
lock.unlockAsync(getThreadId());
}
use of org.redisson.api.RKeys in project redisson by redisson.
the class UnlinkOperation method commit.
@Override
public void commit(CommandAsyncExecutor commandExecutor) {
RKeys keys = new RedissonKeys(commandExecutor);
keys.unlinkAsync(getName());
if (lockName != null) {
RedissonLock lock = new RedissonLock(commandExecutor, lockName);
lock.unlockAsync(getThreadId());
}
}
Aggregations