redis.clients.jedis.BitPosParams Java Examples

The following examples show how to use redis.clients.jedis.BitPosParams. 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: BitCommandsTest.java    From cachecloud with Apache License 2.0 6 votes vote down vote up
@Test
public void bitposWithNoMatchingBitExistWithinRange() {
  String foo = "foo";

  jedis.set(foo, String.valueOf(0));
  for (int idx = 0; idx < 8 * 5; idx++) {
    jedis.setbit(foo, idx, true);
  }

  /*
   * byte: 0 1 2 3 4 bit: 11111111 / 11111111 / 11111111 / 11111111 / 11111111
   */
  long offset = jedis.bitpos(foo, false, new BitPosParams(2, 3));
  // offset should be -1
  assertEquals(-1, offset);
}
 
Example #2
Source File: EnhancedJedisCluster.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
@Override
public Long bitpos(final String key, final boolean value, final BitPosParams params) {
	checkArgumentsSpecification(key);
	return new EnhancedJedisClusterCommand<Long>(connectionHandler, maxAttempts) {
		@Override
		public Long doExecute(Jedis connection) {
			return connection.bitpos(key, value, params);
		}
	}.run(key);
}
 
Example #3
Source File: TracingJedisCluster.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Override
public Long bitpos(String key, boolean value, BitPosParams params) {
  Span span = helper.buildSpan("bitpos", key);
  span.setTag("value", value);
  span.setTag("params", TracingHelper.toString(params.getParams()));
  try {
    return super.bitpos(key, value, params);
  } catch (Exception e) {
    onError(e, span);
    throw e;
  } finally {
    span.finish();
  }
}
 
Example #4
Source File: BaseRedisClient.java    From search-commons with Apache License 2.0 5 votes vote down vote up
@Override
public long bitPos(final String key, final boolean value, final long byteStart, final long byteEnd) {
    return runTask(new Task<J, Long>() {
        @Override
        public Long run(J jedis) {
            BitPosParams params = byteEnd < 0 ? new BitPosParams(byteStart) : new BitPosParams(byteStart, byteEnd);
            Long ret = jedis.bitpos(key, value, params);
            if (ret == null || ret < 0) return -1L;
            else return ret;
        }
    });
}
 
Example #5
Source File: BitCommandsTest.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Test
public void bitpos() {
  String foo = "foo";

  jedis.set(foo, String.valueOf(0));

  jedis.setbit(foo, 3, true);
  jedis.setbit(foo, 7, true);
  jedis.setbit(foo, 13, true);
  jedis.setbit(foo, 39, true);

  /*
   * byte: 0 1 2 3 4 bit: 00010001 / 00000100 / 00000000 / 00000000 / 00000001
   */
  long offset = jedis.bitpos(foo, true);
  assertEquals(2, offset);
  offset = jedis.bitpos(foo, false);
  assertEquals(0, offset);

  offset = jedis.bitpos(foo, true, new BitPosParams(1));
  assertEquals(13, offset);
  offset = jedis.bitpos(foo, false, new BitPosParams(1));
  assertEquals(8, offset);

  offset = jedis.bitpos(foo, true, new BitPosParams(2, 3));
  assertEquals(-1, offset);
  offset = jedis.bitpos(foo, false, new BitPosParams(2, 3));
  assertEquals(16, offset);

  offset = jedis.bitpos(foo, true, new BitPosParams(3, 4));
  assertEquals(39, offset);
}
 
Example #6
Source File: BitCommandsTest.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Test
public void bitposBinary() {
  // binary
  byte[] bfoo = { 0x01, 0x02, 0x03, 0x04 };

  jedis.set(bfoo, Protocol.toByteArray(0));

  jedis.setbit(bfoo, 3, true);
  jedis.setbit(bfoo, 7, true);
  jedis.setbit(bfoo, 13, true);
  jedis.setbit(bfoo, 39, true);

  /*
   * byte: 0 1 2 3 4 bit: 00010001 / 00000100 / 00000000 / 00000000 / 00000001
   */
  long offset = jedis.bitpos(bfoo, true);
  assertEquals(2, offset);
  offset = jedis.bitpos(bfoo, false);
  assertEquals(0, offset);

  offset = jedis.bitpos(bfoo, true, new BitPosParams(1));
  assertEquals(13, offset);
  offset = jedis.bitpos(bfoo, false, new BitPosParams(1));
  assertEquals(8, offset);

  offset = jedis.bitpos(bfoo, true, new BitPosParams(2, 3));
  assertEquals(-1, offset);
  offset = jedis.bitpos(bfoo, false, new BitPosParams(2, 3));
  assertEquals(16, offset);

  offset = jedis.bitpos(bfoo, true, new BitPosParams(3, 4));
  assertEquals(39, offset);
}
 
Example #7
Source File: JedisSentinel.java    From conductor with Apache License 2.0 4 votes vote down vote up
@Override
public Long bitpos(String key, boolean value, BitPosParams params) {
    try (Jedis jedis = jedisPool.getResource()) {
        return jedis.bitpos(key, value, params);
    }
}
 
Example #8
Source File: JedisCluster.java    From conductor with Apache License 2.0 4 votes vote down vote up
@Override
public Long bitpos(String key, boolean value, BitPosParams params) {
    throw new UnsupportedOperationException();
}
 
Example #9
Source File: DefaultRedis.java    From craft-atom with MIT License 4 votes vote down vote up
private Long bitpos0(Jedis j, String key, boolean value, long start) {
	return j.bitpos(key, value, new BitPosParams(start));
}
 
Example #10
Source File: DefaultRedis.java    From craft-atom with MIT License 4 votes vote down vote up
private Long bitpos0(Jedis j, String key, boolean value, long start, long end) {
	return j.bitpos(key, value, new BitPosParams(start, end));
}