Managing Heroku Redis Using the CLI
Last updated May 16, 2022
Table of Contents
Heroku Redis is integrated directly into the Heroku CLI and offers several commands for managing a Redis instance.
To see all Redis instances provisioned by your application and to identify the characteristics of each, use the
heroku redis:info command.
$ heroku redis:info === maturing-deeply-2628 (REDIS_URL) Plan Premium 0 Status Available Created 2015-03-26 23:40 UTC Timeout 60 Maxmemory volatile-lru Maintenance window Mondays 22:30 to Tuesdays 02:30 UTC Persistence AOF === maturing-calmly-4191 (HEROKU_REDIS_AMBER_URL) Plan Premium 1 Status Available Created 2015-03-20 23:40 UTC Timeout 0 Maxmemory noeviction Maintenance window Mondays 22:30 to Tuesdays 02:30 UTC Persistence AOF
To establish a Redis CLI session with your remote Redis instance, use
heroku redis:cli. If you don’t specify an instance, then the instance located at REDIS_URL is used by default.
$ heroku redis:cli -a myapp -c myapp Connecting to maturing-deeply-2628 (REDIS_URL): ec2-54-221-206-137.compute-1.amazonaws.com:6379> PING PONG ec2-54-221-206-137.compute-1.amazonaws.com:6379>
If there are multiple instances, specify the instance to connect to. As a shorthand, you can specify the
HEROKU_REDIS_<color> config var name as the first argument to the command, or the resource name
$ heroku redis:cli HEROKU_REDIS_AMBER $ heroku redis:cli maturing-deeply-2628
Heroku Redis provides convenient access to the credentials and location of your instance. This makes it easier to use a GUI to access your instance.
The instance name argument must be provided with the
redis:credentials command. Use REDIS_URL for your primary data store.
$ heroku redis:credentials REDIS_URL redis://h:firstname.lastname@example.org:6379
It’s a good security practice to rotate the credentials for important services on a regular basis. On Heroku Redis, use
heroku redis:credentials --reset to rotate credentials.
$ heroku redis:credentials HEROKU_REDIS_GRAY_URL --reset
When you issue this command, new credentials are created for your instance and the related config vars on your Heroku application are updated.
All of the open connections remain open until the currently running tasks complete. This is to make sure that any background jobs or other workers running on your production environment aren’t abruptly terminated, potentially leaving the system in an inconsistent state. Any new connections opened after the credentials rotation has been run but before dynos have restarted with the new value of the config var will fail.
In configurations where with multiple Redis instances provisioned, it is often necessary to promote an instance to the primary role. You can promote an instance using the
heroku redis:promote command.
$ heroku redis:promote shining-surely-6441 -a myapp Promoting shining-surely-6441 to REDIS_URL on myapp
redis:promote works by setting the value of the
REDIS_URL config var (which your application uses to connect) to the newly promoted instance’s URL and restarting your app. The old primary Redis instance location is still accessible via its
After a promotion, the demoted instance is still provisioned and incurring charges. If it’s no longer needed, remove it with
heroku addons:destroy maturing-deeply-2628.
To change the number of seconds Redis waits before killing idle connections, use the
$ heroku redis:timeout maturing-deeply-2628 --seconds 60 Timeout for maturing-deeply-2628 (REDIS_URL) set to 60 seconds. Connections to the redis instance will be stopped after idling for 60 seconds.
To change the key eviction policy used when an instance reaches its storage limit, use the
$ heroku redis:maxmemory maturing-deeply-2628 --policy volatile-lru Maxmemory policy for maturing-deeply-2628 (REDIS_URL) set to volatile-lru. volatile-lru evicts keys trying to remove the less recently used keys first, but only those that have an expiry set.
Heroku Redis supports keyspace notifications. To configure this, use the
$ heroku redis:keyspace-notifications maturing-deeply-2628 --config AKE Keyspace notifications for maturing-deeply-2628 (REDIS_URL) set to 'AKE'.
A number of possible configurations are possible. Consult
heroku help redis:keyspace-notifications for more.
Resets the statistics on your Heroku Redis instance. This article outlines the statistics that are reset:
$ heroku redis:stats-reset maturing-deeply-2628 ▸ WARNING: Irreversible action. ▸ All stats covered by RESETSTAT will be reset on maturing-deeply-2628. ▸ To proceed, type sushi or re-run this command with --confirm sushi > sushi Stats reset successful.