Package redis.clients.jedis

Examples of redis.clients.jedis.Pipeline


  }

  @Override
  public void invalidateUnreadCount(FeedSubscription... subs) {
    try (Jedis jedis = pool.getResource()) {
      Pipeline pipe = jedis.pipelined();
      if (subs != null) {
        for (FeedSubscription sub : subs) {
          String key = buildRedisUnreadCountKey(sub);
          pipe.del(key);
        }
      }
      pipe.sync();
    }
  }
View Full Code Here


  public List<Object> execute(PipelineAction pipelineAction) throws JedisException {
    Jedis jedis = null;
    boolean broken = false;
    try {
      jedis = jedisPool.getResource();
      Pipeline pipeline = jedis.pipelined();
      pipelineAction.action(pipeline);
      return pipeline.syncAndReturnAll();
    } catch (JedisException e) {
      broken = handleJedisException(e);
      throw e;
    } finally {
      closeResource(jedis, broken);
View Full Code Here

  public void execute(PipelineActionNoResult pipelineAction) throws JedisException {
    Jedis jedis = null;
    boolean broken = false;
    try {
      jedis = jedisPool.getResource();
      Pipeline pipeline = jedis.pipelined();
      pipelineAction.action(pipeline);
      pipeline.sync();
    } catch (JedisException e) {
      broken = handleJedisException(e);
      throw e;
    } finally {
      closeResource(jedis, broken);
View Full Code Here

        }

        Set<Tuple> users = conn.zrangeByScoreWithScores(
            incoming, String.valueOf(start), "inf", 0, REFILL_USERS_STEP);

        Pipeline pipeline = conn.pipelined();
        for (Tuple tuple : users){
            String uid = tuple.getElement();
            start = tuple.getScore();
            pipeline.zrevrangeWithScores(
                "profile:" + uid, 0, HOME_TIMELINE_SIZE - 1);
        }

        List<Object> response = pipeline.syncAndReturnAll();
        List<Tuple> messages = new ArrayList<Tuple>();
        for (Object results : response) {
            messages.addAll((Set<Tuple>)results);
        }
View Full Code Here

        conn.del(key);
        for (int i = 0; i < length; i++) {
            conn.rpush(key, String.valueOf(i));
        }

        Pipeline pipeline = conn.pipelined();
        long time = System.currentTimeMillis();
        for (int p = 0; p < passes; p++) {
            for (int pi = 0; pi < psize; pi++) {
                pipeline.rpoplpush(key, key);
            }
            pipeline.sync();
        }

        return (passes * psize) / (System.currentTimeMillis() - time);
    }
View Full Code Here

        long shardId = userId / USERS_PER_SHARD;
        int position = (int)(userId % USERS_PER_SHARD);
        int offset = position * 2;

        Pipeline pipe = conn.pipelined();
        pipe.setrange("location:" + shardId, offset, code);

        String tkey = UUID.randomUUID().toString();
        pipe.zadd(tkey, userId, "max");
        pipe.zunionstore(
            "location:max",
            new ZParams().aggregate(ZParams.Aggregate.MAX),
            tkey,
            "location:max");
        pipe.del(tkey);
        pipe.sync();
    }
View Full Code Here

        Jedis conn, long[] userIds)
    {
        Map<String,Long> countries = new HashMap<String,Long>();
        Map<String,Map<String,Long>> states = new HashMap<String,Map<String,Long>>();

        Pipeline pipe = conn.pipelined();
        for (int i = 0; i < userIds.length; i++) {
            long userId = userIds[i];
            long shardId = userId / USERS_PER_SHARD;
            int position = (int)(userId % USERS_PER_SHARD);
            int offset = position * 2;

            pipe.substr("location:" + shardId, offset, offset + 1);

            if ((i + 1) % 1000 == 0) {
                updateAggregates(countries, states, pipe.syncAndReturnAll());
            }
        }

        updateAggregates(countries, states, pipe.syncAndReturnAll());

        return new Pair<Map<String,Long>,Map<String,Map<String,Long>>>(countries, states);
    }
View Full Code Here

        logRecent(conn, name, message, INFO);
    }

    public void logRecent(Jedis conn, String name, String message, String severity) {
        String destination = "recent:" + name + ':' + severity;
        Pipeline pipe = conn.pipelined();
        pipe.lpush(destination, TIMESTAMP.format(new Date()) + ' ' + message);
        pipe.ltrim(destination, 0, 99);
        pipe.sync();
    }
View Full Code Here

        }
    }

    public void updateTokenPipeline(Jedis conn, String token, String user, String item) {
        long timestamp = System.currentTimeMillis() / 1000;
        Pipeline pipe = conn.pipelined();
        pipe.hset("login:", token, user);
        pipe.zadd("recent:", timestamp, token);
        if (item != null){
            pipe.zadd("viewed:" + token, timestamp, item);
            pipe.zremrangeByRank("viewed:" + token, 0, -26);
            pipe.zincrby("viewed:", -1, item);
        }
        pipe.exec();
    }
View Full Code Here

     * @param callback executable instance unider Pipeline
     */
    private void runWithPipeline(final JedisPipelinedCallback callback) {
        final Jedis jedis = jedisPool.getResource();
        try {
            final Pipeline pipeline = jedis.pipelined();
            callback.execute(pipeline);
            // use #sync(), not #exec()
            pipeline.sync();
        } finally {
            jedisPool.returnResource(jedis);
        }
    }
View Full Code Here

TOP

Related Classes of redis.clients.jedis.Pipeline

Copyright © 2018 www.massapicom. 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.