+ renamed get[X]Ops to -opsFor[X]
+ add Jedis 1.5.2 support
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
<properties>
|
||||
<!--<jredis.ver>02112010</jredis.ver>-->
|
||||
<jredis.ver>03122010</jredis.ver>
|
||||
<jedis.ver>1.5.1</jedis.ver>
|
||||
<jedis.ver>1.5.2-SNAPSHOT</jedis.ver>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -181,7 +181,14 @@ public class JedisConnection implements RedisConnection {
|
||||
|
||||
try {
|
||||
if (isQueueing()) {
|
||||
throw new UnsupportedOperationException("Jedis does not support sort&store in MULTI/EXEC mode.");
|
||||
if (sortParams != null) {
|
||||
transaction.sort(key, sortParams, sortKey);
|
||||
}
|
||||
else {
|
||||
transaction.sort(key, sortKey);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return (sortParams != null ? jedis.sort(key, sortParams, sortKey) : jedis.sort(key, sortKey));
|
||||
} catch (Exception ex) {
|
||||
@@ -767,7 +774,7 @@ public class JedisConnection implements RedisConnection {
|
||||
// return null;
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
return (jedis.getbit(key, (int) offset) == 0 ? Boolean.FALSE : Boolean.TRUE);
|
||||
return (jedis.getbit(key, offset) == 0 ? Boolean.FALSE : Boolean.TRUE);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
@@ -781,7 +788,7 @@ public class JedisConnection implements RedisConnection {
|
||||
// return;
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
jedis.setbit(key, (int) offset, JedisUtils.asBit(value));
|
||||
jedis.setbit(key, offset, JedisUtils.asBit(value));
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
@@ -995,7 +1002,7 @@ public class JedisConnection implements RedisConnection {
|
||||
if (isQueueing()) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
return jedis.brpoplpush(srcKey, dstKey, timeout).getBytes();
|
||||
return jedis.brpoplpush(srcKey, dstKey, timeout);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
@@ -1667,8 +1674,8 @@ public class JedisConnection implements RedisConnection {
|
||||
}
|
||||
|
||||
// FIXME: DATAKV-24 once Jedis adds support for binary messages
|
||||
String msg = new String(message);
|
||||
String chn = new String(channel);
|
||||
String msg = new String(message);
|
||||
|
||||
return jedis.publish(chn, msg);
|
||||
} catch (Exception ex) {
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.data.keyvalue.redis.connection.jedis;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.commons.pool.impl.GenericObjectPool;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
@@ -29,6 +28,7 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
import redis.clients.jedis.JedisShardInfo;
|
||||
import redis.clients.jedis.Protocol;
|
||||
|
||||
@@ -48,11 +48,12 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
|
||||
private String password;
|
||||
|
||||
private boolean usePool = true;
|
||||
|
||||
private JedisPool pool = null;
|
||||
private JedisPoolConfig poolConfig = new JedisPoolConfig();
|
||||
|
||||
/**
|
||||
* Constructs a new <code>JedisConnectionFactory</code> instance.
|
||||
* Constructs a new <code>JedisConnectionFactory</code> instance
|
||||
* with default settings (default connection pooling, no shard information).
|
||||
*/
|
||||
public JedisConnectionFactory() {
|
||||
}
|
||||
@@ -61,12 +62,23 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
|
||||
* Constructs a new <code>JedisConnectionFactory</code> instance.
|
||||
* Will override the other connection parameters passed to the factory.
|
||||
*
|
||||
* @param shardInfo
|
||||
* @param shardInfo shard information
|
||||
*/
|
||||
public JedisConnectionFactory(JedisShardInfo shardInfo) {
|
||||
this.shardInfo = shardInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new <code>JedisConnectionFactory</code> instance using
|
||||
* the given pool configuration.
|
||||
*
|
||||
* @param poolConfig pool configuration
|
||||
*/
|
||||
public JedisConnectionFactory(JedisPoolConfig poolConfig) {
|
||||
this.poolConfig = poolConfig;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a Jedis instance to be used as a Redis connection.
|
||||
* The instance can be newly created or retrieved from a pool.
|
||||
@@ -101,7 +113,7 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
|
||||
}
|
||||
|
||||
if (usePool) {
|
||||
pool = new JedisPool(new GenericObjectPool.Config(), shardInfo.getHost(), shardInfo.getPort(),
|
||||
pool = new JedisPool(poolConfig, shardInfo.getHost(), shardInfo.getPort(),
|
||||
shardInfo.getTimeout(), shardInfo.getPassword());
|
||||
}
|
||||
}
|
||||
@@ -233,4 +245,22 @@ public class JedisConnectionFactory implements InitializingBean, DisposableBean,
|
||||
public void setUsePool(boolean usePool) {
|
||||
this.usePool = usePool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the poolConfig.
|
||||
*
|
||||
* @return Returns the poolConfig
|
||||
*/
|
||||
public JedisPoolConfig getPoolConfig() {
|
||||
return poolConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the pool configuration for this factory.
|
||||
*
|
||||
* @param poolConfig The poolConfig to set.
|
||||
*/
|
||||
public void setPoolConfig(JedisPoolConfig poolConfig) {
|
||||
this.poolConfig = poolConfig;
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ class DefaultBoundHashOperations<H, HK, HV> extends DefaultKeyBound<H> implement
|
||||
*/
|
||||
public DefaultBoundHashOperations(H key, RedisOperations<H, ?> operations) {
|
||||
super(key);
|
||||
this.ops = operations.getHashOps();
|
||||
this.ops = operations.opsForHash();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -36,7 +36,7 @@ class DefaultBoundListOperations<K, V> extends DefaultKeyBound<K> implements Bou
|
||||
*/
|
||||
public DefaultBoundListOperations(K key, RedisOperations<K, V> operations) {
|
||||
super(key);
|
||||
this.ops = operations.getListOps();
|
||||
this.ops = operations.opsForList();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ class DefaultBoundSetOperations<K, V> extends DefaultKeyBound<K> implements Boun
|
||||
*/
|
||||
DefaultBoundSetOperations(K key, RedisOperations<K, V> operations) {
|
||||
super(key);
|
||||
this.ops = operations.getSetOps();
|
||||
this.ops = operations.opsForSet();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -32,7 +32,7 @@ class DefaultBoundValueOperations<K, V> extends DefaultKeyBound<K> implements Bo
|
||||
*/
|
||||
public DefaultBoundValueOperations(K key, RedisOperations<K, V> operations) {
|
||||
super(key);
|
||||
this.ops = operations.getValueOps();
|
||||
this.ops = operations.opsForValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -36,7 +36,7 @@ class DefaultBoundZSetOperations<K, V> extends DefaultKeyBound<K> implements Bou
|
||||
*/
|
||||
public DefaultBoundZSetOperations(K key, RedisOperations<K, V> oeprations) {
|
||||
super(key);
|
||||
this.ops = oeprations.getZSetOps();
|
||||
this.ops = oeprations.opsForZSet();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -96,7 +96,7 @@ public interface RedisOperations<K, V> {
|
||||
*
|
||||
* @return value operations
|
||||
*/
|
||||
ValueOperations<K, V> getValueOps();
|
||||
ValueOperations<K, V> opsForValue();
|
||||
|
||||
/**
|
||||
* Returns the operations performed on simple values (or Strings in Redis terminology)
|
||||
@@ -112,7 +112,7 @@ public interface RedisOperations<K, V> {
|
||||
*
|
||||
* @return list operations
|
||||
*/
|
||||
ListOperations<K, V> getListOps();
|
||||
ListOperations<K, V> opsForList();
|
||||
|
||||
/**
|
||||
* Returns the operations performed on list values bound to the given key.
|
||||
@@ -127,7 +127,7 @@ public interface RedisOperations<K, V> {
|
||||
*
|
||||
* @return set operations
|
||||
*/
|
||||
SetOperations<K, V> getSetOps();
|
||||
SetOperations<K, V> opsForSet();
|
||||
|
||||
/**
|
||||
* Returns the operations performed on set values bound to the given key.
|
||||
@@ -142,7 +142,7 @@ public interface RedisOperations<K, V> {
|
||||
*
|
||||
* @return zset operations
|
||||
*/
|
||||
ZSetOperations<K, V> getZSetOps();
|
||||
ZSetOperations<K, V> opsForZSet();
|
||||
|
||||
/**
|
||||
* Returns the operations performed on zset values (also known as sorted sets)
|
||||
@@ -160,7 +160,7 @@ public interface RedisOperations<K, V> {
|
||||
* @param <HV> hash value type
|
||||
* @return hash operations
|
||||
*/
|
||||
<HK, HV> HashOperations<K, HK, HV> getHashOps();
|
||||
<HK, HV> HashOperations<K, HK, HV> opsForHash();
|
||||
|
||||
/**
|
||||
* Returns the operations performed on hash values bound to the given key.
|
||||
|
||||
@@ -697,7 +697,7 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueOperations<K, V> getValueOps() {
|
||||
public ValueOperations<K, V> opsForValue() {
|
||||
return valueOps;
|
||||
}
|
||||
|
||||
@@ -914,7 +914,7 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListOperations<K, V> getListOps() {
|
||||
public ListOperations<K, V> opsForList() {
|
||||
return listOps;
|
||||
}
|
||||
|
||||
@@ -1158,7 +1158,7 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
}
|
||||
|
||||
@Override
|
||||
public SetOperations<K, V> getSetOps() {
|
||||
public SetOperations<K, V> opsForSet() {
|
||||
return setOps;
|
||||
}
|
||||
|
||||
@@ -1353,7 +1353,7 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZSetOperations<K, V> getZSetOps() {
|
||||
public ZSetOperations<K, V> opsForZSet() {
|
||||
return zSetOps;
|
||||
}
|
||||
|
||||
@@ -1572,7 +1572,7 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
}
|
||||
|
||||
@Override
|
||||
public <HK, HV> HashOperations<K, HK, HV> getHashOps() {
|
||||
public <HK, HV> HashOperations<K, HK, HV> opsForHash() {
|
||||
return new DefaultHashOperations<HK, HV>();
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ public class RedisAtomicInteger extends Number implements Serializable, KeyBound
|
||||
*/
|
||||
public RedisAtomicInteger(String redisCounter, RedisOperations<String, Integer> operations) {
|
||||
this.key = redisCounter;
|
||||
this.operations = operations.getValueOps();
|
||||
this.operations = operations.opsForValue();
|
||||
this.generalOps = operations;
|
||||
if (this.operations.get(redisCounter) == null) {
|
||||
set(0);
|
||||
@@ -63,7 +63,7 @@ public class RedisAtomicInteger extends Number implements Serializable, KeyBound
|
||||
*/
|
||||
public RedisAtomicInteger(String redisCounter, RedisOperations<String, Integer> operations, int initialValue) {
|
||||
this.key = redisCounter;
|
||||
this.operations = operations.getValueOps();
|
||||
this.operations = operations.opsForValue();
|
||||
this.generalOps = operations;
|
||||
this.operations.set(redisCounter, initialValue);
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class RedisAtomicLong extends Number implements Serializable, KeyBound<St
|
||||
*/
|
||||
public RedisAtomicLong(String redisCounter, RedisOperations<String, Long> operations) {
|
||||
this.key = redisCounter;
|
||||
this.operations = operations.getValueOps();
|
||||
this.operations = operations.opsForValue();
|
||||
this.generalOps = operations;
|
||||
if (this.operations.get(redisCounter) == null) {
|
||||
set(0);
|
||||
@@ -63,7 +63,7 @@ public class RedisAtomicLong extends Number implements Serializable, KeyBound<St
|
||||
*/
|
||||
public RedisAtomicLong(String redisCounter, RedisOperations<String, Long> operations, long initialValue) {
|
||||
this.key = redisCounter;
|
||||
this.operations = operations.getValueOps();
|
||||
this.operations = operations.opsForValue();
|
||||
this.operations.set(redisCounter, initialValue);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user