package com.elab.redis.redisson;

import com.elab.redis.RedissonApplication;
import com.elab.redis.config.CacheAutoConfiguration;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.redisson.api.RAtomicLong;
import org.redisson.api.RFuture;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest(
        classes = {RedissonApplication.class, CacheAutoConfiguration.class}
)
public class RedisAutoConfigurationTest {

    @Autowired
    private RedissonClient client;

    /**
     * 同步和异步
     */
    @Test
    public void testApp() throws Exception {
        RAtomicLong longObject = client.getAtomicLong("myLong");
        // 同步执行方式
        longObject.compareAndSet(3, 401);
        // 异步执行方式
        RFuture<Boolean> result = longObject.compareAndSetAsync(3, 401);
        Boolean isLock = result.get();
    }


}