Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/derhuerst/redis-iterate-keys

Iterate over keys in Redis, using the SCAN command.
https://github.com/derhuerst/redis-iterate-keys

Last synced: 6 days ago
JSON representation

Iterate over keys in Redis, using the SCAN command.

Awesome Lists containing this project

README

        

# redis-iterate-keys

**Iterate over keys in [Redis](https://redis.io/)**, using the [`SCAN` command](https://redis.io/commands/scan).

[![npm version](https://img.shields.io/npm/v/redis-iterate-keys.svg)](https://www.npmjs.com/package/redis-iterate-keys)
[![build status](https://api.travis-ci.org/derhuerst/redis-iterate-keys.svg?branch=master)](https://travis-ci.org/derhuerst/redis-iterate-keys)
![ISC-licensed](https://img.shields.io/github/license/derhuerst/redis-iterate-keys.svg)
![minimum Node.js version](https://img.shields.io/node/v/redis-iterate-keys.svg)
[![chat with me on Gitter](https://img.shields.io/badge/chat%20with%20me-on%20gitter-512e92.svg)](https://gitter.im/derhuerst)
[![support me via GitHub Sponsors](https://img.shields.io/badge/support%20me-donate-fa7664.svg)](https://github.com/sponsors/derhuerst)

## Installation

```shell
npm install redis-iterate-keys
```

## Usage

```js
const Redis = require('ioredis')
const iterateKeys = require('redis-iterate-keys')

const redis = new Redis()
for await (const key of iterateKeys(redis)) {
console.log(key)
}
redis.quit()
```

```js
iterateKeys(redisClient, opt = {})
```

You can pass the following options:

- `opt.match`: Match keys with a pattern, see the [`MATCH` docs](https://redis.io/commands/scan#the-match-option)
- `opt.batchSize`: How many keys to retrieve in one `SCAN` call. Set it to a higher number for higher iteration speed. Default: 20

## Related

- [`redis-scanrx`](https://github.com/sukobuto/redis-scanrx) – Rx interface to Redis `SCAN`.
- [`redis-skim`](https://github.com/mattbudish/redis-skim) – Callback interface to Redis `SCAN`.

## Contributing

If you have a question or need support using `redis-iterate-keys`, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, use [the issues page](https://github.com/derhuerst/redis-iterate-keys/issues).