acl-ioredis
v0.0.2
Published
Adapter that wraps an ioredis client so it works as node_acl's Redis backend client (adds batch() and normalizes pipeline/multi exec replies).
Maintainers
Readme
acl-ioredis
A tiny adapter that lets you use a modern ioredis client with node_acl's Redis backend.
node_acl's Redis backend was written against node_redis v2. ioredis is almost
a drop-in replacement, but two things differ:
| node_acl expects (node_redis) | ioredis provides |
| ----------------------------- | ---------------- |
| client.batch() — non-atomic command queue | client.pipeline() |
| exec() replies as a flat [result \| Error] array | [[err, result], ...] tuples |
This package wraps your ioredis client in a thin Proxy that bridges exactly
those two gaps and forwards everything else untouched. No runtime dependencies.
Install
npm install acl-ioredis ioredisioredis is a peer dependency — you bring your own client (works with >=4,
tested against the latest 5.x).
Usage
const Redis = require('ioredis');
const wrap = require('acl-ioredis');
const acl = require('acl');
// Wrap your ioredis client...
const client = wrap(new Redis({ host: '127.0.0.1', port: 6379 }));
// ...and hand it to node_acl's Redis backend as usual.
const myAcl = new acl(new acl.redisBackend(client, 'myprefix'));
myAcl.addUserRoles('user1', 'admin', function (err) {
// ...
});It also works with Redis.Cluster and with connection URLs:
const client = wrap(new Redis('redis://:[email protected]:6379/0'));API
const wrap = require('acl-ioredis');
wrap(ioredisClient) // → node_acl-compatible client (Proxy)
wrap.createClient(client) // alias
wrap.normalizeReplies(r) // exposed for testing: flattens ioredis exec tuplesThe returned object is a transparent proxy over your ioredis client: every
command (smembers, sunion, sadd, srem, del, keys, ...) passes
straight through. Only batch() (→ pipeline()) and the exec() reply shape
of batch()/multi() are adapted.
Why a separate package?
The Redis backend in node_acl stays unchanged. This adapter only touches the client, so you can upgrade to the latest ioredis without forking node_acl.
Tests
npm testUnit tests run with no dependencies. The integration suite connects to a Redis
on 127.0.0.1:6379 and is skipped automatically if none is reachable.
License
MIT
