diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundHashOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundHashOperations.java new file mode 100644 index 000000000..fe954333b --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/BoundHashOperations.java @@ -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 extends KeyBound { + + +} diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundHashOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundHashOperations.java new file mode 100644 index 000000000..44a726fc7 --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundHashOperations.java @@ -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 extends DefaultKeyBound implements BoundHashOperations { + + /** + * Constructs a new DefaultBoundHashOperations instance. + * + * @param key + */ + public DefaultBoundHashOperations(K key) { + super(key); + } +} diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundListOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundListOperations.java index a2c576305..b2a413cc0 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundListOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/DefaultBoundListOperations.java @@ -26,54 +26,65 @@ import java.util.List; public class DefaultBoundListOperations extends DefaultKeyBound implements BoundListOperations { private final ListOperations ops; - + public DefaultBoundListOperations(K key, RedisTemplate template) { super(key); this.ops = template.listOps(); } - + + + @Override + public RedisOperations 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 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); } } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/HashOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/HashOperations.java new file mode 100644 index 000000000..865876da6 --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/HashOperations.java @@ -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 { + + +} diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java index 4aaa99039..06646c329 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisOperations.java @@ -50,4 +50,8 @@ public interface RedisOperations { ZSetOperations zSetOps(); BoundZSetOperations forZSet(K key); + + HashOperations hashOps(); + + BoundHashOperations forHash(K key); } diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java index b232cbe9e..5f82effc8 100644 --- a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/core/RedisTemplate.java @@ -850,4 +850,23 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation }, true); } } + + + // + // Hash Operations + // + + @Override + public BoundHashOperations forHash(K key) { + return new DefaultBoundHashOperations(key); + } + + @Override + public HashOperations hashOps() { + return new DefaultHashOperations(); + } + + private class DefaultHashOperations implements HashOperations { + + } } \ No newline at end of file diff --git a/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/DefaultRedisMap.java b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/DefaultRedisMap.java new file mode 100644 index 000000000..8c304b0ca --- /dev/null +++ b/spring-data-redis/src/main/java/org/springframework/data/keyvalue/redis/util/DefaultRedisMap.java @@ -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 implements RedisMap { + + private final BoundHashOperations hashOps; + + public DefaultRedisMap(String key, RedisOperations operations) { + this.hashOps = operations.forHash(key); + } + + public DefaultRedisMap(BoundHashOperations 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 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> entrySet() { + throw new UnsupportedOperationException(); + } + + @Override + public V get(Object key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean isEmpty() { + throw new UnsupportedOperationException(); + } + + @Override + public Set keySet() { + throw new UnsupportedOperationException(); + } + + @Override + public V put(K key, V value) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map m) { + throw new UnsupportedOperationException(); + } + + @Override + public V remove(Object key) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + throw new UnsupportedOperationException(); + } + + @Override + public Collection values() { + throw new UnsupportedOperationException(); + } +} \ No newline at end of file