Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/xetorthio/jedis into Clea…
Browse files Browse the repository at this point in the history
…ning
  • Loading branch information
Dario Guzik committed May 13, 2011
2 parents ace1588 + 6a78b32 commit 9af964e
Show file tree
Hide file tree
Showing 41 changed files with 2,456 additions and 1,317 deletions.
75 changes: 68 additions & 7 deletions src/main/java/redis/clients/jedis/BinaryClient.java
Expand Up @@ -28,6 +28,10 @@ private LIST_POSITION() {

private boolean isInMulti;

private String password;

private long db;

public boolean isInMulti() {
return isInMulti;
}
Expand All @@ -40,6 +44,21 @@ public BinaryClient(final String host, final int port) {
super(host, port);
}

public void setPassword(final String password) {
this.password = password;
}

@Override
public void connect() {
if (!isConnected()) {
super.connect();
if (password != null) {
sendCommand(AUTH, password);
getStatusCodeReply();
}
}
}

public void ping() {
sendCommand(PING);
}
Expand All @@ -53,6 +72,7 @@ public void get(final byte[] key) {
}

public void quit() {
db = 0;
sendCommand(QUIT);
}

Expand Down Expand Up @@ -105,6 +125,7 @@ public void ttl(final byte[] key) {
}

public void select(final int index) {
db = index;
sendCommand(SELECT, toByteArray(index));
}

Expand Down Expand Up @@ -234,23 +255,23 @@ public void llen(final byte[] key) {
sendCommand(LLEN, key);
}

public void lrange(final byte[] key, final int start, final int end) {
public void lrange(final byte[] key, final long start, final long end) {
sendCommand(LRANGE, key, toByteArray(start), toByteArray(end));
}

public void ltrim(final byte[] key, final int start, final int end) {
public void ltrim(final byte[] key, final long start, final long end) {
sendCommand(LTRIM, key, toByteArray(start), toByteArray(end));
}

public void lindex(final byte[] key, final int index) {
public void lindex(final byte[] key, final long index) {
sendCommand(LINDEX, key, toByteArray(index));
}

public void lset(final byte[] key, final int index, final byte[] value) {
public void lset(final byte[] key, final long index, final byte[] value) {
sendCommand(LSET, key, toByteArray(index), value);
}

public void lrem(final byte[] key, int count, final byte[] value) {
public void lrem(final byte[] key, long count, final byte[] value) {
sendCommand(LREM, key, toByteArray(count), value);
}

Expand Down Expand Up @@ -438,6 +459,7 @@ public void brpop(final byte[][] args) {
}

public void auth(final String password) {
setPassword(password);
sendCommand(AUTH, password);
}

Expand Down Expand Up @@ -478,30 +500,59 @@ public void zrangeByScore(final byte[] key, final double min,
sendCommand(ZRANGEBYSCORE, key, toByteArray(min), toByteArray(max));
}

public void zrevrangeByScore(final byte[] key, final double max,
final double min) {
sendCommand(ZREVRANGEBYSCORE, key, toByteArray(max), toByteArray(min));
}

public void zrangeByScore(final byte[] key, final byte[] min,
final byte[] max) {
sendCommand(ZRANGEBYSCORE, key, min, max);
}

public void zrevrangeByScore(final byte[] key, final byte[] max,
final byte[] min) {
sendCommand(ZREVRANGEBYSCORE, key, max, min);
}

public void zrangeByScore(final byte[] key, final double min,
final double max, final int offset, int count) {
sendCommand(ZRANGEBYSCORE, key, toByteArray(min), toByteArray(max),
LIMIT.raw, toByteArray(offset), toByteArray(count));
}

public void zrevrangeByScore(final byte[] key, final double max,
final double min, final int offset, int count) {
sendCommand(ZREVRANGEBYSCORE, key, toByteArray(max), toByteArray(min),
LIMIT.raw, toByteArray(offset), toByteArray(count));
}

public void zrangeByScoreWithScores(final byte[] key, final double min,
final double max) {
sendCommand(ZRANGEBYSCORE, key, toByteArray(min), toByteArray(max),
WITHSCORES.raw);
}

public void zrevrangeByScoreWithScores(final byte[] key, final double max,
final double min) {
sendCommand(ZREVRANGEBYSCORE, key, toByteArray(max), toByteArray(min),
WITHSCORES.raw);
}

public void zrangeByScoreWithScores(final byte[] key, final double min,
final double max, final int offset, final int count) {
sendCommand(ZRANGEBYSCORE, key, toByteArray(min), toByteArray(max),
LIMIT.raw, toByteArray(offset), toByteArray(count),
WITHSCORES.raw);
}

public void zrevrangeByScoreWithScores(final byte[] key, final double max,
final double min, final int offset, final int count) {
sendCommand(ZREVRANGEBYSCORE, key, toByteArray(max), toByteArray(min),
LIMIT.raw, toByteArray(offset), toByteArray(count),
WITHSCORES.raw);
}

public void zremrangeByRank(final byte[] key, final int start, final int end) {
sendCommand(ZREMRANGEBYRANK, key, toByteArray(start), toByteArray(end));
}
Expand Down Expand Up @@ -650,6 +701,16 @@ public void setrange(byte[] key, long offset, byte[] value) {
}

public void getrange(byte[] key, long startOffset, long endOffset) {
sendCommand(GETRANGE, key, toByteArray(startOffset), toByteArray(endOffset));
sendCommand(GETRANGE, key, toByteArray(startOffset),
toByteArray(endOffset));
}

public Long getDB() {
return db;
}

public void disconnect() {
db = 0;
super.disconnect();
}
}
}
68 changes: 57 additions & 11 deletions src/main/java/redis/clients/jedis/BinaryJedis.java
@@ -1,7 +1,5 @@
package redis.clients.jedis;

import java.io.IOException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
Expand All @@ -11,13 +9,13 @@
import java.util.Set;

import redis.clients.jedis.BinaryClient.LIST_POSITION;
import redis.clients.jedis.exceptions.JedisDataException;
import redis.clients.jedis.exceptions.JedisException;
import redis.clients.util.JedisByteHashMap;
import redis.clients.util.SafeEncoder;

public class BinaryJedis implements BinaryJedisCommands {
protected Client client = null;
protected String password = null;

public BinaryJedis(final String host) {
client = new Client(host);
Expand All @@ -35,7 +33,7 @@ public BinaryJedis(final String host, final int port, final int timeout) {
public BinaryJedis(final JedisShardInfo shardInfo) {
client = new Client(shardInfo.getHost(), shardInfo.getPort());
client.setTimeout(shardInfo.getTimeout());
this.password = shardInfo.getPassword();
client.setPassword(shardInfo.getPassword());
}

public String ping() {
Expand Down Expand Up @@ -79,9 +77,10 @@ public byte[] get(final byte[] key) {
/**
* Ask the server to silently close the connection.
*/
public void quit() {
public String quit() {
checkIsInMulti();
client.quit();
return client.getStatusCodeReply();
}

/**
Expand Down Expand Up @@ -1649,16 +1648,16 @@ public List<Object> multi(final TransactionBlock jedisTransaction) {

protected void checkIsInMulti() {
if (client.isInMulti()) {
throw new JedisException(
throw new JedisDataException(
"Cannot use Jedis when in Multi. Please use JedisTransaction instead.");
}
}

public void connect() throws UnknownHostException, IOException {
public void connect() {
client.connect();
}

public void disconnect() throws IOException {
public void disconnect() {
client.disconnect();
}

Expand Down Expand Up @@ -2019,11 +2018,13 @@ public String auth(final String password) {
public List<Object> pipelined(final PipelineBlock jedisPipeline) {
jedisPipeline.setClient(client);
jedisPipeline.execute();
return client.getAll();
return jedisPipeline.sync();
}

public Pipeline pipelined() {
return new Pipeline(client);
Pipeline pipeline = new Pipeline();
pipeline.setClient(client);
return pipeline;
}

public void subscribe(final JedisPubSub jedisPubSub,
Expand Down Expand Up @@ -2326,6 +2327,44 @@ private Set<Tuple> getBinaryTupledSet() {
return set;
}

public Set<byte[]> zrevrangeByScore(final byte[] key, final double max,
final double min) {
checkIsInMulti();
client.zrevrangeByScore(key, max, min);
return new LinkedHashSet<byte[]>(client.getBinaryMultiBulkReply());
}

public Set<byte[]> zrevrangeByScore(final byte[] key, final byte[] max,
final byte[] min) {
checkIsInMulti();
client.zrevrangeByScore(key, max, min);
return new LinkedHashSet<byte[]>(client.getBinaryMultiBulkReply());
}

public Set<byte[]> zrevrangeByScore(final byte[] key, final double max,
final double min, final int offset, final int count) {
checkIsInMulti();
client.zrevrangeByScore(key, max, min, offset, count);
return new LinkedHashSet<byte[]>(client.getBinaryMultiBulkReply());
}

public Set<Tuple> zrevrangeByScoreWithScores(final byte[] key,
final double max, final double min) {
checkIsInMulti();
client.zrevrangeByScoreWithScores(key, max, min);
Set<Tuple> set = getBinaryTupledSet();
return set;
}

public Set<Tuple> zrevrangeByScoreWithScores(final byte[] key,
final double max, final double min, final int offset,
final int count) {
checkIsInMulti();
client.zrevrangeByScoreWithScores(key, max, min, offset, count);
Set<Tuple> set = getBinaryTupledSet();
return set;
}

/**
* Remove all elements in the sorted set at key with rank between start and
* end. Start and end are 0-based with rank 0 being the element with the
Expand Down Expand Up @@ -2898,7 +2937,10 @@ public Client getClient() {
*/
public byte[] brpoplpush(byte[] source, byte[] destination, int timeout) {
client.brpoplpush(source, destination, timeout);
return client.getBinaryBulkReply();
client.setTimeoutInfinite();
byte[] reply = client.getBinaryBulkReply();
client.rollbackTimeout();
return reply;
}

/**
Expand Down Expand Up @@ -2952,4 +2994,8 @@ public void psubscribe(BinaryJedisPubSub jedisPubSub, byte[]... patterns) {
jedisPubSub.proceedWithPatterns(client, patterns);
client.rollbackTimeout();
}

public Long getDB() {
return client.getDB();
}
}
10 changes: 10 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryJedisCommands.java
Expand Up @@ -139,6 +139,16 @@ Set<byte[]> zrangeByScore(byte[] key, double min, double max, int offset,
Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max,
int offset, int count);

Set<byte[]> zrevrangeByScore(byte[] key, double max, double min);

Set<byte[]> zrevrangeByScore(byte[] key, double max, double min, int offset,
int count);

Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min);

Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min,
int offset, int count);

Long zremrangeByRank(byte[] key, int start, int end);

Long zremrangeByScore(byte[] key, double start, double end);
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/redis/clients/jedis/BinaryShardedJedis.java
Expand Up @@ -357,6 +357,28 @@ public Set<Tuple> zrangeByScoreWithScores(byte[] key, double min,
return j.zrangeByScoreWithScores(key, min, max, offset, count);
}

public Set<byte[]> zrevrangeByScore(byte[] key, double max, double min) {
Jedis j = getShard(key);
return j.zrevrangeByScore(key, max, min);
}

public Set<byte[]> zrevrangeByScore(byte[] key, double max, double min,
int offset, int count) {
Jedis j = getShard(key);
return j.zrevrangeByScore(key, max, min, offset, count);
}

public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min) {
Jedis j = getShard(key);
return j.zrevrangeByScoreWithScores(key, max, min);
}

public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max,
double min, int offset, int count) {
Jedis j = getShard(key);
return j.zrevrangeByScoreWithScores(key, max, min, offset, count);
}

public Long zremrangeByRank(byte[] key, int start, int end) {
Jedis j = getShard(key);
return j.zremrangeByRank(key, start, end);
Expand Down

0 comments on commit 9af964e

Please sign in to comment.