+ add key operations contract (no impl yet)
This commit is contained in:
@@ -20,6 +20,8 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Hash operations bound to a certain key.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public interface BoundHashOperations<H, HK, HV> extends KeyBound<H> {
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.data.keyvalue.redis.connection.DataType;
|
||||
|
||||
/**
|
||||
* Key operations bound to a certain value.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public interface BoundKeyOperations<K> extends KeyBound<K> {
|
||||
|
||||
Boolean exists();
|
||||
|
||||
void delete();
|
||||
|
||||
DataType type();
|
||||
|
||||
void rename(K newKey);
|
||||
|
||||
Boolean renameIfAbsent(K newKey);
|
||||
|
||||
Boolean expire(long timeout, TimeUnit unit);
|
||||
|
||||
Boolean expireAt(Date date);
|
||||
|
||||
long getExpire();
|
||||
|
||||
void persist();
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.data.keyvalue.redis.connection.DataType;
|
||||
|
||||
|
||||
/**
|
||||
* Default implementation for {@link BoundKeyOperations}.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
class DefaultBoundKeyOperations<K> extends DefaultKeyBound<K> implements BoundKeyOperations<K> {
|
||||
|
||||
private final KeyOperations<K> keyOps;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>DefaultBoundKeyOperations</code> instance.
|
||||
*
|
||||
* @param key
|
||||
*/
|
||||
public DefaultBoundKeyOperations(K key, KeyOperations<K> keyOps) {
|
||||
super(key);
|
||||
this.keyOps = keyOps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete() {
|
||||
keyOps.delete(getKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean exists() {
|
||||
return keyOps.exists(getKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean expire(long timeout, TimeUnit unit) {
|
||||
return keyOps.expire(getKey(), timeout, unit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean expireAt(Date date) {
|
||||
return keyOps.expireAt(getKey(), date);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getExpire() {
|
||||
return keyOps.getExpire(getKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void persist() {
|
||||
keyOps.persist(getKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rename(K newKey) {
|
||||
keyOps.rename(getKey(), newKey);
|
||||
setKey(newKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean renameIfAbsent(K newKey) {
|
||||
if (keyOps.renameIfAbsent(getKey(), newKey)) {
|
||||
setKey(newKey);
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType type() {
|
||||
return keyOps.type(getKey());
|
||||
}
|
||||
}
|
||||
@@ -23,10 +23,16 @@ import java.util.List;
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public class DefaultBoundListOperations<K, V> extends DefaultKeyBound<K> implements BoundListOperations<K, V> {
|
||||
class DefaultBoundListOperations<K, V> extends DefaultKeyBound<K> implements BoundListOperations<K, V> {
|
||||
|
||||
private final ListOperations<K, V> ops;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>DefaultBoundListOperations</code> instance.
|
||||
*
|
||||
* @param key
|
||||
* @param template
|
||||
*/
|
||||
public DefaultBoundListOperations(K key, RedisTemplate<K, V> template) {
|
||||
super(key);
|
||||
this.ops = template.listOps();
|
||||
|
||||
@@ -28,6 +28,12 @@ class DefaultBoundSetOperations<K, V> extends DefaultKeyBound<K> implements Boun
|
||||
private final SetOperations<K, V> ops;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a new <code>DefaultBoundSetOperations</code> instance.
|
||||
*
|
||||
* @param key
|
||||
* @param template
|
||||
*/
|
||||
DefaultBoundSetOperations(K key, RedisTemplate<K, V> template) {
|
||||
super(key);
|
||||
this.ops = template.setOps();
|
||||
|
||||
@@ -27,6 +27,12 @@ class DefaultBoundZSetOperations<K, V> extends DefaultKeyBound<K> implements Bou
|
||||
|
||||
private final ZSetOperations<K, V> ops;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>DefaultBoundZSetOperations</code> instance.
|
||||
*
|
||||
* @param key
|
||||
* @param template
|
||||
*/
|
||||
public DefaultBoundZSetOperations(K key, RedisTemplate<K, V> template) {
|
||||
super(key);
|
||||
this.ops = template.zSetOps();
|
||||
|
||||
@@ -21,16 +21,20 @@ package org.springframework.data.keyvalue.redis.core;
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public class DefaultKeyBound<K> implements KeyBound<K> {
|
||||
class DefaultKeyBound<K> implements KeyBound<K> {
|
||||
|
||||
private final K key;
|
||||
private K key;
|
||||
|
||||
public DefaultKeyBound(K key) {
|
||||
this.key = key;
|
||||
setKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public K getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
protected void setKey(K key) {
|
||||
this.key = key;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.data.keyvalue.redis.connection.DataType;
|
||||
|
||||
/**
|
||||
* Redis operations available for all keys.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public interface KeyOperations<K> {
|
||||
|
||||
Boolean exists(K key);
|
||||
|
||||
void delete(K key);
|
||||
|
||||
DataType type(K key);
|
||||
|
||||
Set<K> keys(String pattern);
|
||||
|
||||
K randomKey();
|
||||
|
||||
void rename(K oldKey, K newKey);
|
||||
|
||||
Boolean renameIfAbsent(K oldKey, K newKey);
|
||||
|
||||
Boolean expire(K key, long timeout, TimeUnit unit);
|
||||
|
||||
Boolean expireAt(K key, Date date);
|
||||
|
||||
void persist(K key);
|
||||
|
||||
long getExpire(K key);
|
||||
}
|
||||
Reference in New Issue
Block a user