Java Code Examples for redis.clients.jedis.SortingParams#limit()

The following examples show how to use redis.clients.jedis.SortingParams#limit() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SortingCommandsTest.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Test
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);
  bexpected.add(b2);
  bexpected.add(b3);

  assertEquals(bexpected, bresult);
}
 
Example 2
Source File: DefaultRedis.java    From craft-atom with MIT License 5 votes vote down vote up
private List<String> sort_offset_count_alpha_desc(Jedis j, String key, int offset, int count, boolean alpha, boolean desc) {
	SortingParams sp = new SortingParams();
	if (desc) {
		sp.desc();
	}
	if (alpha) { 
		sp.alpha() ;
	}
	sp.limit(offset, count);
	
	return j.sort(key, sp);
}
 
Example 3
Source File: DefaultRedis.java    From craft-atom with MIT License 5 votes vote down vote up
private List<String> sort_by_offset_count_get(Jedis j, String key, String bypattern, int offset, int count, String... getpatterns) {
	SortingParams sp = new SortingParams();
	sp.by(bypattern);
	sp.get(getpatterns);
	sp.limit(offset, count);
	return j.sort(key, sp);
}
 
Example 4
Source File: DefaultRedis.java    From craft-atom with MIT License 5 votes vote down vote up
private List<String> sort_by_offset_count_alpha_desc_get(Jedis j, String key, String bypattern, int offset, int count, boolean alpha, boolean desc, String... getpatterns) {
	SortingParams sp = new SortingParams();
	sp.by(bypattern);
	sp.get(getpatterns);
	sp.limit(offset, count);
	if (alpha) {
		sp.alpha();
	}
	if (desc) {
		sp.desc();
	}
	
	return j.sort(key, sp);
}
 
Example 5
Source File: DefaultRedis.java    From craft-atom with MIT License 5 votes vote down vote up
private Long sort_offset_count_alpha_desc_destination(Jedis j, String key, int offset, int count, boolean alpha, boolean desc, String destination) {
	SortingParams sp = new SortingParams();
	sp.limit(offset, count);
	if (desc) {
		sp.desc();
	}
	if (alpha) {
		sp.alpha();
	}
	return j.sort(key, sp, destination);
}
 
Example 6
Source File: DefaultRedis.java    From craft-atom with MIT License 5 votes vote down vote up
private Long sort_by_offset_count_destination_get(Jedis j, String key, String bypattern, int offset, int count, String destination, String... getpatterns) {
	SortingParams sp = new SortingParams();
	sp.by(bypattern);
	sp.get(getpatterns);
	sp.limit(offset, count);
	
	return j.sort(key, sp, destination);
}
 
Example 7
Source File: DefaultRedis.java    From craft-atom with MIT License 5 votes vote down vote up
private Long sort_by_offset_count_alpha_desc_destination_get(Jedis j, String key, String bypattern, int offset, int count, boolean alpha, boolean desc, String destination, String... getpatterns) {
	SortingParams sp = new SortingParams();
	sp.by(bypattern);
	sp.get(getpatterns);
	sp.limit(offset, count);
	if (alpha) {
		sp.alpha();
	}
	if (desc) {
		sp.desc();
	}
	
	return j.sort(key, sp, destination);
}
 
Example 8
Source File: DefaultRedisTransaction.java    From craft-atom with MIT License 5 votes vote down vote up
private void sort_offset_count_alpha_desc(String key, int offset, int count, boolean alpha, boolean desc) {
	SortingParams sp = new SortingParams();
	if (desc) {
		sp.desc();
	}
	if (alpha) { 
		sp.alpha() ;
	}
	sp.limit(offset, count);
	
	t.sort(key, sp);
}
 
Example 9
Source File: DefaultRedisTransaction.java    From craft-atom with MIT License 5 votes vote down vote up
private void sort_by_offset_count_get(String key, String bypattern, int offset, int count, String... getpatterns) {
	SortingParams sp = new SortingParams();
	sp.by(bypattern);
	sp.get(getpatterns);
	sp.limit(offset, count);
	t.sort(key, sp);
}
 
Example 10
Source File: DefaultRedisTransaction.java    From craft-atom with MIT License 5 votes vote down vote up
private void sort_by_offset_count_alpha_desc_get(String key, String bypattern, int offset, int count, boolean alpha, boolean desc, String... getpatterns) {
	SortingParams sp = new SortingParams();
	sp.by(bypattern);
	sp.get(getpatterns);
	sp.limit(offset, count);
	if (alpha) {
		sp.alpha();
	}
	if (desc) {
		sp.desc();
	}
	
	t.sort(key, sp);
}
 
Example 11
Source File: DefaultRedisTransaction.java    From craft-atom with MIT License 5 votes vote down vote up
private void sort_offset_count_alpha_desc_destination(String key, int offset, int count, boolean alpha, boolean desc, String destination) {
	SortingParams sp = new SortingParams();
	sp.limit(offset, count);
	if (desc) {
		sp.desc();
	}
	if (alpha) {
		sp.alpha();
	}
	t.sort(key, sp, destination);
}
 
Example 12
Source File: DefaultRedisTransaction.java    From craft-atom with MIT License 5 votes vote down vote up
private void sort_by_offset_count_destination_get(String key, String bypattern, int offset, int count, String destination, String... getpatterns) {
	SortingParams sp = new SortingParams();
	sp.by(bypattern);
	sp.get(getpatterns);
	sp.limit(offset, count);
	
	t.sort(key, sp, destination);
}
 
Example 13
Source File: DefaultRedisTransaction.java    From craft-atom with MIT License 5 votes vote down vote up
private void sort_by_offset_count_alpha_desc_destination_get(String key, String bypattern, int offset, int count, boolean alpha, boolean desc, String destination, String... getpatterns) {
	SortingParams sp = new SortingParams();
	sp.by(bypattern);
	sp.get(getpatterns);
	sp.limit(offset, count);
	if (alpha) {
		sp.alpha();
	}
	if (desc) {
		sp.desc();
	}
	
	t.sort(key, sp, destination);
}
 
Example 14
Source File: SomeOperate.java    From Redis_Learning with Apache License 2.0 4 votes vote down vote up
public static void ListOperate(Jedis jedis, ShardedJedis shardedJedis) {

		System.out.println("===================list=======================");
		System.out.println("��տ����������ݣ�" + jedis.flushDB());

		System.out.println("=============��=============");
		// rpush(key, value)��������Ϊkey��listβ���һ��ֵΪvalue��Ԫ��
		// lpush(key, value)��������Ϊkey��listͷ���һ��ֵΪvalue��Ԫ��
		shardedJedis.lpush("stringlists", "vector");
		shardedJedis.lpush("stringlists", "ArrayList");
		shardedJedis.lpush("stringlists", "vector");
		shardedJedis.lpush("stringlists", "vector");
		shardedJedis.lpush("stringlists", "LinkedList");
		shardedJedis.lpush("stringlists", "MapList");
		shardedJedis.lpush("stringlists", "SerialList");
		shardedJedis.lpush("stringlists", "HashList");
		shardedJedis.rpush("stringlists", "TestList");
		shardedJedis.lpush("numberlists", "3");
		shardedJedis.lpush("numberlists", "1");
		shardedJedis.lpush("numberlists", "5");
		shardedJedis.lpush("numberlists", "2");

		// lrange(key, start, end)����������Ϊkey��list��start��end֮���Ԫ��
		System.out.println("����Ԫ��-stringlists��"
				+ shardedJedis.lrange("stringlists", 0, -1));
		System.out.println("����Ԫ��-numberlists��"
				+ shardedJedis.lrange("numberlists", 0, -1));
		System.out.println("=============ɾ=============");
		// lrem(key, count, value)��ɾ��count��key��list��ֵΪvalue��Ԫ��
		// ���ڶ�������Ϊɾ���ĸ���,�����ظ�ʱ����count>0ʱ����ͷ��β��˳��ɾ���������ڳ�ջ��
		// ��count<0ʱ������β��ͷ��˳��ɾ����count=0ʱ��ɾ��ȫ��
		System.out.println("�ɹ�ɾ��ָ��Ԫ�ظ���-stringlists��"
				+ shardedJedis.lrem("stringlists", 2, "vector"));
		System.out.println("ɾ��ָ��Ԫ��֮��-stringlists��"
				+ shardedJedis.lrange("stringlists", 0, -1));
		// ��ȡָ�����������
		System.out.println("ɾ���±�0-3����֮���Ԫ�أ�"
				+ shardedJedis.ltrim("stringlists", 0, 3));
		System.out.println("ɾ��ָ������֮��Ԫ�غ�-stringlists��"
				+ shardedJedis.lrange("stringlists", 0, -1));
		// lpop(key)�����ز�ɾ������Ϊkey��list�е���Ԫ��
		// rpop(key)�����ز�ɾ������Ϊkey��list�е�βԪ��
		System.out.println("��ջԪ�أ�" + shardedJedis.lpop("stringlists"));
		System.out.println("Ԫ�س�ջ��-stringlists��"
				+ shardedJedis.lrange("stringlists", 0, -1));

		System.out.println("=============��=============");
		// �޸��б���ָ���±��ֵ
		shardedJedis.lset("stringlists", 0, "hello list!");
		System.out.println("�±�Ϊ0��ֵ�޸ĺ�-stringlists��"
				+ shardedJedis.lrange("stringlists", 0, -1));

		System.out.println("=============��=============");
		// llen(key)����������Ϊkey��list�ij���
		System.out
				.println("����-stringlists��" + shardedJedis.llen("stringlists"));
		System.out
				.println("����-numberlists��" + shardedJedis.llen("numberlists"));
		// lindex(key, index)����������Ϊkey��list��indexλ�õ�Ԫ��
		System.out.println("stringlists�е�����Ԫ�أ� "
				+ shardedJedis.lindex("stringlists", 2));

		// ����
		/*
		 * list�д��ַ���ʱ����ָ������Ϊalpha�������ʹ��SortingParams������ֱ��ʹ��sort("list")��
		 * �����"ERR One or more scores can't be converted into double"
		 */
		SortingParams sortingParameters = new SortingParams();
		sortingParameters.alpha();// ���ֵ�������
		// limit(int start, int count) ���Ʒ���Ԫ�صĸ���
		sortingParameters.limit(0, 3);
		System.out.println("���������Ľ��-stringlists��"
				+ shardedJedis.sort("stringlists", sortingParameters));
		System.out.println("���������Ľ��-numberlists��"
				+ shardedJedis.sort("numberlists"));
		// �Ӵ��� startΪԪ���±꣬endҲΪԪ���±ꣻ-1������һ��Ԫ�أ�-2�������ڶ���Ԫ��
		// ע�⣺��Ȼ�Ƚ�����������������˴���Ȼ�������ԭ���Ĵ洢˳��
		System.out.println("�Ӵ�-�ڶ�����ʼ��������"
				+ shardedJedis.lrange("stringlists", 1, -1) + "\n");
	}
 
Example 15
Source File: DefaultRedis.java    From craft-atom with MIT License 4 votes vote down vote up
private Long sort_offset_count_destination(Jedis j, String key, int offset, int count, String destination) {
	SortingParams sp = new SortingParams();
	sp.limit(offset, count);
	return j.sort(key, sp, destination);
}
 
Example 16
Source File: DefaultRedisTransaction.java    From craft-atom with MIT License 4 votes vote down vote up
private void sort_offset_count_destination(String key, int offset, int count, String destination) {
	SortingParams sp = new SortingParams();
	sp.limit(offset, count);
	t.sort(key, sp, destination);
}