Skip to content

Commit e4b0a6a

Browse files
authored
Add support for AI.CONFIG (#7)
* Add support for AI.CONFIG
1 parent cdf71bc commit e4b0a6a

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/client.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,25 @@ export class Client {
150150
throw error;
151151
});
152152
}
153+
154+
/**
155+
* Loads the DL/ML backend specified by the backend identifier from path.
156+
*
157+
* @param backend
158+
* @param path
159+
*/
160+
public configLoadBackend(backend: string, path: string): Promise<any> {
161+
const args: any[] = ['LOADBACKEND', backend, path];
162+
return this._sendCommand('ai.config', args);
163+
}
164+
165+
/**
166+
* Specifies the default base backends path to path.
167+
*
168+
* @param path
169+
*/
170+
public configBackendsPath(path: string): Promise<any> {
171+
const args: any[] = ['BACKENDSPATH', path];
172+
return this._sendCommand('ai.config', args);
173+
}
153174
}

tests/test_client.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,3 +622,28 @@ it(
622622
aiclient.end(true);
623623
}),
624624
);
625+
626+
it(
627+
'ai.config positive and negative testing',
628+
mochaAsync(async () => {
629+
const nativeClient = createClient();
630+
const aiclient = new Client(nativeClient);
631+
const result = await aiclient.configBackendsPath('/usr/lib/redis/modules/backends/');
632+
expect(result).to.equal('OK');
633+
// negative test
634+
try {
635+
const loadReply = await aiclient.configLoadBackend(Backend.TF, 'notexist/redisai_tensorflow.so');
636+
} catch (e) {
637+
expect(e.toString()).to.equal('ReplyError: ERR error loading backend');
638+
}
639+
640+
try {
641+
// may throw error if backend already loaded
642+
const loadResult = await aiclient.configLoadBackend(Backend.TF, 'redisai_tensorflow/redisai_tensorflow.so');
643+
expect(loadResult).to.equal('OK');
644+
} catch (e) {
645+
expect(e.toString()).to.equal('ReplyError: ERR error loading backend');
646+
}
647+
aiclient.end(true);
648+
}),
649+
);

0 commit comments

Comments
 (0)