|
|
|
@ -427,14 +427,22 @@ public class RedissonBitSet extends RedissonExpirable implements RBitSet {
|
|
|
|
|
@Override
|
|
|
|
|
public RFuture<Long> lengthAsync() {
|
|
|
|
|
return commandExecutor.evalReadAsync(getRawName(), LongCodec.INSTANCE, RedisCommands.EVAL_LONG,
|
|
|
|
|
"local fromBit = redis.call('bitpos', KEYS[1], 1, -1);"
|
|
|
|
|
+ "local toBit = 8*(fromBit/8 + 1) - fromBit % 8;"
|
|
|
|
|
+ "for i = toBit, fromBit, -1 do "
|
|
|
|
|
+ "if redis.call('getbit', KEYS[1], i) == 1 then "
|
|
|
|
|
+ "return i+1;"
|
|
|
|
|
+ "end;"
|
|
|
|
|
+ "end;" +
|
|
|
|
|
"return fromBit+1",
|
|
|
|
|
"local i = redis.call('bitpos', KEYS[1], 1, -1); "
|
|
|
|
|
+ "local pos = i < 0 and redis.call('bitpos', KEYS[1], 0, -1) or math.floor(i / 8) * 8; "
|
|
|
|
|
+ "while (pos >= 0) "
|
|
|
|
|
+ "do "
|
|
|
|
|
+ "i = redis.call('bitpos', KEYS[1], 1, math.floor(pos / 8), math.floor(pos / 8)); "
|
|
|
|
|
+ "if i < 0 then "
|
|
|
|
|
+ "pos = pos - 8; "
|
|
|
|
|
+ "else "
|
|
|
|
|
+ "for j = pos + 7, pos, -1 do "
|
|
|
|
|
+ "if redis.call('getbit', KEYS[1], j) == 1 then "
|
|
|
|
|
+ "return j + 1; "
|
|
|
|
|
+ "end; "
|
|
|
|
|
+ "end; "
|
|
|
|
|
+ "end; "
|
|
|
|
|
+ "end; "
|
|
|
|
|
+ "return 0; ",
|
|
|
|
|
Collections.<Object>singletonList(getRawName()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|