Skip to content

Commit

Permalink
Merge branch 'variadic_arg_support' of git://github.com/shaofengniu/j…
Browse files Browse the repository at this point in the history
…edis into shaofengniu-variadic_arg_support
  • Loading branch information
xetorthio committed Apr 17, 2012
2 parents aa05406 + f010bc0 commit caac648
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 27 deletions.
18 changes: 12 additions & 6 deletions src/main/java/redis/clients/jedis/BinaryClient.java
Expand Up @@ -248,12 +248,18 @@ public void hgetAll(final byte[] key) {
sendCommand(HGETALL, key);
}

public void rpush(final byte[] key, final byte[] string) {
sendCommand(RPUSH, key, string);
}

public void lpush(final byte[] key, final byte[] string) {
sendCommand(LPUSH, key, string);
public void rpush(final byte[] key, final byte[]... vals) {
byte[][] args = new byte[vals.length+1][];
args[0] = key;
System.arraycopy(vals, 0, args, 1, vals.length);
sendCommand(RPUSH, args);
}

public void lpush(final byte[] key, final byte[]... vals) {
byte [][] args = new byte[vals.length+1][];
args[0] = key;
System.arraycopy(vals, 0, args, 1, vals.length);
sendCommand(LPUSH, args);
}

public void llen(final byte[] key) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/redis/clients/jedis/BinaryJedis.java
Expand Up @@ -888,7 +888,7 @@ public Map<byte[], byte[]> hgetAll(final byte[] key) {
* @return Integer reply, specifically, the number of elements inside the
* list after the push operation.
*/
public Long rpush(final byte[] key, final byte[] string) {
public Long rpush(final byte[] key, final byte[]... string) {
checkIsInMulti();
client.rpush(key, string);
return client.getIntegerReply();
Expand All @@ -909,7 +909,7 @@ public Long rpush(final byte[] key, final byte[] string) {
* @return Integer reply, specifically, the number of elements inside the
* list after the push operation.
*/
public Long lpush(final byte[] key, final byte[] string) {
public Long lpush(final byte[] key, final byte[]... string) {
checkIsInMulti();
client.lpush(key, string);
return client.getIntegerReply();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/redis/clients/jedis/BinaryJedisCommands.java
Expand Up @@ -67,9 +67,9 @@ public interface BinaryJedisCommands {

Map<byte[], byte[]> hgetAll(byte[] key);

Long rpush(byte[] key, byte[] string);
Long rpush(byte[] key, byte[]... string);

Long lpush(byte[] key, byte[] string);
Long lpush(byte[] key, byte[]... string);

Long llen(byte[] key);

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/redis/clients/jedis/BinaryShardedJedis.java
Expand Up @@ -180,12 +180,12 @@ public Map<byte[], byte[]> hgetAll(byte[] key) {
return j.hgetAll(key);
}

public Long rpush(byte[] key, byte[] string) {
public Long rpush(byte[] key, byte[]... string) {
Jedis j = getShard(key);
return j.rpush(key, string);
}

public Long lpush(byte[] key, byte[] string) {
public Long lpush(byte[] key, byte[]... string) {
Jedis j = getShard(key);
return j.lpush(key, string);
}
Expand Down Expand Up @@ -407,4 +407,4 @@ public ShardedJedisPipeline pipelined() {
pipeline.setShardedJedis(this);
return pipeline;
}
}
}
18 changes: 14 additions & 4 deletions src/main/java/redis/clients/jedis/Client.java
Expand Up @@ -189,12 +189,22 @@ public void hgetAll(final String key) {
hgetAll(SafeEncoder.encode(key));
}

public void rpush(final String key, final String string) {
rpush(SafeEncoder.encode(key), SafeEncoder.encode(string));

public void rpush(final String key, final String... vals) {
final byte[][] bvals = new byte[vals.length][];
for (int i = 0; i < bvals.length; i++) {
bvals[i] = SafeEncoder.encode(vals[i]);
}
rpush(SafeEncoder.encode(key), bvals);
}

public void lpush(final String key, final String string) {
lpush(SafeEncoder.encode(key), SafeEncoder.encode(string));

public void lpush(final String key, final String... vals) {
final byte[][] bvals = new byte[vals.length][];
for (int i = 0; i < bvals.length; i++) {
bvals[i] = SafeEncoder.encode(vals[i]);
}
lpush(SafeEncoder.encode(key), bvals);
}

public void llen(final String key) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/redis/clients/jedis/Commands.java
Expand Up @@ -86,9 +86,9 @@ public interface Commands {

public void hgetAll(final String key);

public void rpush(final String key, final String string);
public void rpush(final String key, final String... string);

public void lpush(final String key, final String string);
public void lpush(final String key, final String... string);

public void llen(final String key);

Expand Down Expand Up @@ -259,4 +259,4 @@ public void linsert(final String key, final LIST_POSITION where,
public void exec();

public void discard();
}
}
4 changes: 2 additions & 2 deletions src/main/java/redis/clients/jedis/Jedis.java
Expand Up @@ -865,7 +865,7 @@ public Map<String, String> hgetAll(final String key) {
* @return Integer reply, specifically, the number of elements inside the
* list after the push operation.
*/
public Long rpush(final String key, final String string) {
public Long rpush(final String key, final String... string) {
checkIsInMulti();
client.rpush(key, string);
return client.getIntegerReply();
Expand All @@ -886,7 +886,7 @@ public Long rpush(final String key, final String string) {
* @return Integer reply, specifically, the number of elements inside the
* list after the push operation.
*/
public Long lpush(final String key, final String string) {
public Long lpush(final String key, final String... string) {
checkIsInMulti();
client.lpush(key, string);
return client.getIntegerReply();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/redis/clients/jedis/JedisCommands.java
Expand Up @@ -72,9 +72,9 @@ public interface JedisCommands {

Map<String, String> hgetAll(String key);

Long rpush(String key, String string);
Long rpush(String key, String... string);

Long lpush(String key, String string);
Long lpush(String key, String... string);

Long llen(String key);

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/redis/clients/jedis/ShardedJedis.java
Expand Up @@ -198,12 +198,12 @@ public Map<String, String> hgetAll(String key) {
return j.hgetAll(key);
}

public Long rpush(String key, String string) {
public Long rpush(String key, String... string) {
Jedis j = getShard(key);
return j.rpush(key, string);
}

public Long lpush(String key, String string) {
public Long lpush(String key, String... string) {
Jedis j = getShard(key);
return j.lpush(key, string);
}
Expand Down
Expand Up @@ -30,12 +30,17 @@ public void rpush() {
assertEquals(1, size);
size = jedis.rpush("foo", "foo");
assertEquals(2, size);
size = jedis.rpush("foo", "bar", "foo");
assertEquals(4, size);


// Binary
long bsize = jedis.rpush(bfoo, bbar);
assertEquals(1, bsize);
bsize = jedis.rpush(bfoo, bfoo);
assertEquals(2, bsize);
bsize = jedis.rpush(bfoo, bbar, bfoo);
assertEquals(4, bsize);

}

Expand All @@ -45,12 +50,16 @@ public void lpush() {
assertEquals(1, size);
size = jedis.lpush("foo", "foo");
assertEquals(2, size);
size = jedis.lpush("foo", "bar", "foo");
assertEquals(4, size);

// Binary
long bsize = jedis.lpush(bfoo, bbar);
assertEquals(1, bsize);
bsize = jedis.lpush(bfoo, bfoo);
assertEquals(2, bsize);
bsize = jedis.lpush(bfoo, bbar, bfoo);
assertEquals(4, bsize);

}

Expand Down Expand Up @@ -620,4 +629,4 @@ public void run() {
assertEquals("a", jedis.lrange("bar", 0, -1).get(0));

}
}
}

0 comments on commit caac648

Please sign in to comment.