Skip to content
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

sRandMember seems to not support the count argument #2732

Open
atuttle opened this issue Apr 3, 2024 · 2 comments
Open

sRandMember seems to not support the count argument #2732

atuttle opened this issue Apr 3, 2024 · 2 comments
Labels

Comments

@atuttle
Copy link

atuttle commented Apr 3, 2024

Description

I feel like I'm going crazy! How can this not work for such a widely used project?

Redis console, showing that my redis server does the right thing and returns more than 1 row back (yes, the rows are intentionally ~identical, this is test data)

IQ Prod NEW v7:0>SRANDMEMBER "MQ:click-track:LAWR:QA"
"{"ml":"00225535-5c1d-4986-a93b3d7c27e5b427","mc":"0D6DD930-F41E-856C-42796C6D1F84A46F","ts":"2024-04-03T19:05:50.586Z","referer":null}"
IQ Prod NEW v7:0>SRANDMEMBER "MQ:click-track:LAWR:QA" 100
1) "{"ml":"00225535-5c1d-4986-a93b3d7c27e5b427","mc":"0D6DD930-F41E-856C-42796C6D1F84A46F","ts":"2024-04-03T19:14:55.533Z","referer":null}"
2) "{"ml":"00225535-5c1d-4986-a93b3d7c27e5b427","mc":"0D6DD930-F41E-856C-42796C6D1F84A46F","ts":"2024-04-03T19:05:50.586Z","referer":null}"
3) "{"ml":"00225535-5c1d-4986-a93b3d7c27e5b427","mc":"0D6DD930-F41E-856C-42796C6D1F84A46F","ts":"2024-04-03T19:14:52.653Z","referer":null}"
4) "{"ml":"00225535-5c1d-4986-a93b3d7c27e5b427","mc":"0D6DD930-F41E-856C-42796C6D1F84A46F","ts":"2024-04-03T19:01:21.925Z","referer":null}"

But now a node REPL showing that some commands return multiple rows still work as expected (SMEMBERS), but SRANDMEMBER only ever returns 1 row, both with and without the count argument:

node
Welcome to Node.js v18.20.0.
Type ".help" for more information.
> const redis = /* connect to redis server */
undefined
> await redis.SMEMBERS('MQ:click-track:LAWR:QA');
[
  '{"ml":"00225535-5c1d-4986-a93b3d7c27e5b427","mc":"0D6DD930-F41E-856C-42796C6D1F84A46F","ts":"2024-04-03T19:14:55.533Z","referer":null}',
  '{"ml":"00225535-5c1d-4986-a93b3d7c27e5b427","mc":"0D6DD930-F41E-856C-42796C6D1F84A46F","ts":"2024-04-03T19:05:50.586Z","referer":null}',
  '{"ml":"00225535-5c1d-4986-a93b3d7c27e5b427","mc":"0D6DD930-F41E-856C-42796C6D1F84A46F","ts":"2024-04-03T19:14:52.653Z","referer":null}',
  '{"ml":"00225535-5c1d-4986-a93b3d7c27e5b427","mc":"0D6DD930-F41E-856C-42796C6D1F84A46F","ts":"2024-04-03T19:01:21.925Z","referer":null}'
]
> await redis.SRANDMEMBER('MQ:click-track:LAWR:QA');
'{"ml":"00225535-5c1d-4986-a93b3d7c27e5b427","mc":"0D6DD930-F41E-856C-42796C6D1F84A46F","ts":"2024-04-03T19:14:52.653Z","referer":null}'
> await redis.SRANDMEMBER('MQ:click-track:LAWR:QA', 100);
'{"ml":"00225535-5c1d-4986-a93b3d7c27e5b427","mc":"0D6DD930-F41E-856C-42796C6D1F84A46F","ts":"2024-04-03T19:01:21.925Z","referer":null}'
>

Node.js Version

18.20.0

Redis Server Version

7.0.7

Node Redis Version

1.5.14

Platform

MacOS, Linux (AWS Lambda)

Logs

No response

@atuttle atuttle added the Bug label Apr 3, 2024
@atuttle
Copy link
Author

atuttle commented Apr 3, 2024

Digging through the code, we found that it does work but it's been split into a separate command:

redis.SRANDMEMBER_COUNT("key", count);

Is that intentional? Is it documented anywhere?

@leibale
Copy link
Collaborator

leibale commented Apr 3, 2024

@atuttle The reason is to have better TS support (i.e. SRANDMEMBER returns a string, SRANDMEMBER_COUNT returns an Array<string>). TBH I'm not too sure if it's mentioned in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants