+ introduce the concept of 'Connection'
+ add dedicated command interfaces
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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<String> 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();
|
||||
}
|
||||
@@ -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> T getNativeConnection();
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user