diff --git a/pom.xml b/pom.xml index 00cf712..357a1fa 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ com.github.slacrey redisson-extend - 1.1.2150 + 1.2.2150 redisson-extend redisson extend diff --git a/src/main/java/org/redisson/RedissonCountingBloomFilter.java b/src/main/java/org/redisson/RedissonCountingBloomFilter.java index ca591fc..1ac59b9 100644 --- a/src/main/java/org/redisson/RedissonCountingBloomFilter.java +++ b/src/main/java/org/redisson/RedissonCountingBloomFilter.java @@ -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; } } @@ -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 { @@ -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(); @@ -464,6 +464,9 @@ 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()); @@ -471,7 +474,7 @@ public Boolean[] increase() { int increaseInt = resultInt + 1; if (increaseInt > maxRepeat) { - return new Boolean[0]; + return new Boolean[maxBinaryBit]; } return addBinary2Array(resultList, defaultList); } @@ -479,6 +482,9 @@ public Boolean[] increase() { @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()); @@ -486,7 +492,7 @@ public Boolean[] subtract() { int subtractInt = resultInt - 1; if (subtractInt < 0) { - return new Boolean[0]; + return new Boolean[maxBinaryBit]; } return subBinary2Array(resultList, defaultList); } diff --git a/src/test/java/org/redisson/RedissonExtendTest.java b/src/test/java/org/redisson/RedissonExtendTest.java index 5020b0d..b2bdd19 100644 --- a/src/test/java/org/redisson/RedissonExtendTest.java +++ b/src/test/java/org/redisson/RedissonExtendTest.java @@ -21,17 +21,19 @@ public static void main(String[] args) { // RBloomFilter bloomFilter = redissonClientExtend.getBloomFilter("test1"); RCountingBloomFilter 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();