Skip to content

Commit

Permalink
Merge pull request #1038 from naitik30/updating_chunk_size
Browse files Browse the repository at this point in the history
Add configurable SCAN_CHUNK_SIZE for Redis database queries
  • Loading branch information
inlife authored Jan 24, 2025
2 parents 5be6680 + f48d477 commit 5bf5b40
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/nexrender-database-redis/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ npm i @nexrender/database-redis -g
## Configuration

In order to use this, `NEXRENDER_DATABASE_PROVIDER` needs to be set to `redis`.
Also you can define the number of keys to retrieve in a single iteration during the `SCAN` operation using `SCAN_CHUNK_SIZE`. Default is `10`.

```
export NEXRENDER_DATABASE_PROVIDER="redis"
export REDIS_URL="redis://localhost:6379"
export SCAN_CHUNK_SIZE="100"
```
4 changes: 3 additions & 1 deletion packages/nexrender-database-redis/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const client = redis.createClient({
url: process.env.REDIS_URL
});

const scanChunkSize = process.env.SCAN_CHUNK_SIZE? process.env.SCAN_CHUNK_SIZE : '10';

client.getAsync = promisify(client.get).bind(client);
client.setAsync = promisify(client.set).bind(client);
client.delAsync = promisify(client.del).bind(client);
Expand All @@ -16,7 +18,7 @@ const scan = async parser => {
let results = [];

const _scan = async () => {
const [ next, keys ] = await client.scanAsync(cursor, 'MATCH', 'nexjob:*', 'COUNT', '10');
const [ next, keys ] = await client.scanAsync(cursor, 'MATCH', 'nexjob:*', 'COUNT', scanChunkSize);

cursor = next;
results = results.concat(keys);
Expand Down

0 comments on commit 5bf5b40

Please sign in to comment.