1 module RedisClusterDemo; 2 3 import hunt.redis.RedisPoolOptions; 4 5 import hunt.logging.ConsoleLogger; 6 import hunt.util.DateTime; 7 8 import hunt.redis; 9 import std.conv; 10 11 enum string RedisServerHost = "10.1.11.115"; 12 enum int RedisServerPort = 6379; 13 // enum string RedisPassword = "foobared"; 14 enum int DEFAULT_TIMEOUT = 2000; 15 enum int DEFAULT_REDIRECTIONS = 5; 16 17 class RedisClusterBenchmark { 18 19 static void run() { 20 21 Redis node2 = new Redis(new HostAndPort(RedisServerHost, 6380)); 22 // node2.auth(RedisPassword); 23 node2.flushAll(); 24 25 Redis node3 = new Redis(new HostAndPort(RedisServerHost, 6381)); 26 // node3.auth(RedisPassword); 27 node3.flushAll(); 28 29 // 30 RedisPoolOptions DEFAULT_CONFIG = new RedisPoolOptions(); 31 // DEFAULT_CONFIG.password = RedisPassword; 32 DEFAULT_CONFIG.clientName = "cluster-demo"; 33 DEFAULT_CONFIG.connectionTimeout = DEFAULT_TIMEOUT; 34 DEFAULT_CONFIG.soTimeout = DEFAULT_TIMEOUT; 35 36 HostAndPort jedisClusterNode = new HostAndPort(RedisServerHost, RedisServerPort); 37 38 RedisCluster rc = new RedisCluster(jedisClusterNode, DEFAULT_CONFIG); 39 rc.set("foo", "bar"); 40 rc.set("test", "test"); 41 assert("bar" == node3.get("foo")); 42 assert("test" == node2.get("test")); 43 44 RedisCluster rc2 = new RedisCluster(jedisClusterNode, DEFAULT_CONFIG); 45 rc2.set("foo", "bar2"); 46 rc2.set("test", "test2"); 47 48 string foo = node3.get("foo"); 49 warningf("foo=> %s", foo); 50 assert("bar2" == foo); 51 52 string test = node2.get("test"); 53 warningf("test=> %s", test); 54 assert("test2" == test); 55 56 info("Done."); 57 rc.close(); 58 rc2.close(); 59 node2.close(); 60 node3.close(); 61 } 62 }