Examples of ShardedJedis


Examples of redis.clients.jedis.ShardedJedis

  shards.add(new JedisShardInfo(new URI(
    "redis://:foobared@localhost:6379")));

  ShardedJedisPool pool = new ShardedJedisPool(config, shards);

  ShardedJedis jedis = pool.getResource();
  jedis.set("pipelined", String.valueOf(0));
  jedis.set("pipelined2", String.valueOf(0));

  ShardedJedisPipeline pipeline = jedis.pipelined();

  pipeline.incr("pipelined");
  pipeline.incr("pipelined2");

  jedis.resetState();

  pipeline = jedis.pipelined();
  pipeline.incr("pipelined");
  pipeline.incr("pipelined2");
  List<Object> results = pipeline.syncAndReturnAll();

  assertEquals(2, results.size());
View Full Code Here

Examples of redis.clients.jedis.ShardedJedis

  shards.add(new JedisShardInfo(new URI(
    "redis://:foobared@localhost:6379")));

  ShardedJedisPool pool = new ShardedJedisPool(config, shards);

  ShardedJedis jedis = pool.getResource();
  try {
      jedis.set("hello", "jedis");
  } finally {
      jedis.close();
  }

  ShardedJedis jedis2 = pool.getResource();
  try {
      assertEquals(jedis, jedis2);
  } finally {
      jedis2.close();
  }
    }
View Full Code Here

Examples of redis.clients.jedis.ShardedJedis

    @Test
    public void checkSharding() {
  List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
  shards.add(new JedisShardInfo(redis1.getHost(), redis1.getPort()));
  shards.add(new JedisShardInfo(redis2.getHost(), redis2.getPort()));
  ShardedJedis jedis = new ShardedJedis(shards);
  List<String> keys = getKeysDifferentShard(jedis);
  JedisShardInfo s1 = jedis.getShardInfo(keys.get(0));
  JedisShardInfo s2 = jedis.getShardInfo(keys.get(1));
  assertNotSame(s1, s2);
    }
View Full Code Here

Examples of redis.clients.jedis.ShardedJedis

  si.setPassword("foobared");
  shards.add(si);
  si = new JedisShardInfo(redis2.getHost(), redis2.getPort());
  si.setPassword("foobared");
  shards.add(si);
  ShardedJedis jedis = new ShardedJedis(shards);
  jedis.set("a", "bar");
  JedisShardInfo s1 = jedis.getShardInfo("a");
  jedis.set("b", "bar1");
  JedisShardInfo s2 = jedis.getShardInfo("b");
  jedis.disconnect();

  Jedis j = new Jedis(s1.getHost(), s1.getPort());
  j.auth("foobared");
  assertEquals("bar", j.get("a"));
  j.disconnect();
View Full Code Here

Examples of redis.clients.jedis.ShardedJedis

  si.setPassword("foobared");
  shards.add(si);
  si = new JedisShardInfo(redis2.getHost(), redis2.getPort());
  si.setPassword("foobared");
  shards.add(si);
  ShardedJedis jedis = new ShardedJedis(shards, Hashing.MURMUR_HASH);
  jedis.set("a", "bar");
  JedisShardInfo s1 = jedis.getShardInfo("a");
  jedis.set("b", "bar1");
  JedisShardInfo s2 = jedis.getShardInfo("b");
  jedis.disconnect();

  Jedis j = new Jedis(s1.getHost(), s1.getPort());
  j.auth("foobared");
  assertEquals("bar", j.get("a"));
  j.disconnect();
View Full Code Here

Examples of redis.clients.jedis.ShardedJedis

    @Test
    public void checkKeyTags() {
  List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
  shards.add(new JedisShardInfo(redis1.getHost(), redis1.getPort()));
  shards.add(new JedisShardInfo(redis2.getHost(), redis2.getPort()));
  ShardedJedis jedis = new ShardedJedis(shards,
    ShardedJedis.DEFAULT_KEY_TAG_PATTERN);

  assertEquals(jedis.getKeyTag("foo"), "foo");
  assertEquals(jedis.getKeyTag("foo{bar}"), "bar");
  assertEquals(jedis.getKeyTag("foo{bar}}"), "bar"); // default pattern is
  // non greedy
  assertEquals(jedis.getKeyTag("{bar}foo"), "bar"); // Key tag may appear
  // anywhere
  assertEquals(jedis.getKeyTag("f{bar}oo"), "bar"); // Key tag may appear
  // anywhere

  JedisShardInfo s1 = jedis.getShardInfo("abc{bar}");
  JedisShardInfo s2 = jedis.getShardInfo("foo{bar}");
  assertSame(s1, s2);

  List<String> keys = getKeysDifferentShard(jedis);
  JedisShardInfo s3 = jedis.getShardInfo(keys.get(0));
  JedisShardInfo s4 = jedis.getShardInfo(keys.get(1));
  assertNotSame(s3, s4);

  ShardedJedis jedis2 = new ShardedJedis(shards);

  assertEquals(jedis2.getKeyTag("foo"), "foo");
  assertNotSame(jedis2.getKeyTag("foo{bar}"), "bar");

  JedisShardInfo s5 = jedis2.getShardInfo(keys.get(0) + "{bar}");
  JedisShardInfo s6 = jedis2.getShardInfo(keys.get(1) + "{bar}");
  assertNotSame(s5, s6);
    }
View Full Code Here

Examples of redis.clients.jedis.ShardedJedis

  shards.add(new JedisShardInfo(redis1.getHost(), redis1.getPort()));
  shards.add(new JedisShardInfo(redis2.getHost(), redis2.getPort()));
  shards.get(0).setPassword("foobared");
  shards.get(1).setPassword("foobared");

  ShardedJedis jedisShard = new ShardedJedis(shards);
  try {
      jedisShard.set("shard_closeable", "true");
  } finally {
      jedisShard.close();
  }

  for (Jedis jedis : jedisShard.getAllShards()) {
      assertTrue(!jedis.isConnected());
  }
    }
View Full Code Here

Examples of redis.clients.jedis.ShardedJedis

  shard.setPassword("foobared");
  shards.add(shard);
  shard = new JedisShardInfo(hnp2.getHost(), hnp2.getPort());
  shard.setPassword("foobared");
  shards.add(shard);
  ShardedJedis jedis = new ShardedJedis(shards);
  Collection<Jedis> allShards = jedis.getAllShards();
  for (Jedis j : allShards) {
      j.flushAll();
  }

  long begin = Calendar.getInstance().getTimeInMillis();

  for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
      String key = "foo" + n;
      jedis.set(key, "bar" + n);
      jedis.get(key);
  }

  long elapsed = Calendar.getInstance().getTimeInMillis() - begin;

  jedis.disconnect();

  System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops");
    }
View Full Code Here

Examples of redis.clients.jedis.ShardedJedis

      RedisSortedSetPersistence redisP = RedisSortedSetPersistence.getInstance();
      try{

           
        boolean brokenJedis = false;
            ShardedJedis jedis = null;
            int shard = 0;
           
            try {
                long ts1 = System.currentTimeMillis();
                jedis = redisP.getResource();
                Long clearNum = jedis.del(ralativeUrl + "-" + shard + "-" + CQSConstants.REDIS_STATE);
                logger.debug("num removed=" + clearNum);
                clearNum = jedis.del(ralativeUrl + "-" + shard + "-Q");
                logger.debug("num removed=" + clearNum);
                clearNum = jedis.del(ralativeUrl + "-" + shard + "-F");
                logger.debug("num removed=" + clearNum);
                long ts2 = System.currentTimeMillis();
                CQSControllerServlet.valueAccumulator.addToCounter(AccumulatorName.RedisTime, (ts2 - ts1));
                logger.debug("event=cleared_queue queue_url=" + queueUrl + " shard=" + shard);
            } catch (JedisConnectionException e) {
View Full Code Here

Examples of redis.clients.jedis.ShardedJedis

   public Map<String, String> sendMessageBatch(CQSQueue queue, int shard, List<CQSMessage> messages) throws PersistenceException, IOException, InterruptedException, NoSuchAlgorithmException, JSONException {

     persistenceStorage.sendMessageBatch(queue, shard, messages);
     Map<String, String> memIds = new HashMap<String, String>();
     boolean cacheAvailable = checkCacheConsistency(queue.getRelativeUrl(), shard, true);//set in cache even if its filling
     ShardedJedis jedis = null;

     if (cacheAvailable) {
       try {
         jedis = getResource();
       } catch (JedisConnectionException e) {
         cacheAvailable = false;
         trySettingCacheState(queue.getRelativeUrl(), shard, QCacheState.Unavailable);
       }
     }
     // add messages in the same order as messages list
     boolean brokenJedis = false;
     long ts1 = System.currentTimeMillis();
     try {
       for (CQSMessage message : messages) {
         int delaySeconds = 0;
         if (queue.getDelaySeconds() > 0) {
           delaySeconds = queue.getDelaySeconds();
         }
         if (message.getAttributes().containsKey(CQSConstants.DELAY_SECONDS)) {
           delaySeconds = Integer.parseInt(message.getAttributes().get(CQSConstants.DELAY_SECONDS));
         }
         String clientId = message.getSuppliedMessageId();
         String messageId = message.getMessageId();
         String memId = getMemQueueMessage(messageId);
         if (cacheAvailable) {     
           try {
             jedis.zadd(queue.getRelativeUrl() + "-" + shard + "-Q", System.currentTimeMillis() + (delaySeconds * 1000), memId); //insert or update already existing
             //expire old message
             jedis.zremrangeByScore(queue.getRelativeUrl() + "-" + shard + "-Q","-inf",String.valueOf(System.currentTimeMillis() -
                 (queue.getMsgRetentionPeriod() * 1000)));
           } catch (JedisConnectionException e) {
             trySettingCacheState(queue.getRelativeUrl(), shard, QCacheState.Unavailable);
           }
           logger.debug("event=send_message_batch cache_available=true msg_id= " + memId + " queue_url=" + queue.getAbsoluteUrl() + " shard=" + shard);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.