DATAKV-28
+ add property editors for [X] Operations
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2011 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.beans.PropertyEditorSupport;
|
||||
|
||||
/**
|
||||
* PropertyEditor allowing for easy injection of {@link HashOperations} from
|
||||
* {@link RedisOperations}.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
class HashOperationsEditor extends PropertyEditorSupport {
|
||||
|
||||
@Override
|
||||
public void setValue(Object value) {
|
||||
if (value instanceof RedisOperations) {
|
||||
super.setValue(((RedisOperations) value).opsForHash());
|
||||
}
|
||||
else {
|
||||
throw new java.lang.IllegalArgumentException("Editor supports only conversion of type "
|
||||
+ RedisOperations.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2011 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.beans.PropertyEditorSupport;
|
||||
|
||||
/**
|
||||
* PropertyEditor allowing for easy injection of {@link ListOperations} from
|
||||
* {@link RedisOperations}.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
class ListOperationsEditor extends PropertyEditorSupport {
|
||||
@Override
|
||||
public void setValue(Object value) {
|
||||
if (value instanceof RedisOperations) {
|
||||
super.setValue(((RedisOperations) value).opsForList());
|
||||
}
|
||||
else {
|
||||
throw new java.lang.IllegalArgumentException("Editor supports only conversion of type "
|
||||
+ RedisOperations.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2011 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.beans.PropertyEditorSupport;
|
||||
|
||||
/**
|
||||
* PropertyEditor allowing for easy injection of {@link SetOperations} from
|
||||
* {@link RedisOperations}.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
class SetOperationsEditor extends PropertyEditorSupport {
|
||||
|
||||
@Override
|
||||
public void setValue(Object value) {
|
||||
if (value instanceof RedisOperations) {
|
||||
super.setValue(((RedisOperations) value).opsForSet());
|
||||
}
|
||||
else {
|
||||
throw new java.lang.IllegalArgumentException("Editor supports only conversion of type "
|
||||
+ RedisOperations.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,238 @@
|
||||
/*
|
||||
* Copyright 2011 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.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.data.keyvalue.redis.connection.DataType;
|
||||
import org.springframework.data.keyvalue.redis.connection.MessageListener;
|
||||
import org.springframework.data.keyvalue.redis.connection.RedisConnection;
|
||||
import org.springframework.data.keyvalue.redis.connection.SortParameters;
|
||||
import org.springframework.data.keyvalue.redis.serializer.RedisSerializer;
|
||||
|
||||
/**
|
||||
* Convenience extension of {@link RedisConnection} that accepts and returns {@link String}s instead of
|
||||
* byte arrays. Uses a {@link RedisSerializer} underneath to perform the conversion.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @see RedisCallback
|
||||
* @see RedisSerializer
|
||||
* @see StringRedisTemplate
|
||||
*/
|
||||
public interface StringRedisConnection extends RedisConnection {
|
||||
|
||||
Boolean exists(String key);
|
||||
|
||||
Long del(String... keys);
|
||||
|
||||
DataType type(String key);
|
||||
|
||||
Collection<String> keys(String pattern);
|
||||
|
||||
void rename(String oldName, String newName);
|
||||
|
||||
Boolean renameNX(String oldName, String newName);
|
||||
|
||||
Boolean expire(String key, long seconds);
|
||||
|
||||
Boolean expireAt(String key, long unixTime);
|
||||
|
||||
Boolean persist(String key);
|
||||
|
||||
Long ttl(String key);
|
||||
|
||||
String echo(String message);
|
||||
|
||||
// sort commands
|
||||
List<String> sort(String key, SortParameters params);
|
||||
|
||||
Long sort(String key, SortParameters params, String storeKey);
|
||||
|
||||
String get(String key);
|
||||
|
||||
String getSet(String key, String value);
|
||||
|
||||
List<String> mGet(String... keys);
|
||||
|
||||
void set(String key, String value);
|
||||
|
||||
Boolean setNX(String key, String value);
|
||||
|
||||
void setEx(String key, long seconds, String value);
|
||||
|
||||
void mSetString(Map<String, String> tuple);
|
||||
|
||||
void mSetNXString(Map<String, String> tuple);
|
||||
|
||||
Long incr(String key);
|
||||
|
||||
Long incrBy(String key, long value);
|
||||
|
||||
Long decr(String key);
|
||||
|
||||
Long decrBy(String key, long value);
|
||||
|
||||
Long append(String key, String value);
|
||||
|
||||
String getRange(String key, int start, int end);
|
||||
|
||||
void setRange(String key, int start, int end);
|
||||
|
||||
Boolean getBit(String key, long offset);
|
||||
|
||||
void setBit(String key, long offset, boolean value);
|
||||
|
||||
Long strLen(String key);
|
||||
|
||||
Long rPush(String key, String value);
|
||||
|
||||
Long lPush(String key, String value);
|
||||
|
||||
Long rPushX(String key, String value);
|
||||
|
||||
Long lPushX(String key, String value);
|
||||
|
||||
Long lLen(String key);
|
||||
|
||||
List<String> lRange(String key, long start, long end);
|
||||
|
||||
void lTrim(String key, long start, long end);
|
||||
|
||||
String lIndex(String key, long index);
|
||||
|
||||
Long lInsert(String key, POSITION where, String pivot, String value);
|
||||
|
||||
void lSet(String key, long index, String value);
|
||||
|
||||
Long lRem(String key, long count, String value);
|
||||
|
||||
String lPop(String key);
|
||||
|
||||
String rPop(String key);
|
||||
|
||||
List<String> bLPop(int timeout, String... keys);
|
||||
|
||||
List<String> bRPop(int timeout, String... keys);
|
||||
|
||||
String rPopLPush(String srcKey, String dstKey);
|
||||
|
||||
String bRPopLPush(int timeout, String srcKey, String dstKey);
|
||||
|
||||
Boolean sAdd(String key, String value);
|
||||
|
||||
Boolean sRem(String key, String value);
|
||||
|
||||
String sPop(String key);
|
||||
|
||||
Boolean sMove(String srcKey, String destKey, String value);
|
||||
|
||||
Long sCard(String key);
|
||||
|
||||
Boolean sIsMember(String key, String value);
|
||||
|
||||
Set<String> sInter(String... keys);
|
||||
|
||||
void sInterStore(String destKey, String... keys);
|
||||
|
||||
Set<String> sUnion(String... keys);
|
||||
|
||||
void sUnionStore(String destKey, String... keys);
|
||||
|
||||
Set<String> sDiff(String... keys);
|
||||
|
||||
void sDiffStore(String destKey, String... keys);
|
||||
|
||||
Set<String> sMembers(String key);
|
||||
|
||||
String sRandMember(String key);
|
||||
|
||||
Boolean zAdd(String key, double score, String value);
|
||||
|
||||
Boolean zRem(String key, String value);
|
||||
|
||||
Double zIncrBy(String key, double increment, String value);
|
||||
|
||||
Long zRank(String key, String value);
|
||||
|
||||
Long zRevRank(String key, String value);
|
||||
|
||||
Set<String> zRange(String key, long start, long end);
|
||||
|
||||
Set<Tuple> zRangeWithScore(String key, long start, long end);
|
||||
|
||||
Set<String> zRevRange(String key, long start, long end);
|
||||
|
||||
Set<Tuple> zRevRangeWithScore(String key, long start, long end);
|
||||
|
||||
Set<String> zRangeByScore(String key, double min, double max);
|
||||
|
||||
Set<Tuple> zRangeByScoreWithScore(String key, double min, double max);
|
||||
|
||||
Set<String> zRangeByScore(String key, double min, double max, long offset, long count);
|
||||
|
||||
Set<Tuple> zRangeByScoreWithScore(String key, double min, double max, long offset, long count);
|
||||
|
||||
Long zCount(String key, double min, double max);
|
||||
|
||||
Long zCard(String key);
|
||||
|
||||
Double zScore(String key, String value);
|
||||
|
||||
Long zRemRange(String key, long start, long end);
|
||||
|
||||
Long zRemRangeByScore(String key, double min, double max);
|
||||
|
||||
Long zUnionStore(String destKey, String... sets);
|
||||
|
||||
Long zUnionStore(String destKey, Aggregate aggregate, int[] weights, String... sets);
|
||||
|
||||
Long zInterStore(String destKey, String... sets);
|
||||
|
||||
Long zInterStore(String destKey, Aggregate aggregate, int[] weights, String... sets);
|
||||
|
||||
Boolean hSet(String key, String field, String value);
|
||||
|
||||
Boolean hSetNX(String key, String field, String value);
|
||||
|
||||
String hGet(String key, String field);
|
||||
|
||||
List<String> hMGet(String key, String... fields);
|
||||
|
||||
void hMSet(String key, Map<String, String> hashes);
|
||||
|
||||
Long hIncrBy(String key, String field, long delta);
|
||||
|
||||
Boolean hExists(String key, String field);
|
||||
|
||||
Boolean hDel(String key, String field);
|
||||
|
||||
Long hLen(String key);
|
||||
|
||||
Set<String> hKeys(String key);
|
||||
|
||||
List<String> hVals(String key);
|
||||
|
||||
Map<String, String> hGetAll(String key);
|
||||
|
||||
Long publish(String channel, String message);
|
||||
|
||||
void subscribe(MessageListener listener, String... channels);
|
||||
|
||||
void pSubscribe(MessageListener listener, String... patterns);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2011 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.beans.PropertyEditorSupport;
|
||||
|
||||
/**
|
||||
* PropertyEditor allowing for easy injection of {@link ValueOperations} from
|
||||
* {@link RedisOperations}.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
class ValueOperationsEditor extends PropertyEditorSupport {
|
||||
|
||||
@Override
|
||||
public void setValue(Object value) {
|
||||
if (value instanceof RedisOperations) {
|
||||
super.setValue(((RedisOperations) value).opsForValue());
|
||||
}
|
||||
else {
|
||||
throw new java.lang.IllegalArgumentException("Editor supports only conversion of type "
|
||||
+ RedisOperations.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2011 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.beans.PropertyEditorSupport;
|
||||
|
||||
/**
|
||||
* PropertyEditor allowing for easy injection of {@link ZSetOperations} from
|
||||
* {@link RedisOperations}.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
class ZSetOperationsEditor extends PropertyEditorSupport {
|
||||
|
||||
@Override
|
||||
public void setValue(Object value) {
|
||||
if (value instanceof RedisOperations) {
|
||||
super.setValue(((RedisOperations) value).opsForZSet());
|
||||
}
|
||||
else {
|
||||
throw new java.lang.IllegalArgumentException("Editor supports only conversion of type "
|
||||
+ RedisOperations.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2011 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;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.support.GenericXmlApplicationContext;
|
||||
import org.springframework.data.keyvalue.redis.core.RedisOperations;
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public class PropertyEditorsTest {
|
||||
|
||||
private GenericXmlApplicationContext ctx;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
ctx = new GenericXmlApplicationContext("/org/springframework/data/keyvalue/redis/pe.xml");
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
if (ctx != null)
|
||||
ctx.destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInjection() throws Exception {
|
||||
RedisViewPE bean = ctx.getBean(RedisViewPE.class);
|
||||
RedisOperations<?, ?> ops = ctx.getBean(RedisOperations.class);
|
||||
|
||||
assertSame(ops.opsForValue(), bean.getValueOps());
|
||||
assertSame(ops.opsForList(), bean.getListOps());
|
||||
assertSame(ops.opsForSet(), bean.getSetOps());
|
||||
assertSame(ops.opsForZSet(), bean.getZsetOps());
|
||||
assertSame(ops, bean.getHashOps().getOperations());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright 2011 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;
|
||||
|
||||
import org.springframework.data.keyvalue.redis.core.HashOperations;
|
||||
import org.springframework.data.keyvalue.redis.core.ListOperations;
|
||||
import org.springframework.data.keyvalue.redis.core.SetOperations;
|
||||
import org.springframework.data.keyvalue.redis.core.ValueOperations;
|
||||
import org.springframework.data.keyvalue.redis.core.ZSetOperations;
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public class RedisViewPE {
|
||||
|
||||
private ValueOperations<String, String> valueOps;
|
||||
private ListOperations<String, String> listOps;
|
||||
private SetOperations<String, String> setOps;
|
||||
private ZSetOperations<String, Object> zsetOps;
|
||||
private HashOperations<Object, String, Object> hashOps;
|
||||
|
||||
public ValueOperations<String, String> getValueOps() {
|
||||
return valueOps;
|
||||
}
|
||||
|
||||
public void setValueOps(ValueOperations<String, String> valueOps) {
|
||||
this.valueOps = valueOps;
|
||||
}
|
||||
|
||||
public ListOperations<String, String> getListOps() {
|
||||
return listOps;
|
||||
}
|
||||
|
||||
public void setListOps(ListOperations<String, String> listOps) {
|
||||
this.listOps = listOps;
|
||||
}
|
||||
|
||||
public SetOperations<String, String> getSetOps() {
|
||||
return setOps;
|
||||
}
|
||||
|
||||
public void setSetOps(SetOperations<String, String> setOps) {
|
||||
this.setOps = setOps;
|
||||
}
|
||||
|
||||
public ZSetOperations<String, Object> getZsetOps() {
|
||||
return zsetOps;
|
||||
}
|
||||
|
||||
public void setZsetOps(ZSetOperations<String, Object> zsetOps) {
|
||||
this.zsetOps = zsetOps;
|
||||
}
|
||||
|
||||
public HashOperations<Object, String, Object> getHashOps() {
|
||||
return hashOps;
|
||||
}
|
||||
|
||||
public void setHashOps(HashOperations<Object, String, Object> hashOps) {
|
||||
this.hashOps = hashOps;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
|
||||
|
||||
<bean id="connectionFactory" class="org.springframework.data.keyvalue.redis.connection.jedis.JedisConnectionFactory"/>
|
||||
|
||||
<bean id="redisTemplate" class="org.springframework.data.keyvalue.redis.core.RedisTemplate" p:connection-factory-ref="connectionFactory"/>
|
||||
|
||||
<bean id="injected" class="org.springframework.data.keyvalue.redis.RedisViewPE"
|
||||
p:value-ops-ref="redisTemplate"
|
||||
p:list-ops-ref="redisTemplate"
|
||||
p:set-ops-ref="redisTemplate"
|
||||
p:zset-ops-ref="redisTemplate"
|
||||
p:hash-ops-ref="redisTemplate"
|
||||
/>
|
||||
</beans>
|
||||
Reference in New Issue
Block a user