Redis set up with ghost

Hi all!

Anyone got a good guide of how to set up REDIS cache with ghost?

My setup is ghost in a docker container and redid in another docker container. Both are working great but I need to link the two…

The docs on this are really confusing as there is a cache helper already and this just needs enabling but then there doesn’t seem to be any way of me inputting my redis hostname and port?

Has anyone got this working and could share the secrets?

Thanks!

Indeed, the documentation about Cache Adapter is not very clear. I managed to run redis cache adapter by reading the source code. Here is how I did it:

Basically, in your ghost config:

{
   ...
   adapters: {
      cache: {
        imageSizes: {
          adapter: "Redis",
          ttl: 3600,
          host: process.env.REDIS_CACHE_HOST,
          port: process.env.REDIS_CACHE_PORT,
          keyPrefix: "mysite:imageSizes"
        },
        stats: {
          adapter: "Redis",
          ttl: 3600,
          host: process.env.REDIS_CACHE_HOST,
          port: process.env.REDIS_CACHE_PORT,
          keyPrefix: "mysite:stats"
        },
        // settings: {},
        gscan: {
          adapter: "Redis",
          ttl: 3600,
          host: process.env.REDIS_CACHE_HOST,
          port: process.env.REDIS_CACHE_PORT,
          keyPrefix: "mysite:gscan"
        },
        linkRedirectsPublic: {
          adapter: "Redis",
          ttl: 3600,
          host: process.env.REDIS_CACHE_HOST,
          port: process.env.REDIS_CACHE_PORT,
          keyPrefix: "mysite:linkRedirectsPublic"
        },
      }
    },

Somehow I couldn’t manage to run cache adapter for “settings”. :man_shrugging:

Brill so adding that to the main config file?

Can I be clear on which bits to change for my setup? Every mention of REDIS_CACHE_HOST with the host and every mention of REDUS_CACHE_PORT with the port?

Does the mysite need changing to the domain also?

Yes, host and port should be the host address and port of your Redis server. key prefixes can be any string, just make sure that every keyPrefix is different.

Ghost and its documentation have always been incomplete, but that doesn’t stop the community.

If you are using Redis version 7.x or later, you have likely implemented the new authentication system, which is through ACL.

Your configuration file should look like the following.

File: /etc/redis/users.acl or wherever you have it.

user default off
user YOURNAME-FOR-MONITOR on >YOUR-LONG-PASSWORD +monitor
user YOUR-GHOST-USARNAME-INSTANCE on >YOUR-LONG-PASSWORD resetkeys ~YOUR-KEYPREFIX:* +@read +info +setex
  • Line 1: We disable the default user.
  • Line 2: We assign a user to use the monitor command and then check that Redis works correctly.
  • Line 3: We assign the username of our Ghost adapter, as well as the keys to be used and the necessary permissions. (Only basic permissions are kept; no admin permissions or dangerous commands are granted.)

The final file should look like the following.

File: /etc/redis/users.acl or wherever you have it.

user default off
user stats on >dsoiro34jrkl34wkrmlekwmflse +monitor
user ghostusr on >dsaiujdoi3joi4uo9sdfu9uw4r9rjfsioe resetkeys ~ghost-images:* +@read +info +setex

In your file: /etc/redis/redis.conf or wherever you have it, look for the line: # aclfile /etc/redis/users.acl and change it to: aclfile /etc/redis/users.acl

Now go to your Ghost file: config.production.json

"adapters": {
   "cache": {
   "imageSizes": {
      "adapter": "Redis",
      "username": "ghostusr",
      "password": "dsaiujdoi3joi4uo9sdfu9uw4r9rjfsioe",
      "ttl": 3600,
      "keyPrefix": "ghost-images:"
   }
   }
},

This is for production instances, without Docker.

I hope this is helpful or relevant to your question.