当前位置: 首页>>代码示例>>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;未经允许,请勿转载。