Search in sources :

Example 1 with RedissonKeys

use of org.redisson.RedissonKeys 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();
    }
}
Also used : RKeys(org.redisson.api.RKeys) RedissonLock(org.redisson.RedissonLock) RedissonTransactionalLock(org.redisson.transaction.RedissonTransactionalLock) RedissonKeys(org.redisson.RedissonKeys)

Example 2 with RedissonKeys

use of org.redisson.RedissonKeys 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;
}
Also used : RedissonPromise(org.redisson.misc.RedissonPromise) RKeys(org.redisson.api.RKeys) BucketsTrySetOperation(org.redisson.transaction.operation.bucket.BucketsTrySetOperation) RedissonKeys(org.redisson.RedissonKeys) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 3 with RedissonKeys

use of org.redisson.RedissonKeys 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());
}
Also used : RKeys(org.redisson.api.RKeys) RedissonLock(org.redisson.RedissonLock) RedissonKeys(org.redisson.RedissonKeys)

Example 4 with RedissonKeys

use of org.redisson.RedissonKeys 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());
    }
}
Also used : RKeys(org.redisson.api.RKeys) RedissonLock(org.redisson.RedissonLock) RedissonKeys(org.redisson.RedissonKeys)

Aggregations

RedissonKeys (org.redisson.RedissonKeys)4 RKeys (org.redisson.api.RKeys)4 RedissonLock (org.redisson.RedissonLock)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 RedissonPromise (org.redisson.misc.RedissonPromise)1 RedissonTransactionalLock (org.redisson.transaction.RedissonTransactionalLock)1 BucketsTrySetOperation (org.redisson.transaction.operation.bucket.BucketsTrySetOperation)1