+ rename RedisKeyStore to KeyBound

+ add default implementations for BoundListOperations & co
+ wire RedisOperations into RedisTemplate
This commit is contained in:
Costin Leau
2010-11-12 18:40:31 +02:00
parent 7d151cc7aa
commit c3b3c8c79c
5 changed files with 167 additions and 3 deletions

View File

@@ -22,7 +22,7 @@ import java.util.List;
*
* @author Costin Leau
*/
public interface BoundListOperations<K, V> extends RedisKeyedStore<K> {
public interface BoundListOperations<K, V> extends KeyBound<K> {
List<V> range(int start, int end);

View File

@@ -0,0 +1,79 @@
/*
* 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.List;
/**
* Default implementation for {@link BoundListOperations}.
*
* @author Costin Leau
*/
public class DefaultBoundListOperations<K, V> extends DefaultKeyBound<K> implements BoundListOperations<K, V> {
private final ListOperations<K, V> ops;
public DefaultBoundListOperations(K key, RedisTemplate<K, V> template) {
super(key);
this.ops = template.listOps();
}
@Override
public V index(int index) {
throw new UnsupportedOperationException();
}
@Override
public V leftPop() {
throw new UnsupportedOperationException();
}
@Override
public Integer leftPush(V value) {
throw new UnsupportedOperationException();
}
@Override
public Integer length() {
throw new UnsupportedOperationException();
}
@Override
public List<V> range(int start, int end) {
throw new UnsupportedOperationException();
}
@Override
public Integer remove(int i, Object value) {
throw new UnsupportedOperationException();
}
@Override
public V rightPop() {
throw new UnsupportedOperationException();
}
@Override
public Integer rightPush(V value) {
throw new UnsupportedOperationException();
}
@Override
public void trim(int start, int end) {
throw new UnsupportedOperationException();
}
}

View File

@@ -0,0 +1,36 @@
/*
* 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;
/**
* Default {@link KeyBound} implementation.
*
* @author Costin Leau
*/
public class DefaultKeyBound<K> implements KeyBound<K> {
private final K key;
public DefaultKeyBound(K key) {
this.key = key;
}
@Override
public K getKey() {
return key;
}
}

View File

@@ -20,7 +20,7 @@ package org.springframework.datastore.redis.core;
*
* @author Costin Leau
*/
public interface RedisKeyedStore<K> {
public interface KeyBound<K> {
/**
* Returns the key associated with this store.

View File

@@ -44,7 +44,7 @@ import org.springframework.util.ClassUtils;
*
* @author Costin Leau
*/
public class RedisTemplate<K, V> extends RedisAccessor {
public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperations<K, V> {
private boolean exposeConnection = false;
private RedisSerializer keySerializer = new StringRedisSerializer();
@@ -179,4 +179,53 @@ public class RedisTemplate<K, V> extends RedisAccessor {
}
}
}
//
// RedisOperations
//
@Override
public Object exec() {
throw new UnsupportedOperationException();
}
@Override
public BoundListOperations<K, V> forList(K key) {
return new DefaultBoundListOperations<K, V>(key, this);
}
@Override
public V get(K key) {
throw new UnsupportedOperationException();
}
@Override
public V getSet(K key, V newValue) {
throw new UnsupportedOperationException();
}
@Override
public V increment(K key, int delta) {
throw new UnsupportedOperationException();
}
@Override
public ListOperations<K, V> listOps() {
throw new UnsupportedOperationException();
}
@Override
public void multi() {
throw new UnsupportedOperationException();
}
@Override
public void set(K key, V value) {
throw new UnsupportedOperationException();
}
@Override
public void watch(K key) {
throw new UnsupportedOperationException();
}
}