From 8efc8275591f33c923be6b688b3b29f650a44643 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Mon, 15 Nov 2010 13:36:06 +0100 Subject: [PATCH] + add (Bound)SetOperations --- .../redis/core/BoundSetOperations.java | 51 ++++++++++ .../redis/core/DefaultBoundSetOperations.java | 95 +++++++++++++++++++ .../datastore/redis/core/SetOperations.java | 52 ++++++++++ .../datastore/redis/util/DefaultRedisMap.java | 4 +- 4 files changed, 200 insertions(+), 2 deletions(-) create mode 100644 spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/BoundSetOperations.java create mode 100644 spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/DefaultBoundSetOperations.java create mode 100644 spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/SetOperations.java diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/BoundSetOperations.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/BoundSetOperations.java new file mode 100644 index 000000000..c1afe7f4a --- /dev/null +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/BoundSetOperations.java @@ -0,0 +1,51 @@ +/* + * Copyright 2010 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.datastore.redis.core; + +import java.util.Set; + +/** + * Set operations bound to a certain key. + * + * @author Costin Leau + */ +public interface BoundSetOperations extends KeyBound { + + Set diff(K... keys); + + void diffAndStore(K destKey, K... keys); + + RedisOperations getOperations(); + + Set intersect(K... keys); + + void intersectAndStore(K destKey, K... keys); + + Set union(K... keys); + + void unionAndStore(K destKey, K... keys); + + Boolean add(V value); + + boolean isMember(Object o); + + Set members(); + + boolean remove(Object o); + + int size(); +} diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/DefaultBoundSetOperations.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/DefaultBoundSetOperations.java new file mode 100644 index 000000000..ff9a529ef --- /dev/null +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/DefaultBoundSetOperations.java @@ -0,0 +1,95 @@ +/* + * Copyright 2010 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.datastore.redis.core; + +import java.util.Set; + +/** + * Default implementation for {@link BoundSetOperations}. + * + * @author Costin Leau + */ +class DefaultBoundSetOperations extends DefaultKeyBound implements BoundSetOperations { + + private final SetOperations ops; + + + DefaultBoundSetOperations(K key, RedisTemplate template) { + super(key); + this.ops = template.setOps(); + } + + @Override + public Boolean add(V value) { + return ops.add(getKey(), value); + } + + @Override + public Set diff(K... keys) { + return ops.diff(getKey(), keys); + } + + @Override + public void diffAndStore(K destKey, K... keys) { + ops.diffAndStore(getKey(), destKey, keys); + } + + @Override + public RedisOperations getOperations() { + return ops.getOperations(); + } + + @Override + public Set intersect(K... keys) { + return ops.intersect(getKey(), keys); + } + + @Override + public void intersectAndStore(K destKey, K... keys) { + ops.intersectAndStore(getKey(), destKey, keys); + } + + @Override + public boolean isMember(Object o) { + return ops.isMember(getKey(), o); + } + + @Override + public Set members() { + return ops.members(getKey()); + } + + @Override + public boolean remove(Object o) { + return ops.remove(getKey(), o); + } + + @Override + public int size() { + return ops.size(getKey()); + } + + @Override + public Set union(K... keys) { + return ops.union(getKey(), keys); + } + + @Override + public void unionAndStore(K destKey, K... keys) { + ops.unionAndStore(getKey(), destKey, keys); + } +} \ No newline at end of file diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/SetOperations.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/SetOperations.java new file mode 100644 index 000000000..34dc6e7d4 --- /dev/null +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/SetOperations.java @@ -0,0 +1,52 @@ +/* + * Copyright 2010 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.datastore.redis.core; + +import java.util.Set; + +/** + * Redis set specific operations. + * + * @author Costin Leau + */ +public interface SetOperations { + + Set diff(K key, K... keys); + + void diffAndStore(K key, K destKey, K... keys); + + RedisOperations getOperations(); + + Set intersect(K key, K... keys); + + void intersectAndStore(K key, K destKey, K... keys); + + Set union(K key, K... keys); + + void unionAndStore(K key, K destKey, K... keys); + + Boolean add(K key, V value); + + boolean isMember(K key, Object o); + + Set members(K key); + + boolean remove(K key, Object o); + + int size(K key); + +} diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/util/DefaultRedisMap.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/util/DefaultRedisMap.java index 0cfcb03ee..280b125ed 100644 --- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/util/DefaultRedisMap.java +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/util/DefaultRedisMap.java @@ -66,7 +66,7 @@ public class DefaultRedisMap implements RedisMap { * Constructs a new DefaultRedisMap instance. * * @param key - * @param commands + * @param operations */ public DefaultRedisMap(String key, RedisCommands commands) { this.redisKey = key; @@ -89,7 +89,7 @@ public class DefaultRedisMap implements RedisMap { } @Override - public RedisCommands getCommands() { + public RedisCommands getOperations() { return commands; }