From 8ed620463f4e6e51fc8139f5d84104e3d84ac793 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Fri, 12 Nov 2010 18:25:49 +0200 Subject: [PATCH] + add more methods to the RedisOperations --- .../redis/core/BoundListOperations.java | 44 ++++++++++++++++ .../datastore/redis/core/ListOperations.java | 50 +++++++++++++++++++ .../datastore/redis/core/RedisKeyedStore.java | 31 ++++++++++++ .../datastore/redis/core/RedisOperations.java | 8 +-- 4 files changed, 129 insertions(+), 4 deletions(-) create mode 100644 spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/BoundListOperations.java create mode 100644 spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/ListOperations.java create mode 100644 spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/RedisKeyedStore.java diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/BoundListOperations.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/BoundListOperations.java new file mode 100644 index 000000000..b2fe714f2 --- /dev/null +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/BoundListOperations.java @@ -0,0 +1,44 @@ +/* + * 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; + +/** + * List operations bound to a certain key. + * + * @author Costin Leau + */ +public interface BoundListOperations extends RedisKeyedStore { + + List range(int start, int end); + + void trim(int start, int end); + + Integer length(); + + Integer leftPush(V value); + + Integer rightPush(V value); + + V leftPop(); + + V rightPop(); + + Integer remove(int i, Object value); + + V index(int index); +} diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/ListOperations.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/ListOperations.java new file mode 100644 index 000000000..8bcf32a55 --- /dev/null +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/ListOperations.java @@ -0,0 +1,50 @@ +/* + * 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; + +/** + * Redis, list specific operations. + * + * @author Costin Leau + */ +public interface ListOperations { + + List range(K key, int start, int end); + + void trim(K key, int start, int end); + + Integer length(K key); + + Integer leftPush(K key, V value); + + Integer rightPush(K key, V value); + + void set(K key, int index, V value); + + Integer remove(K key, int i, Object value); + + V index(K key, int index); + + V leftPop(K key); + + V rightPop(K key); + + V blockingLeftPop(K key); + + V blockingRightPop(K key); +} diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/RedisKeyedStore.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/RedisKeyedStore.java new file mode 100644 index 000000000..59612381a --- /dev/null +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/RedisKeyedStore.java @@ -0,0 +1,31 @@ +/* + * 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; + +/** + * Redis store for a certain key. Useful for creating views into Redis 'collection' types. + * + * @author Costin Leau + */ +public interface RedisKeyedStore { + + /** + * Returns the key associated with this store. + * + * @return + */ + K getKey(); +} diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/RedisOperations.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/RedisOperations.java index 83e0f1f86..d9eab1c2d 100644 --- a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/RedisOperations.java +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/RedisOperations.java @@ -15,6 +15,7 @@ */ package org.springframework.datastore.redis.core; + /** * Basic set of Redis operations, implemented by {@link RedisTemplate}. * @@ -34,10 +35,9 @@ public interface RedisOperations { Object exec(); - V incr(K key); + V increment(K key, int delta); - V decr(K key); - - V incrBy(K key, int delta); + ListOperations listOps(); + BoundListOperations forList(K key); }