From bba8407f15631dac82ef02a57410304c892b418b Mon Sep 17 00:00:00 2001 From: Jonathan Leibiusky Date: Fri, 11 Jun 2010 10:18:33 -0300 Subject: [PATCH] Oh damn! forgot to add these files --- src/main/java/redis/clients/jedis/Jedis.java | 49 +++++++++++++++++++ .../redis/clients/jedis/tests/JedisTest.java | 42 ++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 src/main/java/redis/clients/jedis/Jedis.java create mode 100644 src/test/java/redis/clients/jedis/tests/JedisTest.java diff --git a/src/main/java/redis/clients/jedis/Jedis.java b/src/main/java/redis/clients/jedis/Jedis.java new file mode 100644 index 0000000..6bf8881 --- /dev/null +++ b/src/main/java/redis/clients/jedis/Jedis.java @@ -0,0 +1,49 @@ +package redis.clients.jedis; + +import java.io.IOException; + +public class Jedis extends Client { + public Jedis(String host) { + super(host); + } + + public String ping() { + // TODO: I want to be able to do the followin + // return protocol.runCommand(os, + // "PING").getSingleLineReply(inputStream); + // or even maybe + // return protocol.runCommand("PING").getSingleLineReply(); + + String command = protocol.buildCommand("PING"); + try { + outputStream.write(command.getBytes()); + return protocol.getSingleLineReply(inputStream); + } catch (IOException e) { + // TODO Not sure what to do here + return null; + } + } + + public String set(String key, String value) { + String command = protocol.buildCommand("SET", key, value); + try { + outputStream.write(command.getBytes()); + return protocol.getSingleLineReply(inputStream); + } catch (IOException e) { + // TODO Not sure what to do here + return null; + } + } + + public String get(String key) { + String command = protocol.buildCommand("GET", key); + try { + outputStream.write(command.getBytes()); + return protocol.getBulkReply(inputStream); + } catch (IOException e) { + // TODO Not sure what to do here + return null; + } + } + +} diff --git a/src/test/java/redis/clients/jedis/tests/JedisTest.java b/src/test/java/redis/clients/jedis/tests/JedisTest.java new file mode 100644 index 0000000..b2793ea --- /dev/null +++ b/src/test/java/redis/clients/jedis/tests/JedisTest.java @@ -0,0 +1,42 @@ +package redis.clients.jedis.tests; + +import java.io.IOException; +import java.net.UnknownHostException; + +import junit.framework.Assert; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import redis.clients.jedis.Jedis; + +public class JedisTest extends Assert { + private Jedis jedis; + + @Before + public void setUp() throws Exception { + jedis = new Jedis("localhost"); + jedis.connect(); + } + + @After + public void tearDown() throws Exception { + jedis.disconnect(); + } + + @Test + public void ping() throws UnknownHostException, IOException { + String status = jedis.ping(); + assertEquals("PONG", status); + } + + @Test + public void setAndGet() throws UnknownHostException, IOException { + String status = jedis.set("foo", "bar"); + assertEquals("OK", status); + + String value = jedis.get("foo"); + assertEquals("bar", value); + } +}