+ improve redis set contract and default implementation

This commit is contained in:
Costin Leau
2010-11-15 11:48:55 +01:00
parent 0adea177c5
commit d5365c146e
2 changed files with 47 additions and 42 deletions

View File

@@ -53,6 +53,11 @@ public class DefaultRedisSet<E> extends AbstractRedisCollection<E> implements Re
boundSetOps = operations.forSet(key);
}
/**
* Constructs a new <code>DefaultRedisSet</code> instance.
*
* @param boundOps
*/
public DefaultRedisSet(BoundSetOperations<String, E> boundOps) {
super(boundOps.getKey(), boundOps.getOperations());
this.boundSetOps = boundOps;
@@ -66,7 +71,7 @@ public class DefaultRedisSet<E> extends AbstractRedisCollection<E> implements Re
@Override
public RedisSet<E> diffAndStore(String destKey, RedisSet<? extends E>... sets) {
boundSetOps.diffAndStore(destKey, extractKeys(sets));
return new DefaultRedisSet(boundSetOps);
return new DefaultRedisSet(boundSetOps.getOperations().forSet(destKey));
}
@Override
@@ -77,7 +82,7 @@ public class DefaultRedisSet<E> extends AbstractRedisCollection<E> implements Re
@Override
public RedisSet<E> intersectAndStore(String destKey, RedisSet<? extends E>... sets) {
boundSetOps.intersectAndStore(destKey, extractKeys(sets));
return new DefaultRedisSet(boundSetOps);
return new DefaultRedisSet(boundSetOps.getOperations().forSet(destKey));
}
@Override
@@ -88,7 +93,7 @@ public class DefaultRedisSet<E> extends AbstractRedisCollection<E> implements Re
@Override
public RedisSet<E> unionAndStore(String destKey, RedisSet<? extends E>... sets) {
boundSetOps.unionAndStore(destKey, extractKeys(sets));
return new DefaultRedisSet(boundSetOps);
return new DefaultRedisSet(boundSetOps.getOperations().forSet(destKey));
}
@Override

View File

@@ -1,39 +1,39 @@
/*
* 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.util;
import java.util.Set;
/**
* Redis extension for the {@link Set} contract. Supports {@link Set} specific
* operations backed by Redis commands.
*
* @author Costin Leau
*/
public interface RedisSet extends RedisStore, Set<String> {
Set<String> intersect(RedisSet... sets);
Set<String> union(RedisSet... sets);
Set<String> diff(RedisSet... sets);
RedisSet intersectAndStore(String destKey, RedisSet... sets);
RedisSet unionAndStore(String destKey, RedisSet... sets);
RedisSet diffAndStore(String destKey, RedisSet... sets);
}
/*
* 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.util;
import java.util.Set;
/**
* Redis extension for the {@link Set} contract. Supports {@link Set} specific
* operations backed by Redis operations.
*
* @author Costin Leau
*/
public interface RedisSet<E> extends RedisStore<String>, Set<E> {
Set<E> intersect(RedisSet<? extends E>... sets);
Set<E> union(RedisSet<? extends E>... sets);
Set<E> diff(RedisSet<? extends E>... sets);
RedisSet<E> intersectAndStore(String destKey, RedisSet<? extends E>... sets);
RedisSet<E> unionAndStore(String destKey, RedisSet<? extends E>... sets);
RedisSet<E> diffAndStore(String destKey, RedisSet<? extends E>... sets);
}