IBM Cloud Docs
Configuring as persistence

Configuring as persistence

Redis is recognized for its high-performance key-value database, notable for storing all data in RAM to avoid slow disk access. Nonetheless, this RAM-centric approach poses a risk of data loss in the event of a Redis process or host incident, given the volatile nature of RAM. To address this concern, Redis offers mechanisms for persisting data on disk.

Persistence modes in Redis

There are two primary persistence modes available: RDB (snapshot mode) and AOF (strong persistence). Each mode entails distinct trade-offs in terms of performance and reliability. Hence, selecting the appropriate persistence mode in Redis necessitates a strategic decision.

RDB snapshot

Redis saves snapshots of the dataset on disk in a binary file called dump.rdb. The dataset is saved every N seconds if there are at least M changes.

  • Save 3600 1: Every hour if at least one key has changed.
  • Save 300 100: Every 5 minutes if at least 100 keys have changed.
  • Save 60 10000: Every minute if at least 10,000 keys have changed.

AOF (Append only File)

With AOF enabled, Redis persists data by logging every write operation received by the service. AOF is configured by fsync policy, ensuring data durability.

  • Always: Safest but with lowest performance.
  • Everysec (default): Safe with better performance.
  • No: Typically relies on the operating system to decide when to perform fsync, which is usually around 30 seconds (unsafe but provides the best performance).

For more information, see Redis persistence.

Set up persistence in Databases for Redis

In IBM Cloud® Databases for Redis deployment, both RDB snapshot and AOF are enabled by default on provisioning and your data is written to disk. However, users can disable AOF to use Databases for Redis as a cache, which alleviates the IOPS load, resulting in better performance.

Databases for Redis operates in high-availability, wherein RDB snapshots cannot be disabled.

  1. Follow these steps to provision a Databases for Redis instance.

  2. Check the persistence setting by verifying Databases for Redis configuration. Access the ICD Redis instance using Redis CLI.

    As the default, AOF is set to yes, so Databases for Redis is configured to take AOF persistence with fsync every second along with RDB snapshots.

    AOF can be turned off if you want to use Redis as a cache. This can also increase database availability, as the Redis process doesn’t have to replay the transaction logs in case of a failover. For more information, see Configuring Redis as a cache.

Reconfigure a Databases for Redis as a persistent setting

To configure changes to a Databases for Redis instance, you must utilize either the IBM Cloud CLI or API for configuring persistence, as in the following example.

Adjust the following settings:

  • Set appendonly to yes to enable AOF persistence.
  • Ensure maxmemory-policy is set to noeviction to prevent key expiration.
  • Set stop-writes-on-bgsave-error to yes to halt writes in case of backup errors.

CLI example

ibmcloud cdb deployment-configuration '<deployment name or CRN>' '{"configuration":{"maxmemory-policy":" noeviction", "appendonly":"yes", "stop-writes-on-bgsave-error":"yes"}}'

API example

curl -X PATCH 'https://api.{region}.databases.cloud.ibm.com/v4/ibm/deployments/{id}/configuration/schema' -H "Authorization: Bearer $APIKEY" -H "Content-Type: application/json" -d '{"configuration":{ "maxmemory-policy":""noeviction, "appendonly":"yes", "stop-writes-on-bgsave-error":"yes" } }'