Registry / database / adonis-redis

adonis-redis

JSON →
library1.0.1jsnpmunverified

Adonis Redis is the official Redis provider for the AdonisJS framework (v4.x LTS). Version 1.0.1 wraps ioredis and provides a convenient way to configure, connect, and use Redis within AdonisJS applications. It supports multiple connections, Pub/Sub, and cluster configuration. Released as part of the AdonisJS ecosystem, it follows the same release cadence as the framework itself. Compared to using ioredis directly, it integrates seamlessly with AdonisJS's IoC container and configuration system.

npm install adonis-redis
INSTALL
IMPORT
SIG · ADONIS-REDIS
A
adonis-redis
databasejavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Redis
const Redis = use('Redis')
import Redis from 'adonis-redis'
AdonisJS uses the IoC container; always use the `use()` helper with the alias 'Redis'.
RedisFactory
const RedisFactory = use('Adonis/Addons/RedisFactory')
const RedisFactory = require('adonis-redis/providers/RedisFactory')
Factory is accessible via IoC, not direct require. Only used when you need to create custom connections.
register providers in app.js
const providers = ['adonis-redis/providers/RedisFactory', 'adonis-redis/providers/Redis']
const providers = ['adonis-redis']
Both providers must be registered individually in bootstrap/app.js.

Shows complete setup: register providers, configure Redis, and use in a controller with caching.

// In bootstrap/app.js const providers = [ '@adonisjs/framework/providers/AppProvider', 'adonis-redis/providers/RedisFactory', 'adonis-redis/providers/Redis' ] const aliases = { Redis: 'Adonis/Addons/Redis' } // In config/redis.js module.exports = { connection: 'redis', redis: { host: process.env.REDIS_HOST || '127.0.0.1', port: process.env.REDIS_PORT || 6379, password: process.env.REDIS_PASSWORD || '', db: 0 } } // In your controller const Redis = use('Redis') class UserController { async show({ params }) { const cached = await Redis.get(`user:${params.id}`) if (cached) { return JSON.parse(cached) } const user = await User.find(params.id) await Redis.set(`user:${params.id}`, JSON.stringify(user), 'EX', 3600) return user } }
Debug
Known issues
gotchaBoth RedisFactory and Redis providers must be registered in bootstrap/app.js. Missing either will cause 'Redis is not defined' errors.
fix
Add both 'adonis-redis/providers/RedisFactory' and 'adonis-redis/providers/Redis' to providers array.
affects: >=1.0
gotchaThe alias 'Redis' must be defined in aliases object; the IoC key 'Adonis/Addons/Redis' is required.
fix
Add Redis: 'Adonis/Addons/Redis' to aliases in bootstrap/app.js.
affects: >=1.0
deprecatedAdonisJS 4.x is in LTS mode; consider migrating to AdonisJS 5 which uses @adonisjs/redis package.
fix
For AdonisJS 5, use @adonisjs/redis instead and follow v5 documentation.
affects: >=1.0
gotchaUsing promises with Redis methods: ioredis methods return promises, but inside AdonisJS async/await is recommended. Missing await can lead to unexpected behavior.
fix
Use await Redis.get(...) or .then().
affects: >=1.0
gotchaConfiguration must be in config/redis.js; using environment variables directly in the file is allowed.
fix
Create config/redis.js with the required connection object.
affects: >=1.0
Errors
Common errors & fixes
Redis is not defined
Redis provider not registered or alias not set in bootstrap/app.js
fix
Register both providers and add Redis alias as shown in quickstart.
Error: connect ECONNREFUSED 127.0.0.1:6379
Redis server not running or connection config incorrect
fix
Start Redis server or update config/redis.js with correct host/port.
TypeError: Redis.get is not a function
Using the wrong import; need to use 'use("Redis")' after setup
fix
Use const Redis = use('Redis') after registering providers.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
ioredisrequiredUnderlying Redis client used by the provider
Agent activity
38 hits · last 30 days
node
32
OpenAI (training)
1
Resources
adonis-redis — npm install adonis-redis · libregistry