@SuppressWarnings("unchecked")
    private RFuture<V> getAndSet(V newValue, TransactionalOperation operation) {
        checkState();
        return executeLocked(() -> {
            if (state != null) {
                Object prevValue = Optional.of(state).filter(s -> s != NULL).orElse(null);
                operations.add(operation);
                state = Optional.ofNullable((Object) newValue).orElse(NULL);
                return CompletableFuture.completedFuture((V) prevValue);
            }

            return getAsync().thenApply(res -> {
                state = Optional.ofNullable((Object) newValue).orElse(NULL);
                operations.add(operation);
                return res;
            });
        });
    }
@Test
    public void testGetAndSet() {
        RBucket<String> b = redisson.getBucket("test");
        b.set("123");
        
        RTransaction transaction = redisson.createTransaction(TransactionOptions.defaults());
        RBucket<String> bucket = transaction.getBucket("test");
        assertThat(bucket.getAndSet("0")).isEqualTo("123");
        assertThat(bucket.get()).isEqualTo("0");
        assertThat(bucket.getAndSet("324")).isEqualTo("0");
        
        transaction.commit();
        
        assertThat(redisson.getKeys().count()).isEqualTo(1);
        assertThat(b.get()).isEqualTo("324");
    }