Package redis.clients.jedis

Examples of redis.clients.jedis.ZParams


  jedis.zadd("foo", 1, "a");
  jedis.zadd("foo", 2, "b");
  jedis.zadd("bar", 2, "a");
  jedis.zadd("bar", 2, "b");

  ZParams params = new ZParams();
  params.weights(2, 2.5);
  params.aggregate(ZParams.Aggregate.SUM);
  long result = jedis.zunionstore("dst", params, "foo", "bar");

  assertEquals(2, result);

  Set<Tuple> expected = new LinkedHashSet<Tuple>();
  expected.add(new Tuple("b", new Double(9)));
  expected.add(new Tuple("a", new Double(7)));

  assertEquals(expected, jedis.zrangeWithScores("dst", 0, 100));

  // Binary
  jedis.zadd(bfoo, 1, ba);
  jedis.zadd(bfoo, 2, bb);
  jedis.zadd(bbar, 2, ba);
  jedis.zadd(bbar, 2, bb);

  ZParams bparams = new ZParams();
  bparams.weights(2, 2.5);
  bparams.aggregate(ZParams.Aggregate.SUM);
  long bresult = jedis.zunionstore(SafeEncoder.encode("dst"), bparams,
    bfoo, bbar);

  assertEquals(2, bresult);
View Full Code Here


    public void zintertoreParams() {
  jedis.zadd("foo", 1, "a");
  jedis.zadd("foo", 2, "b");
  jedis.zadd("bar", 2, "a");

  ZParams params = new ZParams();
  params.weights(2, 2.5);
  params.aggregate(ZParams.Aggregate.SUM);
  long result = jedis.zinterstore("dst", params, "foo", "bar");

  assertEquals(1, result);

  Set<Tuple> expected = new LinkedHashSet<Tuple>();
  expected.add(new Tuple("a", new Double(7)));

  assertEquals(expected, jedis.zrangeWithScores("dst", 0, 100));

  // Binary
  jedis.zadd(bfoo, 1, ba);
  jedis.zadd(bfoo, 2, bb);
  jedis.zadd(bbar, 2, ba);

  ZParams bparams = new ZParams();
  bparams.weights(2, 2.5);
  bparams.aggregate(ZParams.Aggregate.SUM);
  long bresult = jedis.zinterstore(SafeEncoder.encode("dst"), bparams,
    bfoo, bbar);

  assertEquals(1, bresult);
View Full Code Here

  }

  @Override
  public Long zInterStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) {
    try {
      ZParams zparams = new ZParams().weights(weights).aggregate(
          redis.clients.jedis.ZParams.Aggregate.valueOf(aggregate.name()));

      if (isQueueing()) {
        transaction.zinterstore(destKey, zparams, sets);
        return null;
View Full Code Here

  }

  @Override
  public Long zUnionStore(byte[] destKey, Aggregate aggregate, int[] weights, byte[]... sets) {
    try {
      ZParams zparams = new ZParams().weights(weights).aggregate(
          redis.clients.jedis.ZParams.Aggregate.valueOf(aggregate.name()));

      if (isQueueing()) {
        transaction.zunionstore(destKey, zparams, sets);
        return null;
View Full Code Here

        Transaction trans = conn.multi();
        trans.zremrangeByScore(
            semname.getBytes(),
            "-inf".getBytes(),
            String.valueOf(now - timeout).getBytes());
        ZParams params = new ZParams();
        params.weights(1, 0);
        trans.zinterstore(czset, params, czset, semname);
        trans.incr(ctr);
        List<Object> results = trans.exec();
        int counter = ((Long)results.get(results.size() - 1)).intValue();
View Full Code Here

        int voteWeight = weights.containsKey("vote") ? weights.get("vote") : 0;

        String[] keys = new String[]{id, "sort:update", "sort:votes"};
        Transaction trans = conn.multi();
        id = zintersect(
            trans, ttl, new ZParams().weights(0, updateWeight, voteWeight), keys);

        trans.zcard("idx:" + id);
        if (desc) {
            trans.zrevrange("idx:" + id, start, start + num - 1);
        }else{
View Full Code Here

        Transaction trans = conn.multi();

        String matchedAds = matchLocation(trans, locations);

        String baseEcpm = zintersect(
            trans, 30, new ZParams().weights(0, 1), matchedAds, "ad:value:");

        Pair<Set<String>,String> result = finishScoring(
            trans, matchedAds, baseEcpm, content);

        trans.incr("ads:served:");
View Full Code Here

    {
        Map<String,Integer> bonusEcpm = new HashMap<String,Integer>();
        Set<String> words = tokenize(content);
        for (String word : words){
            String wordBonus = zintersect(
                trans, 30, new ZParams().weights(0, 1), matched, word);
            bonusEcpm.put(wordBonus, 1);
        }

        if (bonusEcpm.size() > 0){

            String[] keys = new String[bonusEcpm.size()];
            int[] weights = new int[bonusEcpm.size()];
            int index = 0;
            for (Map.Entry<String,Integer> bonus : bonusEcpm.entrySet()){
                keys[index] = bonus.getKey();
                weights[index] = bonus.getValue();
                index++;
            }

            ZParams minParams = new ZParams().aggregate(ZParams.Aggregate.MIN).weights(weights);
            String minimum = zunion(trans, 30, minParams, keys);

            ZParams maxParams = new ZParams().aggregate(ZParams.Aggregate.MAX).weights(weights);
            String maximum = zunion(trans, 30, maxParams, keys);

            String result = zunion(
                trans, 30, new ZParams().weights(2, 1, 1), base, minimum, maximum);
            return new Pair<Set<String>,String>(words, result);
        }
        return new Pair<Set<String>,String>(words, base);
    }
View Full Code Here

            weights[i] = 1;
        }

        Transaction trans = conn.multi();
        String jobScores = zunion(
            trans, 30, new ZParams().weights(weights), keys);
        String finalResult = zintersect(
            trans, 30, new ZParams().weights(-1, 1), jobScores, "jobs:req");
        trans.exec();

        return conn.zrangeByScore("idx:" + finalResult, 0, 0);
    }
View Full Code Here

        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

TOP

Related Classes of redis.clients.jedis.ZParams

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.