當前位置: 首頁>>代碼示例>>Java>>正文


Java JedisCluster.set方法代碼示例

本文整理匯總了Java中redis.clients.jedis.JedisCluster.set方法的典型用法代碼示例。如果您正苦於以下問題:Java JedisCluster.set方法的具體用法?Java JedisCluster.set怎麽用?Java JedisCluster.set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在redis.clients.jedis.JedisCluster的用法示例。


在下文中一共展示了JedisCluster.set方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import redis.clients.jedis.JedisCluster; //導入方法依賴的package包/類
@SuppressWarnings("resource")
public static void main(String[] args) {
	
	Set<HostAndPort> nodes = new HashSet<HostAndPort>();
	nodes.add(new HostAndPort("127.0.0.1", 7000));
	nodes.add(new HostAndPort("127.0.0.1", 7001));
	nodes.add(new HostAndPort("127.0.0.1", 7002));
	nodes.add(new HostAndPort("127.0.0.1", 7003));
	nodes.add(new HostAndPort("127.0.0.1", 7004));
	nodes.add(new HostAndPort("127.0.0.1", 7005));
	
	JedisCluster cluster = new JedisCluster(nodes, 5000);
	
	System.out.println(cluster.get("foo"));
	
	cluster.set("test", "6379");
	System.out.println(cluster.get("test"));
	
	Map<String, String> inviteePhone = new HashMap<String, String>();
	inviteePhone.put("inviterID", "1001");
	inviteePhone.put("status", "0");
	cluster.hmset("inviteePhone", inviteePhone);
	
	System.out.println(cluster.hget("inviteePhone", "inviterID"));
	System.out.println(cluster.hget("inviteePhone", "status"));
}
 
開發者ID:colddew,項目名稱:mix-web,代碼行數:27,代碼來源:RedisClusterClient.java

示例2: testCalculateConnectionPerSlot

import redis.clients.jedis.JedisCluster; //導入方法依賴的package包/類
@Test
public void testCalculateConnectionPerSlot() {
  Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
  jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
  JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, DEFAULT_REDIRECTIONS, "cluster", DEFAULT_CONFIG);
  jc.set("foo", "bar");
  jc.set("test", "test");
  assertEquals("bar", node3.get("foo"));
  assertEquals("test", node2.get("test"));
  
  JedisCluster jc2 = new JedisCluster(new HostAndPort("127.0.0.1", 7379), DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, DEFAULT_REDIRECTIONS, "cluster", DEFAULT_CONFIG);
  jc2.set("foo", "bar");
  jc2.set("test", "test");
  assertEquals("bar", node3.get("foo"));
  assertEquals("test", node2.get("test"));
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:17,代碼來源:JedisClusterTest.java

示例3: testStableSlotWhenMigratingNodeOrImportingNodeIsNotSpecified

import redis.clients.jedis.JedisCluster; //導入方法依賴的package包/類
@Test
public void testStableSlotWhenMigratingNodeOrImportingNodeIsNotSpecified()
    throws InterruptedException {
  Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
  jedisClusterNode.add(new HostAndPort(nodeInfo1.getHost(), nodeInfo1.getPort()));
  JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, DEFAULT_REDIRECTIONS, "cluster", DEFAULT_CONFIG);

  int slot51 = JedisClusterCRC16.getSlot("51");
  jc.set("51", "foo");
  // node2 is responsible of taking care of slot51 (7186)

  node3.clusterSetSlotImporting(slot51, JedisClusterTestUtil.getNodeId(node2.clusterNodes()));
  assertEquals("foo", jc.get("51"));
  node3.clusterSetSlotStable(slot51);
  assertEquals("foo", jc.get("51"));

  node2.clusterSetSlotMigrating(slot51, JedisClusterTestUtil.getNodeId(node3.clusterNodes()));
  // assertEquals("foo", jc.get("51")); // it leads Max Redirections
  node2.clusterSetSlotStable(slot51);
  assertEquals("foo", jc.get("51"));
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:22,代碼來源:JedisClusterTest.java

示例4: testCluster

import redis.clients.jedis.JedisCluster; //導入方法依賴的package包/類
/**測試redis集群方案*/
@Test
public void testCluster(){

    Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
    //Jedis Cluster will attempt to discover cluster nodes automatically
    jedisClusterNodes.add(new HostAndPort("192.168.12.90", 7001));
    JedisCluster jc = new JedisCluster(jedisClusterNodes);
    jc.set("foo", "bar");
    String value = jc.get("foo");

    System.out.println(value);
    try {
        jc.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:TomChen001,項目名稱:xmanager,代碼行數:19,代碼來源:SpringRedis.java

示例5: testRecalculateSlotsWhenMoved

import redis.clients.jedis.JedisCluster; //導入方法依賴的package包/類
@Test
public void testRecalculateSlotsWhenMoved() throws InterruptedException {
  Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
  jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
  JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, DEFAULT_REDIRECTIONS, "cluster", DEFAULT_CONFIG);
  int slot51 = JedisClusterCRC16.getSlot("51");
  node2.clusterDelSlots(slot51);
  node3.clusterDelSlots(slot51);
  node3.clusterAddSlots(slot51);

  JedisClusterTestUtil.waitForClusterReady(node1, node2, node3);
  jc.set("51", "foo");
  assertEquals("foo", jc.get("51"));
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:15,代碼來源:JedisClusterTest.java

示例6: testAskResponse

import redis.clients.jedis.JedisCluster; //導入方法依賴的package包/類
@Test
public void testAskResponse() throws InterruptedException {
  Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
  jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
  JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, DEFAULT_REDIRECTIONS, "cluster", DEFAULT_CONFIG);
  int slot51 = JedisClusterCRC16.getSlot("51");
  node3.clusterSetSlotImporting(slot51, JedisClusterTestUtil.getNodeId(node2.clusterNodes()));
  node2.clusterSetSlotMigrating(slot51, JedisClusterTestUtil.getNodeId(node3.clusterNodes()));
  jc.set("51", "foo");
  assertEquals("foo", jc.get("51"));
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:12,代碼來源:JedisClusterTest.java

示例7: testRedisClusterMaxRedirections

import redis.clients.jedis.JedisCluster; //導入方法依賴的package包/類
@Test(expected = JedisClusterMaxRedirectionsException.class)
public void testRedisClusterMaxRedirections() {
  Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
  jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
  JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, DEFAULT_REDIRECTIONS, "cluster", DEFAULT_CONFIG);
  int slot51 = JedisClusterCRC16.getSlot("51");
  // This will cause an infinite redirection loop
  node2.clusterSetSlotMigrating(slot51, JedisClusterTestUtil.getNodeId(node3.clusterNodes()));
  jc.set("51", "foo");
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:11,代碼來源:JedisClusterTest.java

示例8: testClusterCountKeysInSlot

import redis.clients.jedis.JedisCluster; //導入方法依賴的package包/類
@Test
public void testClusterCountKeysInSlot() {
  Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
  jedisClusterNode.add(new HostAndPort(nodeInfo1.getHost(), nodeInfo1.getPort()));
  JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, DEFAULT_REDIRECTIONS, "cluster", DEFAULT_CONFIG);

  for (int index = 0; index < 5; index++) {
    jc.set("foo{bar}" + index, "hello");
  }

  int slot = JedisClusterCRC16.getSlot("foo{bar}");
  assertEquals(DEFAULT_REDIRECTIONS, node1.clusterCountKeysInSlot(slot).intValue());
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:14,代碼來源:JedisClusterTest.java

示例9: testIfPoolConfigAppliesToClusterPools

import redis.clients.jedis.JedisCluster; //導入方法依賴的package包/類
@Test(expected = JedisException.class)
public void testIfPoolConfigAppliesToClusterPools() {
  GenericObjectPoolConfig config = new GenericObjectPoolConfig();
  config.setMaxTotal(0);
  config.setMaxWaitMillis(DEFAULT_TIMEOUT);
  Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
  jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
  JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, DEFAULT_REDIRECTIONS, "cluster", config);
  jc.set("52", "poolTestValue");
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:11,代碼來源:JedisClusterTest.java

示例10: testJedisClusterRunsWithMultithreaded

import redis.clients.jedis.JedisCluster; //導入方法依賴的package包/類
@Test
public void testJedisClusterRunsWithMultithreaded() throws InterruptedException,
    ExecutionException, IOException {
  Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
  jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
  final JedisCluster jc = new JedisCluster(jedisClusterNode, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT, DEFAULT_REDIRECTIONS, "cluster", DEFAULT_CONFIG);
  jc.set("foo", "bar");

  ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 100, 0, TimeUnit.SECONDS,
      new ArrayBlockingQueue<Runnable>(10));
  List<Future<String>> futures = new ArrayList<Future<String>>();
  for (int i = 0; i < 50; i++) {
    executor.submit(new Callable<String>() {
      @Override
      public String call() throws Exception {
        // FIXME : invalidate slot cache from JedisCluster to test
        // random connection also does work
        return jc.get("foo");
      }
    });
  }

  for (Future<String> future : futures) {
    String value = future.get();
    assertEquals("bar", value);
  }

  jc.close();
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:30,代碼來源:JedisClusterTest.java

示例11: foo3

import redis.clients.jedis.JedisCluster; //導入方法依賴的package包/類
@SuppressWarnings("unused")
private static void foo3() {

    System.out.println("TEST JedisCluster ======================================================");

    JedisCluster jc = new JedisCluster(new HostAndPort("127.0.0.1", 6380));
    jc.set("foo", "bar");
    String val = jc.get("foo");
    System.out.println(val);

    jc.set("foo1", "bar");
    jc.set("foo2", "bar");
    jc.set("foo3", "bar");
    jc.set("foo4", "bar");
    jc.set("foo5", "bar");

    jc.del("foo");
    jc.del("foo1");
    jc.del("foo2");
    jc.del("foo3");
    jc.del("foo4");
    jc.del("foo5");

    try {
        jc.close();
    }
    catch (IOException e) {
        e.printStackTrace();
    }
}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:31,代碼來源:DoTestJedisHookProxy.java

示例12: init

import redis.clients.jedis.JedisCluster; //導入方法依賴的package包/類
@Before
public void init() {
	String ip = "192.168.2.160";
	Set<HostAndPort> nodes = new HashSet<>();
	nodes.add(new HostAndPort(ip, 7701));
	nodes.add(new HostAndPort(ip, 7702));
	nodes.add(new HostAndPort(ip, 7703));
	nodes.add(new HostAndPort(ip, 7704));
	nodes.add(new HostAndPort(ip, 7705));
	nodes.add(new HostAndPort(ip, 7706));
	JedisPoolConfig pool = new JedisPoolConfig();
	pool.setMaxTotal(100);
	pool.setFairness(false);
	pool.setNumTestsPerEvictionRun(100);
	pool.setMaxWaitMillis(5000);
	pool.setTestOnBorrow(true);
	jedisCluster = new JedisCluster(nodes, 1000, 1000, 100, null, pool); // maxAttempt必須調大
	jedisCluster.set("test", "test");
	queue = new RedisDelayQueue("com.meipian", "delayqueue", jedisCluster, 60 * 1000,
			new DelayQueueProcessListener() {
				@Override
				public void pushCallback(Message message) {

				}

				@Override
				public void peekCallback(Message message) {
					System.out.println("message----->" + message);
					queue.ack(message.getId());//確認操作。將會刪除消息
				}

				@Override
				public void ackCallback(Message message) {
				}
			});

}
 
開發者ID:MeiPian,項目名稱:delay-queue,代碼行數:38,代碼來源:TestRedisDelayQueue.java

示例13: main

import redis.clients.jedis.JedisCluster; //導入方法依賴的package包/類
/**
 * 如果配置了ip 那麽redis的配置文件裏麵的redis-config的 bind 需要修改成指定的ip
 * redis-trib.rb  create --replicas 1  110.173.28.188:7000 110.173.28.188:7001 110.173.28.188:7002 110.173.28.188:7003 110.173.28.188:7004 110.173.28.188:7005
 * @param args
 */
public static void main(String[] args) {
    Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
    jedisClusterNodes.add(new HostAndPort("110.173.28.188", 7000));
    jedisClusterNodes.add(new HostAndPort("110.173.28.188", 7001));
    jedisClusterNodes.add(new HostAndPort("110.173.28.188", 7002));
    JedisCluster jedisCluster=new JedisCluster(jedisClusterNodes);

    jedisCluster.set("master1","1");
    jedisCluster.set("master2","2");
    jedisCluster.set("master3","3");
}
 
開發者ID:ggj2010,項目名稱:javabase,代碼行數:17,代碼來源:RedisCluster.java

示例14: testCluster

import redis.clients.jedis.JedisCluster; //導入方法依賴的package包/類
public void testCluster(){

        Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
        //Jedis Cluster will attempt to discover cluster nodes automatically
        jedisClusterNodes.add(new HostAndPort("127.0.0.1", 7000));
        JedisCluster jc = new JedisCluster(jedisClusterNodes);
        jc.set("foo", "bar");
        String value = jc.get("foo");
        System.out.println(value);
    }
 
開發者ID:x-hansong,項目名稱:RedisHttpSession,代碼行數:11,代碼來源:RedisHttpSessionTest.java

示例15: main

import redis.clients.jedis.JedisCluster; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
        ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext(new String[]{"bean/*.xml"});
//        RGTRedisClusterService redisClusterService = (RGTRedisClusterService) classPathXmlApplicationContext.getBean("redisClusterService");
//
//        redisClusterService.setString("test", "200");
//        System.out.println(redisClusterService.getString("test"));
        JedisCluster jedisCluster = (JedisCluster) classPathXmlApplicationContext.getBean("jedisCluster");
        jedisCluster.set("test", "200");
        System.out.println(jedisCluster.get("test"));
    }
 
開發者ID:jwpttcg66,項目名稱:redis-game-transaction,代碼行數:11,代碼來源:RedisClusterServiceTest.java


注:本文中的redis.clients.jedis.JedisCluster.set方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。