-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use mget with a variable of type array #48
Comments
The current version does not support the kind of call method you said, you can refer to the documentation about the use of mget. const keys = ["record1", "record2", "record3"]
const records = await tedis.mget(...keys) |
This codes does not work in TypeScript: const clientHashes: string[] = clientFiles.map(f => f.hash);
let serverPaths: string[];
// Error: ts(2556) A spread argument must either have a tuple type or be passed to a rest parameter
serverPaths = await db.hmget(filesKey, ...clientHashes);
// I should write code like this:
if (clientHashes.length == 1)
serverPaths = await db.hmget(filesKey, clientHashes[0]);
else if (clientHashes.length > 1)
serverPaths = await db.hmget(filesKey, clientHashes[0], ...clientHashes.slice(1)); Why public hmget(key: string, field: string, ...fields: string[]) {
return this.command<Array<string | null>>("HMGET", key, field, ...fields);
} => public hmget(key: string, ...fields: string[]) {
return this.command<Array<string | null>>("HMGET", key, ...fields);
} I think above two codes is same. Is there any compatibility problem? |
@AlphaBs Thank you for your feedback, the version switch will be completed this month and the interface will be resolved and optimized by then |
I'm assuming this is just a syntax issue, but I can't seem to use mget with a variable.
If I have a variable
const keys = ["record1", "record2", "record3"]
The following will return 0 records
const records = await tedis.mget(keys)
But if I do the following, I will get 3 records.
const records = await tedis.mget("record1", "record2", "record3")
I'm not sure of the syntax when using a variable.
I even tried the following, but I still get no results.
const keyString = '"record1", "record2", "record3"'
const records = await tedis.mget(keyString)
Any help on how to execute an mget request with a variable (preferably an array) would be appreciated.
Thanks!
The text was updated successfully, but these errors were encountered: