Commit c26127b5 authored by wangwei's avatar wangwei

增加根据template作为参数写入布隆方法

parent e1b35b0b
...@@ -38,7 +38,7 @@ allprojects { ...@@ -38,7 +38,7 @@ allprojects {
} }
group = "cn.com.duiba.boot" group = "cn.com.duiba.boot"
version = "0.0.36" version = "0.0.37-SNAPSHOT"
} }
subprojects { subprojects {
......
...@@ -104,6 +104,24 @@ public class RedisBloomHandler<K, V> { ...@@ -104,6 +104,24 @@ public class RedisBloomHandler<K, V> {
}, true); }, true);
} }
public Boolean addString(String key, String value) {
byte[] rawKey = rawString(key);
byte[] rawValue = rawString(value);
return (Boolean) redisTemplate.execute(connection -> {
Long l = (Long) connection.execute(ADD, rawKey, rawValue);
return Objects.equals(l, 1L);
}, true);
}
public Boolean addString(RedisTemplate redisTemplate, String key, String value) {
byte[] rawKey = rawString(key);
byte[] rawValue = rawString(value);
return (Boolean) redisTemplate.execute(connection -> {
Long l = (Long) connection.execute(ADD, rawKey, rawValue);
return Objects.equals(l, 1L);
}, true);
}
public Boolean[] addMulti(K key, V... values) { public Boolean[] addMulti(K key, V... values) {
byte[][] rawArgs = rawArgs(key, values); byte[][] rawArgs = rawArgs(key, values);
return (Boolean[]) redisTemplate.execute(connection -> { return (Boolean[]) redisTemplate.execute(connection -> {
...@@ -141,6 +159,13 @@ public class RedisBloomHandler<K, V> { ...@@ -141,6 +159,13 @@ public class RedisBloomHandler<K, V> {
return redisTemplate.hasKey(key); return redisTemplate.hasKey(key);
} }
public Boolean hasBloom(RedisTemplate redisTemplate, K key) {
if (redisTemplate == null) {
redisTemplate = this.redisTemplate;
}
return redisTemplate.hasKey(key);
}
byte[] rawKey(Object key) { byte[] rawKey(Object key) {
Assert.notNull(key, "non null key required"); Assert.notNull(key, "non null key required");
return this.keySerializer() == null && key instanceof byte[] ? (byte[]) ((byte[]) key) : this.keySerializer().serialize(key); return this.keySerializer() == null && key instanceof byte[] ? (byte[]) ((byte[]) key) : this.keySerializer().serialize(key);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment