grafana / k6-docs

The k6 documentation website.
https://grafana.com/docs/k6/latest/
87 stars 221 forks source link

Document and clarify the use of redis.sendCommand #1550

Open mkosta opened 7 months ago

mkosta commented 7 months ago

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)))

oleiade commented 7 months ago

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 commented 7 months ago

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 ? πŸ™‡πŸ»

codebien commented 7 months ago

@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?

oleiade commented 7 months ago

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 πŸ‘πŸ»

mkosta commented 7 months ago

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