Skip to content

Commit 795e041

Browse files
authored
Add support for AI.CONFIG (#17)
* Add support for AI.CONFIG
1 parent cda15c0 commit 795e041

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

src/main/java/com/redislabs/redisai/Command.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ public enum Command implements ProtocolCommand{
1313
SCRIPT_GET("AI.SCRIPTGET"),
1414
SCRIPT_SET("AI.SCRIPTSET"),
1515
SCRIPT_RUN("AI.SCRIPTRUN"),
16-
INFO("AI.INFO");
16+
INFO("AI.INFO"),
17+
CONFIG("AI.CONFIG");
1718

1819

1920
private final byte[] raw;

src/main/java/com/redislabs/redisai/Keyword.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
public enum Keyword implements ProtocolCommand{
77

8-
TENSOR, INPUTS, OUTPUTS, META, VALUES, BLOB, SOURCE, RESETSTAT;
8+
TENSOR, INPUTS, OUTPUTS, META, VALUES, BLOB, SOURCE, RESETSTAT, BACKENDSPATH, LOADBACKEND;
99

1010
private final byte[] raw;
1111

src/main/java/com/redislabs/redisai/RedisAI.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,34 @@ public boolean resetStat(String key) {
320320
throw new RedisAIException(ex);
321321
}
322322
}
323+
324+
/**
325+
* AI.CONFIG <BACKENDSPATH <path>>
326+
*
327+
* @return
328+
*/
329+
public boolean setBackendsPath(String path) {
330+
try (Jedis conn = getConnection()) {
331+
return sendCommand(conn, Command.CONFIG, Keyword.BACKENDSPATH.getRaw(), SafeEncoder.encode(path))
332+
.getStatusCodeReply().equals("OK");
333+
} catch(JedisDataException ex) {
334+
throw new RedisAIException(ex);
335+
}
336+
}
337+
338+
/**
339+
* AI.CONFIG <LOADBACKEND <backend> <path>>
340+
*
341+
* @return
342+
*/
343+
public boolean loadBackend(Backend backEnd, String path) {
344+
try (Jedis conn = getConnection()) {
345+
return sendCommand(conn, Command.CONFIG, Keyword.LOADBACKEND.getRaw(), backEnd.getRaw(), SafeEncoder.encode(path))
346+
.getStatusCodeReply().equals("OK");
347+
} catch(JedisDataException ex) {
348+
throw new RedisAIException(ex);
349+
}
350+
}
323351

324352
private Jedis getConnection() {
325353
return pool.getResource();

src/test/java/com/redislabs/redisai/RedisAITest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,17 @@ public void testInfo() {
131131
// ERR cannot find run info for key
132132
}
133133
}
134+
135+
@Test
136+
public void testConfig() {
137+
Assert.assertTrue(client.setBackendsPath("/usr/lib/redis/modules/backends/"));
138+
try {
139+
client.loadBackend(Backend.TF, "notexist/redisai_tensorflow.so");
140+
Assert.fail("Should throw JedisDataException");
141+
} catch (RedisAIException e) {
142+
// ERR error loading backend
143+
}
144+
// will throw error if backend already loaded
145+
Assert.assertTrue(client.loadBackend(Backend.TF, "redisai_tensorflow/redisai_tensorflow.so"));
146+
}
134147
}

0 commit comments

Comments
 (0)