diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/UncategorizedRedisException.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/UncategorizedRedisException.java new file mode 100644 index 000000000..8908b067b --- /dev/null +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/UncategorizedRedisException.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; + +import org.springframework.datastore.keyvalue.UncategorizedKeyvalueStoreException; + +/** + * Exception thrown when we can't classify a Redis exception into one of Spring generic data access exceptions. + * + * @author Costin Leau + */ +public class UncategorizedRedisException extends UncategorizedKeyvalueStoreException { + + public UncategorizedRedisException(String msg, Throwable cause) { + super(msg, cause); + } +} diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/connection/DataTypes.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/connection/DataTypes.java new file mode 100644 index 000000000..e8f14fb6a --- /dev/null +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/connection/DataTypes.java @@ -0,0 +1,27 @@ +/* + * 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.connection; + +/** + * Enumeration of the Redis data types. + * + * @author Costin Leau + */ +public enum DataTypes { + + NONE, STRING, LIST, SET, ZSET, HASH; +} diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/connection/RedisCommands.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/connection/RedisCommands.java new file mode 100644 index 000000000..eb12526cc --- /dev/null +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/connection/RedisCommands.java @@ -0,0 +1,62 @@ +/* + * 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.connection; + +import java.util.Collection; + +/** + * Commands supported by Redis . + * + * @author Costin Leau + */ +public interface RedisCommands { + + boolean exists(String key); + + int del(String... keys); + + DataTypes type(String key); + + Collection keys(String pattern); + + String randomKey(); + + //TODO see whether the status code can be properly intercepted + boolean rename(String oldName, String newName); + + boolean renameNx(String oldName, String newName); + + int dbSize(); + + boolean expire(String key, long seconds); + + boolean persist(String key); + + int ttl(String key); + + void select(int dbIndex); + + void watch(String... keys); + + void unwatch(); + + void multi(); + + void exec(); + + void discard(); +} \ No newline at end of file diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/connection/RedisConnection.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/connection/RedisConnection.java new file mode 100644 index 000000000..34a53d729 --- /dev/null +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/connection/RedisConnection.java @@ -0,0 +1,39 @@ +/* + * 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.connection; + +import org.springframework.datastore.redis.UncategorizedRedisException; + +/** + * A connection (session) to a Redis server. + * The methods namings follows as much as possible the Redis conventions. + * + * @author Costin Leau + */ +public interface RedisConnection extends RedisCommands { + + /** + * Close (or quit) the connection. + * + * @throws UncategorizedRedisException + */ + void close() throws UncategorizedRedisException; + + boolean isClosed(); + + T getNativeConnection(); +} diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/connection/RedisHashCommands.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/connection/RedisHashCommands.java new file mode 100644 index 000000000..bc2281de5 --- /dev/null +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/connection/RedisHashCommands.java @@ -0,0 +1,27 @@ +/* + * 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.connection; + +/** + * Hash-specific commands supported by Redis. + * + * @author Costin Leau + */ +public interface RedisHashCommands { + + int hSet(String key, String field, String value); +} diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/connection/RedisListCommands.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/connection/RedisListCommands.java new file mode 100644 index 000000000..58394c462 --- /dev/null +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/connection/RedisListCommands.java @@ -0,0 +1,29 @@ +/* + * 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.connection; + +/** + * List-specific commands supported by Redis. + * + * @author Costin Leau + */ +public interface RedisListCommands { + + int rPush(String key, String value); + + int lPush(String key, String value); +} diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/connection/RedisSetCommands.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/connection/RedisSetCommands.java new file mode 100644 index 000000000..ef1ea839f --- /dev/null +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/connection/RedisSetCommands.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.datastore.redis.core.connection; + +/** + * Set-specific commands supported by Redis. + * + * @author Costin Leau + */ +public interface RedisSetCommands { + +} diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/connection/RedisStringCommands.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/connection/RedisStringCommands.java new file mode 100644 index 000000000..f9b9464e0 --- /dev/null +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/connection/RedisStringCommands.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.datastore.redis.core.connection; + +/** + * String specific commands supported by Redis . + * + * @author Costin Leau + */ +// TODO should the strings be byte[] instead +// at least for values ? +public interface RedisStringCommands { + + void set(String key, String value); + + String get(String key); + + +} diff --git a/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/connection/RedisZSetCommands.java b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/connection/RedisZSetCommands.java new file mode 100644 index 000000000..74751221c --- /dev/null +++ b/spring-datastore-redis/src/main/java/org/springframework/datastore/redis/core/connection/RedisZSetCommands.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.datastore.redis.core.connection; + +/** + * ZSet(SortedSet)-specific commands supported by Redis. + * + * @author Costin Leau + */ +public interface RedisZSetCommands { + +}