From f70dc8acb242a17a844843d022c77be99825da59 Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 26 Mar 2025 23:47:47 +0100 Subject: [PATCH] Clarify VRANDMEMBER tradeoff. --- vset.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/vset.c b/vset.c index f53e20da7..33ffb8b32 100644 --- a/vset.c +++ b/vset.c @@ -1501,7 +1501,14 @@ int VRANDMEMBER_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int RedisModule_FreeDict(ctx, returned); } else { /* For large samples, get a random starting node and walk - * the list. */ + * the list. + * + * IMPORTANT: doing so does not really generate random + * elements: it's just a linear scan, but we have no choices. + * If we generate too many random elements, more and more would + * fail the check of being novel (not yet collected in the set + * to return) if the % of elements to emit is too large, we would + * spend too much CPU. */ hnswNode *start_node = hnsw_random_node(vset->hnsw, 0); hnswNode *current = start_node;