{"library":"node-redis-scan","title":"Node Redis Scanner","description":"node-redis-scan is a utility library for Node.js (requiring Node 10+) that simplifies key space scanning in Redis, leveraging the `SCAN`, `HSCAN`, `SSCAN`, and `ZSCAN` commands. It provides a higher-level API over the raw Redis commands, abstracting the cursor management typically required for incremental iteration. The current stable version is 1.3.8, with recent releases primarily focusing on `devDependencies` security updates rather than new features. A key differentiator is its provision of `scan()` for retrieving all matching keys in one go and `eachScan()` for processing keys iteratively as they are found, with the ability to cancel. However, it explicitly supports only `node-redis` client versions 3.x and earlier. Users of `node-redis` v4.x or newer are advised to use the client's built-in `scanIterator()` for similar functionality, which offers async iteration capabilities.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install node-redis-scan"],"cli":null},"imports":["import RedisScan from 'node-redis-scan';","const redisScan = require('node-redis-scan');","import { createClient } from 'redis';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { createClient } from 'redis';\nimport RedisScan from 'node-redis-scan';\n\nasync function runScanExample() {\n  // For node-redis v3.x compatibility, which this library requires.\n  // In a real application, ensure your 'redis' package is v3.x.\n  // Connecting to default Redis instance on localhost:6379\n  const client = createClient();\n\n  client.on('error', (err) => {\n    console.error('Redis Client Error', err);\n    // Handle connection errors gracefully\n  });\n\n  // For node-redis v3.x, you might need to connect manually or await client.connect() if using newer patterns.\n  // The example implies an auto-connecting client.\n\n  const scanner = new RedisScan(client);\n\n  console.log('Starting Redis key scan...');\n  scanner.scan('your-pattern-*', { count: 1000 }, (err, matchingKeys) => {\n    if (err) {\n      console.error('Scan Error:', err);\n      // Properly disconnect if using client.connect()\n      client.quit();\n      return;\n    }\n\n    if (matchingKeys.length > 0) {\n      console.log(`Found ${matchingKeys.length} matching keys:`)\n      console.log(matchingKeys);\n    } else {\n      console.log('No keys matched the pattern.');\n    }\n\n    // Always disconnect the Redis client when done\n    client.quit();\n  });\n}\n\nrunScanExample();","lang":"javascript","description":"This example demonstrates how to instantiate the `node-redis-scan` class with a `node-redis` v3.x client and perform a basic `scan()` operation with a pattern and `count` option.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}