Added some set commands
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user