Added some set commands

This commit is contained in:
Jonathan Leibiusky
2010-06-22 23:08:58 -03:00
parent 8815dbb7c6
commit a70037ecbd
2 changed files with 55 additions and 0 deletions

View File

@@ -265,4 +265,8 @@ public class Jedis extends Client {
public String rpoplpush(String srckey, String dstkey) throws JedisException {
return sendCommand("RPOPLPUSH", srckey, dstkey).getBulkReply();
}
public int sadd(String key, String member) throws JedisException {
return sendCommand("SADD", key, member).getIntegerReply();
}
}

View File

@@ -0,0 +1,51 @@
package redis.clients.jedis.tests.commands;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
import junit.framework.Assert;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisException;
public class SetCommandsTest extends Assert {
private Jedis jedis;
@Before
public void setUp() throws Exception {
jedis = new Jedis("localhost");
jedis.connect();
}
@After
public void tearDown() throws Exception {
jedis.flushDB();
jedis.disconnect();
}
@Test
public void sadd() throws JedisException {
int status = jedis.sadd("foo", "a");
assertEquals(1, status);
status = jedis.sadd("foo", "a");
assertEquals(0, status);
}
@Test
public void smembers() throws JedisException {
jedis.sadd("foo", "a");
jedis.sadd("foo", "b");
Set<String> expected = new LinkedHashSet<String>();
expected
assertEquals(0, status);
}
}