+ add (Bound)SetOperations

This commit is contained in:
Costin Leau
2010-11-15 13:36:06 +01:00
parent c909de1fb8
commit 8efc827559
4 changed files with 200 additions and 2 deletions

View File

@@ -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<K, V> extends KeyBound<K> {
Set<V> diff(K... keys);
void diffAndStore(K destKey, K... keys);
RedisOperations<K, V> getOperations();
Set<V> intersect(K... keys);
void intersectAndStore(K destKey, K... keys);
Set<V> union(K... keys);
void unionAndStore(K destKey, K... keys);
Boolean add(V value);
boolean isMember(Object o);
Set<V> members();
boolean remove(Object o);
int size();
}

View File

@@ -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<K, V> extends DefaultKeyBound<K> implements BoundSetOperations<K, V> {
private final SetOperations<K, V> ops;
DefaultBoundSetOperations(K key, RedisTemplate<K, V> template) {
super(key);
this.ops = template.setOps();
}
@Override
public Boolean add(V value) {
return ops.add(getKey(), value);
}
@Override
public Set<V> diff(K... keys) {
return ops.diff(getKey(), keys);
}
@Override
public void diffAndStore(K destKey, K... keys) {
ops.diffAndStore(getKey(), destKey, keys);
}
@Override
public RedisOperations<K, V> getOperations() {
return ops.getOperations();
}
@Override
public Set<V> 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<V> 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<V> union(K... keys) {
return ops.union(getKey(), keys);
}
@Override
public void unionAndStore(K destKey, K... keys) {
ops.unionAndStore(getKey(), destKey, keys);
}
}

View File

@@ -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<K, V> {
Set<V> diff(K key, K... keys);
void diffAndStore(K key, K destKey, K... keys);
RedisOperations<K, V> getOperations();
Set<V> intersect(K key, K... keys);
void intersectAndStore(K key, K destKey, K... keys);
Set<V> 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<V> members(K key);
boolean remove(K key, Object o);
int size(K key);
}

View File

@@ -66,7 +66,7 @@ public class DefaultRedisMap implements RedisMap {
* Constructs a new <code>DefaultRedisMap</code> 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;
}