redis / redis/node-redis

topk commands don't work?

Open
#3,091 2 comments 1 reaction 1 assignee View on GitHub

@nkaradzhov is already working on this.

Since Oct 6, 2025.

Bug
Dominant language
TypeScript
Stars
17.6k
Forks
2k
Avg merge
2d 3h
Merged PRs (30d)
40

Description

Description

When running the stock topk example from the examples folder and using node-redis 5.8.3 I see this:

topk % node topk.js
Error, maybe RedisBloom is not installed?:
TypeError: Cannot read properties of undefined (reading 'reserve')
    at file:///Users/simon/tmp/topk/topk.js:18:21
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
file:///Users/simon/tmp/topk/topk.js:51
  await client.topK.incrBy('mytopk', {
                    ^

TypeError: Cannot read properties of undefined (reading 'incrBy')
    at file:///Users/simon/tmp/topk/topk.js:51:21
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)

Command is in my Redis instance which is a latest Redis Stack Docker container:

127.0.0.1:6379> topk.incrby
(error) ERR wrong number of arguments for 'topk.incrby' command

Running the script:

topk % node topk.js
Error, maybe RedisBloom is not installed?:
TypeError: Cannot read properties of undefined (reading 'reserve')
    at file:///Users/simon/tmp/topk/topk.js:18:21
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
file:///Users/simon/tmp/topk/topk.js:51
  await client.topK.incrBy('mytopk', {
                    ^

TypeError: Cannot read properties of undefined (reading 'incrBy')
    at file:///Users/simon/tmp/topk/topk.js:51:21
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)

Node.js v24.6.0

Code (which is just the example from the examples folder):

// This example demonstrates the use of the Top K
// in the RedisBloom module (https://redis.io/docs/stack/bloom/)

import { createClientPool } from 'redis';

const client = createClientPool({
  url: 'redis://localhost:6379'
});

await client.connect();

// Delete any pre-existing Top K.
await client.del('mytopk');

// Reserve a Top K to track the 10 most common items.
// https://redis.io/commands/topk.reserve/
try {
  await client.topK.reserve('mytopk', 10, { width: 400, depth: 10, decay: 0.9 });
  console.log('Reserved Top K.');
} catch (e) {
  if (e.message.endsWith('key already exists')) {
    console.log('Top K already reserved.');
  } else {
    console.log('Error, maybe RedisBloom is not installed?:');
    console.log(e);
  }
}

const teamMembers = [
  'leibale',
  'simon',
  'guy',
  'suze',
  'brian',
  'steve',
  'kyleb',
  'kyleo',
  'josefin',
  'alex',
  'nava',
  'lance',
  'rachel',
  'kaitlyn'
];

// Add random counts for random team members with TOPK.INCRBY
// https://redis.io/commands/topk.incrby/
for (let n = 0; n < 1000; n++) {
  const teamMember = teamMembers[Math.floor(Math.random() * teamMembers.length)];
  const points = Math.floor(Math.random() * 1000) + 1;
  await client.topK.incrBy('mytopk', {
    item: teamMember,
    incrementBy: points
  });
  console.log(`Added ${points} points for ${teamMember}.`);
}

// List out the top 10 with TOPK.LIST
// https://redis.io/commands/topk.list/
const top10 = await client.topK.list('mytopk');
console.log('The top 10:');
// top10 looks like this:
//   [
//     'guy',     'nava',
//     'kaitlyn', 'brian',
//     'simon',   'suze',
//     'lance',   'alex',
//     'steve',   'kyleo'
// ]
console.log(top10);

// List out the top 10 with their counts (requires RedisBloom >=2.2.9)
// https://redis.io/commands/topk.list/
const top10WithCounts = await client.topK.listWithCount('mytopk');
console.log('The top 10 with counts:');
console.log(top10WithCounts);
// top10WithCounts looks like this:
// [
//    { item: 'suze', count: 42363 },
//    { item: 'lance', count: 41982 },
//    { item: 'simon', count: 41831 },
//    { item: 'steve', count: 39237 },
//    { item: 'guy', count: 39078 },
//    { item: 'kyleb', count: 37338 },
//    { item: 'leibale', count: 34230 },
//    { item: 'kyleo', count: 33812 },
//    { item: 'alex', count: 33679 },
//    { item: 'nava', count: 32663 }
// ]

// Check if a few team members are in the top 10 with TOPK.QUERY:
// https://redis.io/commands/topk.query/
const [ steve, suze, leibale, frederick ] = await client.topK.query('mytopk', [
  'steve',
  'suze',
  'leibale',
  'frederick'
]);

console.log(`steve ${steve ? 'is': 'is not'} in the top 10.`);
console.log(`suze ${suze ? 'is': 'is not'} in the top 10.`);
console.log(`leibale ${leibale ? 'is': 'is not'} in the top 10.`);
console.log(`frederick ${frederick ? 'is': 'is not'} in the top 10.`);

// Get count estimate for some team members with TOPK.COUNT:
// https://redis.io/commands/topk.count/
const [ simonCount, lanceCount ] = await client.topK.count('mytopk', [
  'simon',
  'lance'
]);

console.log(`Count estimate for simon: ${simonCount}.`);
console.log(`Count estimate for lance: ${lanceCount}.`);

client.close();

Script source here fails to create the topk too, it's like no topk commands are working.

Node.js Version

24.6.0

Redis Server Version

7.4.5 (Redis Stack)

Node Redis Version

5.8.3

Platform

macOS

Logs

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.