Package redis.clients.jedis

Examples of redis.clients.jedis.SortingParams


  jedis.set("bar1", "3");
  jedis.set("bar2", "2");
  jedis.set("bar3", "1");

  SortingParams sp = new SortingParams();
  sp.by("bar*");

  List<String> result = jedis.sort("foo", sp);

  List<String> expected = new ArrayList<String>();
  expected.add("3");
  expected.add("2");
  expected.add("1");

  assertEquals(expected, result);

  // Binary
  jedis.lpush(bfoo, b2);
  jedis.lpush(bfoo, b3);
  jedis.lpush(bfoo, b1);

  jedis.set(bbar1, b3);
  jedis.set(bbar2, b2);
  jedis.set(bbar3, b1);

  SortingParams bsp = new SortingParams();
  bsp.by(bbarstar);

  List<byte[]> bresult = jedis.sort(bfoo, bsp);

  List<byte[]> bexpected = new ArrayList<byte[]>();
  bexpected.add(b3);
View Full Code Here


    public void sortDesc() {
  jedis.lpush("foo", "3");
  jedis.lpush("foo", "2");
  jedis.lpush("foo", "1");

  SortingParams sp = new SortingParams();
  sp.desc();

  List<String> result = jedis.sort("foo", sp);

  List<String> expected = new ArrayList<String>();
  expected.add("3");
  expected.add("2");
  expected.add("1");

  assertEquals(expected, result);

  // Binary
  jedis.lpush(bfoo, b3);
  jedis.lpush(bfoo, b2);
  jedis.lpush(bfoo, b1);

  SortingParams bsp = new SortingParams();
  bsp.desc();

  List<byte[]> bresult = jedis.sort(bfoo, bsp);

  List<byte[]> bexpected = new ArrayList<byte[]>();
  bexpected.add(b3);
View Full Code Here

    public void sortLimit() {
  for (int n = 10; n > 0; n--) {
      jedis.lpush("foo", String.valueOf(n));
  }

  SortingParams sp = new SortingParams();
  sp.limit(0, 3);

  List<String> result = jedis.sort("foo", sp);

  List<String> expected = new ArrayList<String>();
  expected.add("1");
  expected.add("2");
  expected.add("3");

  assertEquals(expected, result);

  // Binary
  jedis.rpush(bfoo, new byte[] { (byte) '4' });
  jedis.rpush(bfoo, new byte[] { (byte) '3' });
  jedis.rpush(bfoo, new byte[] { (byte) '2' });
  jedis.rpush(bfoo, new byte[] { (byte) '1' });

  SortingParams bsp = new SortingParams();
  bsp.limit(0, 3);

  List<byte[]> bresult = jedis.sort(bfoo, bsp);

  List<byte[]> bexpected = new ArrayList<byte[]>();
  bexpected.add(b1);
View Full Code Here

    public void sortAlpha() {
  jedis.lpush("foo", "1");
  jedis.lpush("foo", "2");
  jedis.lpush("foo", "10");

  SortingParams sp = new SortingParams();
  sp.alpha();

  List<String> result = jedis.sort("foo", sp);

  List<String> expected = new ArrayList<String>();
  expected.add("1");
  expected.add("10");
  expected.add("2");

  assertEquals(expected, result);

  // Binary
  jedis.lpush(bfoo, b1);
  jedis.lpush(bfoo, b2);
  jedis.lpush(bfoo, b10);

  SortingParams bsp = new SortingParams();
  bsp.alpha();

  List<byte[]> bresult = jedis.sort(bfoo, bsp);

  List<byte[]> bexpected = new ArrayList<byte[]>();
  bexpected.add(b1);
View Full Code Here

  jedis.set("car1", "car1");
  jedis.set("car2", "car2");
  jedis.set("car10", "car10");

  SortingParams sp = new SortingParams();
  sp.get("car*", "bar*");

  List<String> result = jedis.sort("foo", sp);

  List<String> expected = new ArrayList<String>();
  expected.add("car1");
  expected.add("bar1");
  expected.add("car2");
  expected.add("bar2");
  expected.add("car10");
  expected.add("bar10");

  assertEquals(expected, result);

  // Binary
  jedis.lpush(bfoo, b1);
  jedis.lpush(bfoo, b2);
  jedis.lpush(bfoo, b10);

  jedis.set(bbar1, bbar1);
  jedis.set(bbar2, bbar2);
  jedis.set(bbar10, bbar10);

  jedis.set(bcar1, bcar1);
  jedis.set(bcar2, bcar2);
  jedis.set(bcar10, bcar10);

  SortingParams bsp = new SortingParams();
  bsp.get(bcarstar, bbarstar);

  List<byte[]> bresult = jedis.sort(bfoo, bsp);

  List<byte[]> bexpected = new ArrayList<byte[]>();
  bexpected.add(bcar1);
View Full Code Here

  }

  @Override
  protected void command() {
    jedis.select(db);
    SortingParams sp = new SortingParams();
    sp.alpha();
    sp.limit(start, end-start);
    page = jedis.sort(key, sp);
   
  }
View Full Code Here

  }

  @Override
  public List<byte[]> sort(byte[] key, SortParameters params) {

    SortingParams sortParams = JedisUtils.convertSortParams(params);

    try {
      if (isQueueing()) {
        if (sortParams != null) {
          transaction.sort(key, sortParams);
View Full Code Here

  }

  @Override
  public Long sort(byte[] key, SortParameters params, byte[] sortKey) {

    SortingParams sortParams = JedisUtils.convertSortParams(params);

    try {
      if (isQueueing()) {
        if (sortParams != null) {
          transaction.sort(key, sortParams, sortKey);
View Full Code Here

    }
    return result;
  }

  static SortingParams convertSortParams(SortParameters params) {
    SortingParams jedisParams = null;

    if (params != null) {
      jedisParams = new SortingParams();

      byte[] byPattern = params.getByPattern();
      if (byPattern != null) {
        jedisParams.by(params.getByPattern());
      }

      byte[][] getPattern = params.getGetPattern();
      if (getPattern != null) {
        jedisParams.get(getPattern);
      }

      Range limit = params.getLimit();
      if (limit != null) {
        jedisParams.limit((int) limit.getStart(), (int) limit.getCount());
      }
      Order order = params.getOrder();
      if (order != null && order.equals(Order.DESC)) {
        jedisParams.desc();
      }
      Boolean isAlpha = params.isAlphabetic();
      if (isAlpha != null && isAlpha) {
        jedisParams.alpha();
      }
    }

    return jedisParams;
  }
View Full Code Here

        String id = parseAndSearch(conn, queryString, 300);

        Transaction trans = conn.multi();
        trans.scard("idx:" + id);
        SortingParams params = new SortingParams();
        if (desc) {
            params.desc();
        }
        if (alpha){
            params.alpha();
        }
        params.by(by);
        params.limit(0, 20);
        trans.sort("idx:" + id, params);
        List<Object> results = trans.exec();

        return new SearchResult(
            id,
View Full Code Here

TOP

Related Classes of redis.clients.jedis.SortingParams

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.