Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Commit

Permalink
Original issue xetorthio#38
Browse files Browse the repository at this point in the history
  • Loading branch information
agrison committed Mar 1, 2015
1 parent 37cecac commit e78152e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
23 changes: 23 additions & 0 deletions src/main/java/redis/clients/johm/JOhm.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.text.SimpleDateFormat;
import java.util.*;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.TransactionBlock;
import redis.clients.johm.collections.RedisArray;
Expand All @@ -16,6 +17,9 @@
public final class JOhm {
private static JedisPool jedisPool;

/** Current db index, on new redis connection it is set by default to 0 */
public static long dbIndex = 0L;

/**
* Read the id from the given model. This operation will typically be useful
* only after an initial interaction with Redis in the form of a call to
Expand Down Expand Up @@ -478,4 +482,23 @@ public static <T> Set<T> getAll(Class<?> clazz) {
}
return (Set<T>) results;
}

/**
* Select the current database.
*/
public static void selectDb(long dbIndex) {
JOhm.dbIndex = dbIndex;
}

/**
* Flush the current database.
*/
public static void flushDb() {
Jedis jedis = jedisPool.getResource();
try {
jedis.flushDB();
} finally {
jedisPool.returnResource(jedis);
}
}
}
6 changes: 4 additions & 2 deletions src/main/java/redis/clients/johm/Nest.java
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,10 @@ private void returnResource(final Jedis jedis) {
}

private Jedis getResource() {
Jedis jedis;
jedis = jedisPool.getResource();
Jedis jedis = jedisPool.getResource();
// check for selected database
if (!jedis.getDB().equals(JOhm.dbIndex))
jedis.select((int) JOhm.dbIndex);
return jedis;
}

Expand Down

0 comments on commit e78152e

Please sign in to comment.