Skip to content

Commit

Permalink
update jedis to version 1.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Leibiusky committed Dec 26, 2010
1 parent ff1208f commit fe082e2
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 46 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>1.4.0</version>
<version>1.5.1</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/redis/clients/johm/JOhm.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static <T> T get(Class<?> clazz, int id) {

Nest nest = new Nest(clazz);
nest.setJedisPool(jedisPool);
if (nest.cat(id).exists().intValue() == 0) {
if (!nest.cat(id).exists()) {
return null;
}

Expand Down Expand Up @@ -372,7 +372,7 @@ private static Nest initIfNeeded(final Object model) {
nest.setJedisPool(jedisPool);
if (id == null) {
// lazily initialize id, nest, collections
id = nest.cat("id").incr();
id = nest.cat("id").incr().intValue();
JOhmUtils.loadId(model, id);
JOhmUtils.initCollections(model, nest);
}
Expand Down
55 changes: 25 additions & 30 deletions src/main/java/redis/clients/johm/Nest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeoutException;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
Expand Down Expand Up @@ -92,9 +91,9 @@ public String get() {
return string;
}

public Integer incr() {
public Long incr() {
Jedis jedis = getResource();
Integer incr = jedis.incr(key());
Long incr = jedis.incr(key());
returnResource(jedis);
return incr;
}
Expand All @@ -106,16 +105,16 @@ public List<Object> multi(TransactionBlock transaction) {
return multi;
}

public Integer del() {
public Long del() {
Jedis jedis = getResource();
Integer del = jedis.del(key());
Long del = jedis.del(key());
returnResource(jedis);
return del;
}

public Integer exists() {
public Boolean exists() {
Jedis jedis = getResource();
Integer exists = jedis.exists(key());
Boolean exists = jedis.exists(key());
returnResource(jedis);
return exists;
}
Expand All @@ -142,16 +141,16 @@ public String hget(String field) {
return value;
}

public Integer hdel(String field) {
public Long hdel(String field) {
Jedis jedis = getResource();
Integer hdel = jedis.hdel(key(), field);
Long hdel = jedis.hdel(key(), field);
returnResource(jedis);
return hdel;
}

public Integer hlen() {
public Long hlen() {
Jedis jedis = getResource();
Integer hlen = jedis.hlen(key());
Long hlen = jedis.hlen(key());
returnResource(jedis);
return hlen;
}
Expand All @@ -164,16 +163,16 @@ public Set<String> hkeys() {
}

// Redis Set Operations
public Integer sadd(String member) {
public Long sadd(String member) {
Jedis jedis = getResource();
Integer reply = jedis.sadd(key(), member);
Long reply = jedis.sadd(key(), member);
returnResource(jedis);
return reply;
}

public Integer srem(String member) {
public Long srem(String member) {
Jedis jedis = getResource();
Integer reply = jedis.srem(key(), member);
Long reply = jedis.srem(key(), member);
returnResource(jedis);
return reply;
}
Expand All @@ -186,9 +185,9 @@ public Set<String> smembers() {
}

// Redis List Operations
public Integer rpush(String string) {
public Long rpush(String string) {
Jedis jedis = getResource();
Integer rpush = jedis.rpush(key(), string);
Long rpush = jedis.rpush(key(), string);
returnResource(jedis);
return rpush;
}
Expand All @@ -207,16 +206,16 @@ public String lindex(int index) {
return lindex;
}

public Integer llen() {
public Long llen() {
Jedis jedis = getResource();
Integer llen = jedis.llen(key());
Long llen = jedis.llen(key());
returnResource(jedis);
return llen;
}

public Integer lrem(int count, String value) {
public Long lrem(int count, String value) {
Jedis jedis = getResource();
Integer lrem = jedis.lrem(key(), count, value);
Long lrem = jedis.lrem(key(), count, value);
returnResource(jedis);
return lrem;
}
Expand All @@ -236,16 +235,16 @@ public Set<String> zrange(int start, int end) {
return zrange;
}

public Integer zadd(float score, String member) {
public Long zadd(float score, String member) {
Jedis jedis = getResource();
Integer zadd = jedis.zadd(key(), score, member);
Long zadd = jedis.zadd(key(), score, member);
returnResource(jedis);
return zadd;
}

public Integer zcard() {
public Long zcard() {
Jedis jedis = getResource();
Integer zadd = jedis.zcard(key());
Long zadd = jedis.zcard(key());
returnResource(jedis);
return zadd;
}
Expand All @@ -256,11 +255,7 @@ private void returnResource(final Jedis jedis) {

private Jedis getResource() {
Jedis jedis;
try {
jedis = jedisPool.getResource();
} catch (TimeoutException e) {
throw new JOhmException(e);
}
jedis = jedisPool.getResource();
return jedis;
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/redis/clients/johm/collections/RedisArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void write(T[] backingArray) {
}

public int clear() {
return nest.cat(JOhmUtils.getId(owner)).cat(field.getName()).del();
return nest.cat(JOhmUtils.getId(owner)).cat(field.getName()).del().intValue();
}

private boolean save(T element) {
Expand Down Expand Up @@ -132,10 +132,10 @@ private boolean internalDelete(T element) {
Integer lrem = 0;
if (johmElementType == JOhmCollectionDataType.PRIMITIVE) {
lrem = nest.cat(JOhmUtils.getId(owner)).cat(field.getName()).lrem(
1, element.toString());
1, element.toString()).intValue();
} else if (johmElementType == JOhmCollectionDataType.MODEL) {
lrem = nest.cat(JOhmUtils.getId(owner)).cat(field.getName()).lrem(
1, JOhmUtils.getId(element).toString());
1, JOhmUtils.getId(element).toString()).intValue();
}
if (isIndexed) {
unindexValue(element);
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/redis/clients/johm/collections/RedisList.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ public T set(int index, T element) {

@Override
public int size() {
return nest.cat(JOhmUtils.getId(owner)).cat(field.getName()).llen();
return nest.cat(JOhmUtils.getId(owner)).cat(field.getName()).llen()
.intValue();
}

@Override
Expand Down Expand Up @@ -249,10 +250,11 @@ private boolean internalRemove(T element) {
Integer lrem = 0;
if (johmElementType == JOhmCollectionDataType.PRIMITIVE) {
lrem = nest.cat(JOhmUtils.getId(owner)).cat(field.getName())
.lrem(1, element.toString());
.lrem(1, element.toString()).intValue();
} else if (johmElementType == JOhmCollectionDataType.MODEL) {
lrem = nest.cat(JOhmUtils.getId(owner)).cat(field.getName())
.lrem(1, JOhmUtils.getId(element).toString());
.lrem(1, JOhmUtils.getId(element).toString())
.intValue();
}
unindexValue(element);
success = lrem > 0;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/redis/clients/johm/collections/RedisMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public V remove(Object key) {
@Override
public int size() {
int repoSize = nest.cat(JOhmUtils.getId(owner)).cat(field.getName())
.hlen();
.hlen().intValue();
return repoSize;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public boolean retainAll(Collection<?> c) {
@Override
public int size() {
int repoSize = nest.cat(JOhmUtils.getId(owner)).cat(field.getName())
.zcard();
.zcard().intValue();
return repoSize;
}

Expand Down
9 changes: 4 additions & 5 deletions src/test/java/redis/clients/johm/JOhmTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.concurrent.TimeoutException;

import org.apache.commons.pool.impl.GenericObjectPool.Config;
import org.junit.Assert;
import org.junit.Before;

Expand All @@ -20,13 +21,11 @@ public void startUp() throws TimeoutException {

protected void startJedisEngine() throws TimeoutException {
if (benchmarkMode) {
jedisPool = new JedisPool("localhost", Protocol.DEFAULT_PORT, 2000);
jedisPool.setResourcesNumber(50);
jedisPool.setDefaultPoolWait(1000000);
jedisPool = new JedisPool(new Config(), "localhost",
Protocol.DEFAULT_PORT, 2000);
} else {
jedisPool = new JedisPool("localhost");
jedisPool = new JedisPool(new Config(), "localhost");
}
jedisPool.init();
JOhm.setPool(jedisPool);
purgeRedis();
}
Expand Down

0 comments on commit fe082e2

Please sign in to comment.