+ introduce hash operations

+ introduce redis map implementation
This commit is contained in:
Costin Leau
2010-11-26 19:52:28 +02:00
parent 1ad4c1d72b
commit 73ddd2637b
7 changed files with 249 additions and 11 deletions

View File

@@ -0,0 +1,24 @@
/*
* 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.data.keyvalue.redis.core;
/**
* @author Costin Leau
*/
public interface BoundHashOperations<K, HF, HV> extends KeyBound<K> {
}

View File

@@ -0,0 +1,33 @@
/*
* 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.data.keyvalue.redis.core;
/**
* Default implementation for {@link HashOperations}.
*
* @author Costin Leau
*/
class DefaultBoundHashOperations<K, HF, HV> extends DefaultKeyBound<K> implements BoundHashOperations<K, HF, HV> {
/**
* Constructs a new <code>DefaultBoundHashOperations</code> instance.
*
* @param key
*/
public DefaultBoundHashOperations(K key) {
super(key);
}
}

View File

@@ -26,54 +26,65 @@ import java.util.List;
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 RedisOperations<K, V> getOperations() {
return ops.getOperations();
}
@Override
public V index(int index) {
throw new UnsupportedOperationException();
return ops.index(getKey(), index);
}
@Override
public V leftPop() {
throw new UnsupportedOperationException();
return ops.leftPop(getKey());
}
@Override
public Integer leftPush(V value) {
throw new UnsupportedOperationException();
return ops.leftPush(getKey(), value);
}
@Override
public Integer length() {
throw new UnsupportedOperationException();
return ops.length(getKey());
}
@Override
public List<V> range(int start, int end) {
throw new UnsupportedOperationException();
return ops.range(getKey(), start, end);
}
@Override
public Integer remove(int i, Object value) {
throw new UnsupportedOperationException();
return ops.remove(getKey(), i, value);
}
@Override
public V rightPop() {
throw new UnsupportedOperationException();
return ops.rightPop(getKey());
}
@Override
public Integer rightPush(V value) {
throw new UnsupportedOperationException();
return ops.rightPush(getKey(), value);
}
@Override
public void trim(int start, int end) {
throw new UnsupportedOperationException();
ops.trim(getKey(), start, end);
}
@Override
public void set(int index, V value) {
ops.set(getKey(), index, value);
}
}

View File

@@ -0,0 +1,26 @@
/*
* 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.data.keyvalue.redis.core;
/**
* Redis map specific operations working on a hash.
*
* @author Costin Leau
*/
public interface HashOperations<HF, HV> {
}

View File

@@ -50,4 +50,8 @@ public interface RedisOperations<K, V> {
ZSetOperations<K, V> zSetOps();
BoundZSetOperations<K, V> forZSet(K key);
<HF, HV> HashOperations<HF, HV> hashOps();
<HF, HV> BoundHashOperations<K, HF, HV> forHash(K key);
}

View File

@@ -850,4 +850,23 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
}, true);
}
}
//
// Hash Operations
//
@Override
public <HF, HV> BoundHashOperations<K, HF, HV> forHash(K key) {
return new DefaultBoundHashOperations<K, HF, HV>(key);
}
@Override
public <HF, HV> HashOperations<HF, HV> hashOps() {
return new DefaultHashOperations<HF, HV>();
}
private class DefaultHashOperations<HF, HV> implements HashOperations<HF, HV> {
}
}

View File

@@ -0,0 +1,121 @@
/*
* 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.data.keyvalue.redis.util;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import org.springframework.data.keyvalue.redis.core.BoundHashOperations;
import org.springframework.data.keyvalue.redis.core.RedisOperations;
/**
* Default implementation for {@link RedisMap}.
*
* @author Costin Leau
*/
public class DefaultRedisMap<K, V> implements RedisMap<K, V> {
private final BoundHashOperations<String, K, V> hashOps;
public DefaultRedisMap(String key, RedisOperations<String, ?> operations) {
this.hashOps = operations.forHash(key);
}
public DefaultRedisMap(BoundHashOperations<String, K, V> boundOps) {
this.hashOps = boundOps;
}
@Override
public Integer increment(K key, int delta) {
throw new UnsupportedOperationException();
}
@Override
public boolean putIfAbsent(K key, V value) {
throw new UnsupportedOperationException();
}
@Override
public String getKey() {
throw new UnsupportedOperationException();
}
@Override
public RedisOperations<String, ?> getOperations() {
throw new UnsupportedOperationException();
}
@Override
public void clear() {
throw new UnsupportedOperationException();
}
@Override
public boolean containsKey(Object key) {
throw new UnsupportedOperationException();
}
@Override
public boolean containsValue(Object value) {
throw new UnsupportedOperationException();
}
@Override
public Set<java.util.Map.Entry<K, V>> entrySet() {
throw new UnsupportedOperationException();
}
@Override
public V get(Object key) {
throw new UnsupportedOperationException();
}
@Override
public boolean isEmpty() {
throw new UnsupportedOperationException();
}
@Override
public Set<K> keySet() {
throw new UnsupportedOperationException();
}
@Override
public V put(K key, V value) {
throw new UnsupportedOperationException();
}
@Override
public void putAll(Map<? extends K, ? extends V> m) {
throw new UnsupportedOperationException();
}
@Override
public V remove(Object key) {
throw new UnsupportedOperationException();
}
@Override
public int size() {
throw new UnsupportedOperationException();
}
@Override
public Collection<V> values() {
throw new UnsupportedOperationException();
}
}