diff --git a/src/main/java/com/redislabs/redisgraph/Command.java b/src/main/java/com/redislabs/redisgraph/Command.java index 4e9f695..35dbd98 100644 --- a/src/main/java/com/redislabs/redisgraph/Command.java +++ b/src/main/java/com/redislabs/redisgraph/Command.java @@ -8,7 +8,8 @@ * */ public enum Command implements ProtocolCommand { - QUERY("graph.QUERY"); + QUERY("graph.QUERY"), + DELETE("graph.DELETE"); private final byte[] raw; diff --git a/src/main/java/com/redislabs/redisgraph/RedisGraphAPI.java b/src/main/java/com/redislabs/redisgraph/RedisGraphAPI.java index ccac748..ac08f62 100644 --- a/src/main/java/com/redislabs/redisgraph/RedisGraphAPI.java +++ b/src/main/java/com/redislabs/redisgraph/RedisGraphAPI.java @@ -47,6 +47,18 @@ public ResultSet query(String query) { return new ResultSetImpl(sendCommand(conn, Command.QUERY, graphId, query).getObjectMultiBulkReply()); } } + + /** + * Deletes the entire graph + * + * @return delete running time statistics + */ + public String deleteGraph() { + try (Jedis conn = _conn()) { + return sendCommand(conn, Command.DELETE, graphId).getBulkReply(); + } + } + private BinaryClient sendCommand(Jedis conn, ProtocolCommand provider, String ...args) { BinaryClient client = conn.getClient(); diff --git a/src/main/java/com/redislabs/redisgraph/impl/StatisticsImpl.java b/src/main/java/com/redislabs/redisgraph/impl/StatisticsImpl.java index 984ab28..0f67062 100644 --- a/src/main/java/com/redislabs/redisgraph/impl/StatisticsImpl.java +++ b/src/main/java/com/redislabs/redisgraph/impl/StatisticsImpl.java @@ -1,6 +1,5 @@ package com.redislabs.redisgraph.impl; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -26,8 +25,7 @@ public String getStringValue(Statistics.Label label) { private Map getStatistics(){ if(statistics.size() == 0) { for(byte[] touple : this.raw) { - String row = SafeEncoder.encode(touple); - String[] rowTouple = row.split(":"); + String[] rowTouple = SafeEncoder.encode(touple).split(":"); this.statistics.put( Statistics.Label.getEnum(rowTouple[0]), rowTouple[1].trim()); } } diff --git a/src/test/java/com/redislabs/redisgraph/RedisGraphAPITest.java b/src/test/java/com/redislabs/redisgraph/RedisGraphAPITest.java index f039852..5f7db8c 100644 --- a/src/test/java/com/redislabs/redisgraph/RedisGraphAPITest.java +++ b/src/test/java/com/redislabs/redisgraph/RedisGraphAPITest.java @@ -18,12 +18,8 @@ public RedisGraphAPITest() { } @Before - public void flushDB() throws Exception{ - // api.deleteGraph(); - TODO add this back once we implement this API - - Method method = RedisGraphAPI.class.getDeclaredMethod("_conn"); - method.setAccessible(true); - ((Jedis)method.invoke(api)).flushDB(); + public void deleteGraph() throws Exception{ + api.deleteGraph(); } @Test @@ -93,4 +89,4 @@ public void testQuery() throws Exception { Assert.assertEquals( "32.000000", record.getString(0)); } -} \ No newline at end of file +}