Redis

Iterapp apps (and applings) can opt in to receive a redis instance configured for LFU (Least Frequently Used) caching.

[redis_lfu_cache]
enabled = true

Each appling or app that opts in to redis will get their own redis instance for every environment. If you use applings and have the above in the root level iterapp.toml, all applings will get a shared instance. If the configuration is in a appling's iterapp.toml, it will get its own instance.

About the configuration

This redis instance will be configured as a lfu cache. It does not have persistence. This means that data will be lost when the instance is restarted, which will happen pretty regulary.

The least used keys will be deleted if the instance use more than 100MB of memory. This mean that you can cache as much data as you want, and only the most used will be kept. See also the redis reference, especially the section about LFU caching.

Your instance's redis user has some of the commands disabled, mostly to avoid accidental changing of configuration. If you wan't to add some commands that are left out, let us know.

This is the important lines from the configuration that are generated for your instance:

maxmemory 100mb
maxmemory-policy allkeys-lfu
save ""
user default +@all -@dangerous +keys +info +sort +flushall +flushdb allkeys allchannels on >INSTANCE_PASSWORD

Connecting to the redis instance

Your app will receive a environment variable, REDIS_URL, which contain all the required config used to connect to the instance. For instance, if you are using node and ioredis:

const Redis = require('ioredis');
const redis = new Redis(process.env.REDIS_URL);

async function main() {
  await redis.set('my-key', '42');

  let value = await redis.get('my-key');
  console.log(value);
}

Environment variables

If you use client library that does not support a REDIS_URL, the parameters are also exported as individual environment variables. This is all the variables that are available to your app(ling).

REDIS_URL
REDIS_PASSWORD
REDIS_HOST
REDIS_USER
REDIS_PORT