package edu.ustc.mix.persistence.redis;

import org.redisson.Config;
import org.redisson.Redisson;
import org.redisson.core.RBucket;

public class RedissonClient {
	
	public static void main(String[] args) {
		
		Config config = new Config();
		config.useClusterServers().setScanInterval(2000) // sets cluster state scan interval
		    .addNodeAddress("127.0.0.1:7000", "127.0.0.1:7001", "127.0.0.1:7002")
		    .addNodeAddress("127.0.0.1:7003", "127.0.0.1:7004", "127.0.0.1:7005");
		
		Redisson redisson = Redisson.create(config);
		
		RBucket<Integer> bucket = redisson.getBucket("test");
		bucket.set(6379);
		
		System.out.println(bucket.get());
	}
}

@@ -34,16 +34,139 @@
 redis;%0A%0A
+import java.util.concurrent.ExecutorService;%0Aimport java.util.concurrent.Executors;%0Aimport java.util.concurrent.TimeUnit;%0A%0A
 import o
@@ -248,16 +248,48 @@
 RBucket;
+%0Aimport org.redisson.core.RLock;
 %0A%0Apublic
@@ -760,19 +760,16 @@
 (6379);%0A
-%09%09%0A
 %09%09System
@@ -796,13 +796,904 @@
 get());%0A
+%09%09%0A%09%09concurrentLock(redisson);%0A%09%7D%0A%09%0A%09private static void concurrentLock(final Redisson redisson) %7B%0A%09%09%0A%09%09try %7B%0A%09%09%09Integer nThreads = 10;%0A%09%09%09ExecutorService pool = Executors.newFixedThreadPool(nThreads);%0A%09%09%09%0A%09%09%09for (int i = 0; i %3C nThreads; i++) %7B%0A%09%09%09%09%0A%09%09%09%09pool.submit(new Runnable() %7B%0A%09%09%09%09%09%0A%09%09%09%09%09@Override%0A%09%09%09%09%09public void run() %7B%0A%09%09%09%09%09%09%0A%09%09%09%09%09%09RLock lock = redisson.getLock(%22123456%22);%0A%09%09%09%09%09%09%0A%09%09%09%09%09%09try %7B%0A%09%09%09%09%09%09%09if (lock.tryLock(10, TimeUnit.SECONDS)) %7B%0A%09%09%09%09%09%09%09%09Thread.sleep(1000 * 10);%0A%09%09%09%09%09%09%09%09System.out.println(Thread.currentThread() + %22##### first time locked #####%22);%0A%09%09%09%09%09%09%09%7D else %7B%0A%09%09%09%09%09%09%09%09System.out.println(Thread.currentThread() + %22##### already locked #####%22);%0A%09%09%09%09%09%09%09%7D%0A%09%09%09%09%09%09%7D catch (Exception e) %7B%0A%09%09%09%09%09%09%09e.printStackTrace();%0A%09%09%09%09%09%09%7D%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D);%0A%09%09%09%7D%0A%09%09%09%0A%09%09%09pool.shutdown();%0A%09%09%09pool.awaitTermination(60, TimeUnit.SECONDS);%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A
 %09%7D%0A%7D%0A

implement distributed lock by redisson