Skip to content

Commit

Permalink
修改init方法异常
Browse files Browse the repository at this point in the history
  • Loading branch information
linfeng committed Jun 29, 2020
1 parent 031de24 commit 0d5a3d6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>com.github.slacrey</groupId>
<artifactId>redisson-extend</artifactId>
<version>1.1.2150</version>
<version>1.2.2150</version>
<name>redisson-extend</name>
<description>redisson extend</description>

Expand Down
16 changes: 11 additions & 5 deletions src/main/java/org/redisson/RedissonCountingBloomFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ private ReadResult readData(long[] hashes) {
return initCheckResult(true, resultBoolArray);

} catch (RedisException e) {
if (!e.getMessage().contains("Counting Bloom filter config has been changed")) {
if (!e.getMessage().contains("Bloom filter config has been changed")) {
throw e;
}
}
Expand All @@ -227,7 +227,7 @@ private Boolean writeData(long[] hashes, Boolean[] writeValue) {
RBitSetAsync bs = createBitSet(executorService);
for (long[] index : indexes) {
for (int j = 0; j < maxCount; j++) {
bs.setAsync(index[j], writeValue[j]);
bs.setAsync(index[j], writeValue[j] == null ? false : writeValue[j]);
}
}
try {
Expand Down Expand Up @@ -385,7 +385,7 @@ public boolean tryInit(long expectedInsertions, double falseProbability) {
try {
executorService.execute();
} catch (RedisException e) {
if (!e.getMessage().contains("Counting Bloom filter config has been changed")) {
if (!e.getMessage().contains("Bloom filter config has been changed")) {
throw e;
}
readConfig();
Expand Down Expand Up @@ -464,29 +464,35 @@ public boolean success() {
@Override
public Boolean[] increase() {

if (resultList == null) {
return new Boolean[maxBinaryBit];
}
String binary = Arrays.stream(resultList)
.map(item -> Boolean.TRUE.equals(item) ? "1" : "0")
.collect(Collectors.joining());
int resultInt = Integer.parseInt(binary, 2);

int increaseInt = resultInt + 1;
if (increaseInt > maxRepeat) {
return new Boolean[0];
return new Boolean[maxBinaryBit];
}
return addBinary2Array(resultList, defaultList);
}

@Override
public Boolean[] subtract() {

if (resultList == null) {
return new Boolean[maxBinaryBit];
}
String binary = Arrays.stream(resultList)
.map(item -> Boolean.TRUE.equals(item) ? "1" : "0")
.collect(Collectors.joining());
int resultInt = Integer.parseInt(binary, 2);

int subtractInt = resultInt - 1;
if (subtractInt < 0) {
return new Boolean[0];
return new Boolean[maxBinaryBit];
}
return subBinary2Array(resultList, defaultList);
}
Expand Down
10 changes: 6 additions & 4 deletions src/test/java/org/redisson/RedissonExtendTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@ public static void main(String[] args) {
// RBloomFilter<String> bloomFilter = redissonClientExtend.getBloomFilter("test1");
RCountingBloomFilter<String> bloomFilter = redissonClientExtend.getCountingBloomFilter("test2", 3);

bloomFilter.delete();
bloomFilter.tryInit(10000, 0.0001D);
// bloomFilter.delete();
bloomFilter.tryInit(1000, 0.001D);
bloomFilter.tryInit(1000, 0.001D);

long startTime = System.currentTimeMillis();
for (int i=0;i<1000;i++) {
for (int i=0;i<100;i++) {
bloomFilter.add("test1" + i);
}
long endTime = System.currentTimeMillis();
System.out.println("add time:" + (endTime - startTime));

startTime = System.currentTimeMillis();
for (int i=0; i< 1000; i++) {
for (int i=0; i< 100; i++) {
bloomFilter.contains("test1" + i);
}
endTime = System.currentTimeMillis();
Expand Down

0 comments on commit 0d5a3d6

Please sign in to comment.