Skip to content

Commit

Permalink
Issue alphazeroGH-47 (wip) -- keys() and mget binary support. (The fu…
Browse files Browse the repository at this point in the history
…ture was

written Joe ..)
  • Loading branch information
alphazero committed Apr 23, 2011
1 parent c682615 commit cf65061
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
6 changes: 3 additions & 3 deletions core/api/src/main/java/org/jredis/JRedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public interface JRedis {
* @return
* @throws RedisException
*/
public <K extends Object> List<byte[]> mget(String...keys) throws RedisException;
public <K extends Object> List<byte[]> mget(K...keys) throws RedisException;

/**
* @Redis MSET
Expand Down Expand Up @@ -283,7 +283,7 @@ public interface JRedis {
* @return
* @throws RedisException
*/
public <K extends Object> List<String> keys (K pattern) throws RedisException;
public <K extends Object> List<byte[]> keys (K pattern) throws RedisException;

/**
* Convenience method. Equivalent to calling <code>jredis.keys("*");</code>
Expand All @@ -292,7 +292,7 @@ public interface JRedis {
* @throws RedisException
* @see {@link JRedis#keys(String)}
*/
public <K extends Object> List<String> keys () throws RedisException;
public <K extends Object> List<byte[]> keys () throws RedisException;

/**
* @Redis RANDOMKEY
Expand Down
11 changes: 6 additions & 5 deletions core/ri/src/main/java/org/jredis/ri/alphazero/JRedisSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -1117,13 +1117,13 @@ public <K extends Object, T extends Serializable> void mset(KeyValueSet.Objects<
}

// @Override
public <K extends Object> List<byte[]> mget(String...keys) throws RedisException {
public <K extends Object> List<byte[]> mget(K...keys) throws RedisException {

if(null == keys || keys.length == 0) throw new IllegalArgumentException("no keys specified");
byte[] keydata = null;
byte[][] keybytes = new byte[keys.length][];
int i=0;
for(String k : keys) {
for(K k : keys) {
if((keydata = getKeyBytes(k)) == null)
throw new IllegalArgumentException ("invalid key => ["+k+"] @ index: " + i);

Expand Down Expand Up @@ -1158,12 +1158,12 @@ public <K extends Object> List<byte[]> smembers(K key) throws RedisException {
return multiBulkData;
}
// @Override
public <K extends Object> List<String> keys() throws RedisException {
public <K extends Object> List<byte[]> keys() throws RedisException {
return this.keys("*");
}

// @Override
public <K extends Object> List<String> keys(K pattern) throws RedisException {
public <K extends Object> List<byte[]> keys(K pattern) throws RedisException {
byte[] keydata = null;
if((keydata = getKeyBytes(pattern)) == null)
throw new RedisException (Command.KEYS, "ERR Invalid key.");
Expand All @@ -1176,7 +1176,8 @@ public <K extends Object> List<String> keys(K pattern) throws RedisException {
catch (ClassCastException e){
throw new ProviderException("Expecting a MultiBulkResponse here => " + e.getLocalizedMessage(), e);
}
return DefaultCodec.toStr(multiBulkData);
// return DefaultCodec.toStr(multiBulkData);
return multiBulkData;
/*
byte[] bulkData= null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -3016,7 +3018,10 @@ public void testKeys() {
for (int i=0; i<SMALL_CNT; i++)
provider.set(keys.get(i), dataList.get(i));

List<String> rediskeys = provider.keys();
List<byte[]> redisBinkeys = provider.keys();
List<String> rediskeys = new ArrayList<String>(redisBinkeys.size());
for(byte[] bk : redisBinkeys)
rediskeys.add(new String(bk));
assertEquals(SMALL_CNT, rediskeys.size(), "size of key list should be SMALL_CNT");
for(int i=0; i<SMALL_CNT; i++)
assertTrue(rediskeys.contains(keys.get(i)), "should contain " + keys.get(i));
Expand All @@ -3037,7 +3042,10 @@ public void testKeysString() {
for (int i=0; i<SMALL_CNT; i++)
provider.set(patternList.get(i), dataList.get(i));

List<String> rediskeys = provider.keys("*"+patternA+"*");
List<byte[]> redisBinkeys = provider.keys("*"+patternA+"*");
List<String> rediskeys = new ArrayList<String>(redisBinkeys.size());
for(byte[] bk : redisBinkeys)
rediskeys.add(new String(bk));
assertEquals(SMALL_CNT, rediskeys.size(), "size of key list should be SMALL_CNT");
for(int i=0; i<SMALL_CNT; i++)
assertTrue(rediskeys.contains(patternList.get(i)), "should contain " + patternList.get(i));
Expand Down

0 comments on commit cf65061

Please sign in to comment.