k6-docs icon indicating copy to clipboard operation
k6-docs copied to clipboard

Document and clarify the use of redis.sendCommand

Open mkosta opened this issue 1 year ago • 5 comments
trafficstars

if i pass command like this, i get error ERR invalid cursor

const result3 = await redisClient.sendCommand('scan','0  MATCH 17*');

if i send only cursor

const result3 = await redisClient.sendCommand('scan','0');

returns keys.

It seems there is some issue with passing parameter here. Pattern with keys command works. probably because it is a single parameter

 const result = await redisClient.sendCommand('keys','17*');

Would be useful to have not just example with "Echo, Hello World", but more complicated case with arguments.

When trying to pass arrays in sendCommand arguments i get

 Uncaught (in promise) unsupported type provided for argument at index 1, supported types are string, number, and boolean

So i am confused how to pass second argument. Thanks for advice or fix

for example this one works

let args = ['0'];
 const result3 = await redisClient.sendCommand('scan',...args);

this one returns error Uncaught (in promise) ERR syntax error

let args = ['0','MATCH 7*'];
const result3 = await redisClient.sendCommand('scan',...args);

PS we figured second paramets had to be split in two as well

let args = ['0','MATCH','17*'];
const result3 = await redisClient.sendCommand('scan',...args);

should have example like this for dumb people like me)))

mkosta avatar Apr 09 '24 12:04 mkosta

Hi @mkosta 👋🏻

Thanks for pointing that out. Indeed 👍🏻 As you've found out, the issue you're experiencing is likely because you're passing the arguments as a string, whereas we expect an array/sequence of strings in that case. That's essentially how the Redis protocol serializes it under the hood, it expects to receive a list of arguments that will be \r\n separated, and both our API and the underlying library we use reflect that implementation detail.

I also noticed that we haven't provided type definitions for that specific command in DefinitelyTyped, which probably didn't help either.

We should indeed, document that kind of case more explicitly indeed 👍🏻

oleiade avatar Apr 12 '24 12:04 oleiade

I believe this is a valid issue, but we should rather move it to the k6 documentation repository's issue, what do you think @codebien ? 🙇🏻

oleiade avatar Apr 12 '24 12:04 oleiade

@oleiade I agree, we can transfer it. What is your expectation to fix it? Can we directly link the go-redis library? Otherwise, if we need to write all the details in the doc, we will end in rewriting the same doc as they have. Opinions?

codebien avatar Apr 12 '24 13:04 codebien

I would expect the actionable to make a pass on Redis examples in the documentation make sure sendCommand is shown, and ensure that we provide a real-world example as presented here. We would also explicitly document that it does not send the command arguments as a single string but expects each argument to independently as described here 👍🏻

oleiade avatar Apr 12 '24 13:04 oleiade

thank you, guys! while we are on the subject. do you know why INFO command would return empty result? is it go library not able to capture output or is it lost somewhere between go and k6?

const result3 = await redisClient.sendCommand('INFO');

this logs a lot of empty space, kinda the size of INFO output from cli, except no text is present) this command with grep args would be quite helpful to get keys count, connected clients and what not

smth like this

let args = ['|','grep','clients'];
const result3 = await redisClient.sendCommand('INFO',...args);
console.log(typeof result3);
console.log(result3);

outputs this empty string

INFO[0004] string                                        source=console










  source=console
INFO[0004] Preparing the end-of-test summary...          source=console

mkosta avatar Apr 12 '24 19:04 mkosta