Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jreids ZINTERSTORE , ZUNIONSTORE wrong result #56

Closed
sarowlwp opened this issue Aug 2, 2011 · 2 comments
Closed

jreids ZINTERSTORE , ZUNIONSTORE wrong result #56

sarowlwp opened this issue Aug 2, 2011 · 2 comments

Comments

@sarowlwp
Copy link

sarowlwp commented Aug 2, 2011

zinterstore can set up weight params , but when i set { 2 , 3 } as weights for two zset ,it return wrong result

REDIS OFFICE Examples
redis> ZADD zset1 1 "one"
(integer) 1redis> ZADD zset1 2 "two"
(integer) 1redis> ZADD zset2 1 "one"
(integer) 1redis> ZADD zset2 2 "two"
(integer) 1redis> ZADD zset2 3 "three"
(integer) 1redis> ZUNIONSTORE out 2 zset1 zset2 WEIGHTS 2 3
(integer) 3redis> ZRANGE out 0 -1 WITHSCORES

  1. "one"
  2. "5"
  3. "three"
  4. "9"
  5. "two"
  6. "10"

mytestcode:

public void testJREDIS() {
Jedis ir = new Jedis("192.168.105.218");
ir.del("testZUNIONSTORE1");
ir.del("testZUNIONSTORE2");
ir.del("testZUNIONSTOREout");

    ir.zadd("testZUNIONSTORE1", 1, "ONE");
    ir.zadd("testZUNIONSTORE1", 2, "TWO");
    ir.zadd("testZUNIONSTORE2", 2, "ONE");
    ir.zadd("testZUNIONSTORE2", 4, "TWO");
    String[] keys = new String[2];
    keys[1] = "testZUNIONSTORE1";
    keys[0] = "testZUNIONSTORE2";

    ZParams Op_params = new ZParams();
    Op_params.aggregate(ZParams.Aggregate.SUM);
    Op_params.weights(new int[]{2,3});
    ir.zunionstore("testZUNIONSTOREout", Op_params, keys);

    Map <String ,Double> scores1 = new LinkedHashMap<String,Double>();
    scores1.put("ONE", 8.0 = 1*2 + 2*3);    //jredis return 7 = 1*3 + 2*2
    scores1.put("TWO", 16.0 = 2*2 + 4*3); //jredis return 14 = 2*3 + 4*2

    assertEquals(scores1,ir.zrangeWithScores("testZUNIONSTOREout", 0, -1));
    ir.del("testZUNIONSTORE1");
    ir.del("testZUNIONSTORE2");
    ir.del("testZUNIONSTOREout");

}
@sarowlwp
Copy link
Author

sarowlwp commented Aug 2, 2011

可以用中文吗

@sarowlwp sarowlwp closed this as completed Aug 2, 2011
@alphazero
Copy link
Owner

可以 文吗 Farsi ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants