# pub-src-redis

> redis source for pub-server and pub-generator - also provides cache for other sources

Latest version **3.0.0** (published 2026-02-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install pub-src-redis
pnpm add pub-src-redis
yarn add pub-src-redis
bun add pub-src-redis
```

## Health

**Score 45/100 (D)** — status: stable.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2026-02-22 |
| First published | 2015-04-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 15 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jürgen Leschner |
| Maintainers | jldec |

## Links

- npm: https://www.npmjs.com/package/pub-src-redis
- Repository: https://github.com/jldec/pub-server-monorepo
- Homepage: https://github.com/jldec/pub-server-monorepo#readme
- Issues: https://github.com/jldec/pub-server-monorepo/issues
- npm.io page: https://npm.io/package/pub-src-redis

## Dependencies (4)

- [debug](https://npm.io/package/debug.md) 4.3.6
- [redis](https://npm.io/package/redis.md) ^3.1.2
- [pub-util](https://npm.io/package/pub-util.md) 4.0.0
- [pub-src-fs](https://npm.io/package/pub-src-fs.md) 3.0.0

## Recent versions

- 3.0.0 (latest) — 2026-02-22
- 2.4.0 — 2024-09-04
- 2.3.0 — 2024-09-04
- 2.2.0 — 2024-09-01
- 2.1.1 — 2022-01-16
- 2.1.0 — 2021-05-09
- 2.0.3 — 2020-11-08
- 2.0.2 — 2020-09-13
- 2.0.1 — 2020-08-09
- 2.0.0 — 2020-07-26
- 1.3.2 — 2020-05-25
- 1.3.1 — 2020-04-26
- 1.3.0 — 2020-02-18
- 1.2.5 — 2019-07-13
- 1.2.4 — 2019-04-28
- … 24 more at https://npm.io/package/pub-src-redis/versions

## README

# pub-src-redis
redis source for pub-server and pub-generator - also provides cache for other source

* uses a redis hash to map file.path to file.text
* supports non-FILE type (opaque) sources with simple key->data get and set
* provides `get()` and `put()` for bulk reads and writes
* also provides `cache()` to proxy-cache another source.
  This is useful for avoiding startup delays on slow/remote sources like github.

NOTE: This library uses [node-redis](https://github.com/redis/node-redis) v3.x because of difficulties upgrading this codebase to v4.x.

## src(options)

```javascript
var src = require('pub-src-redis');

// instantiate source
// options become properties of source
var source = src( { name:'redis-source' } );

// use redis as a cache
source.cache(otherSource, { writeThru:false });

```

### configuring redis keyname
- the redis keyname is derived from `source.name || source.path`

### redis auth
- auth configuration has to come from `process.env.RCA`
- redis host and port can be configured the same way, or via `source.host` and `source.port`

```sh
export RCA={auth-pass}
export RCH={host}
export RCP={port}
```

### source.get(cb)
- `get()` uses `hgetall` to fetch the entire hash in one async operation - no filtering is provided
- the result is an array of file objects each with a `path:` and a `text:` property
- the array is sorted alphabetically by path, as if the files came from a directory tree

### source.put(files, cb)
- `put()` does nothing unless `writable` is set on the source
- it uses `hmset` to write an array of file objects, overwriting any existing files with the same path
- there is no partial file write but the array may contain a subset of the files read via `get()`

### source.cache(src, [cacheOpts])

- interposes `src.get()` and `src.put()`, for a different source (src) like github.

- `src.get()` will read from src on the first call, and subsequently read only from redis,
  unless the option `get({fromSource:true}, cb)` is used

- `src.put()` will write directly to redis.
   `cacheOpts.writeThru` means that `put()` will also write to src before returning

- `src.commit()` writes a single file from cache back to source - only available if `!cacheOpts.writeThru`.

- `src.revert()` reverts a single file from source - only available if `!cacheOpts.writeThru`.

### source.clear(cb)
- redis-specific api - used mainly for testing
- deletes the key used by this src and everything in it - use with care

### source.unref()
- redis-specific api - e.g. used by `pub -O`
- allows the server to exit after creating an instance of src-redis
- for more information, see [node_redis](https://github.com/mranney/node_redis#clientunref)

---
_Source: https://npm.io/package/pub-src-redis · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
