Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@retlehs
Copy link
Member

@retlehs retlehs commented Aug 3, 2025

This PR adds native Redis support to Trellis πŸŽ‰

Redis configuration incorporated from @jasonsbarr's https://github.com/jasonsbarr/trellis-redis community role

TODO

Configuration examples

FastCGI page caching + Redis object caching:

cache:
  enabled: true     # FastCGI page caching

object_cache:
  enabled: true     # Object caching  
  provider: redis   # Using Redis
  database: 0       # Redis database number

Backward Compatible (Unchanged)

Existing configurations work unchanged:

cache:
  enabled: true  # FastCGI page caching only

Multiple Sites with Isolated Redis Databases

# Site 1
wordpress_sites:
  site1.com:
    cache:
      enabled: true
    object_cache:
      enabled: true
      provider: redis
      database: 0

# Site 2
wordpress_sites:
  site2.com:
    cache:
      enabled: true
    object_cache:
      enabled: true
      provider: redis
      database: 1
Full examples

Detailed Basic Configurations

FastCGI Cache Only (Default)

wordpress_sites:
  example.com:
    cache:
      enabled: true  # FastCGI page caching only
      duration: 30s

Redis Object Cache Only

For sites that need object caching without page caching:

wordpress_sites:
  example.com:
    cache:
      enabled: false     # Disable FastCGI page caching
    object_cache:
      enabled: true
      provider: redis
      database: 0

Multiple Sites

Isolated Redis Databases

Each site uses a different Redis database:

wordpress_sites:
  site1.com:
    cache:
      enabled: true
    object_cache:
      enabled: true
      provider: redis
      database: 0      # Redis DB 0

  site2.com:
    cache:
      enabled: true
    object_cache:
      enabled: true
      provider: redis
      database: 1      # Redis DB 1

  site3.com:
    cache:
      enabled: true
    object_cache:
      enabled: true
      provider: redis
      database: 2      # Redis DB 2

Mixed Cache Strategies

Different caching approaches per site:

wordpress_sites:
  # High-traffic marketing site (page cache only)
  marketing.com:
    cache:
      enabled: true
      duration: 300s    # 5-minute page cache

  # Database-heavy application (both caches)
  app.com:
    cache:
      enabled: true
      duration: 30s
    object_cache:
      enabled: true
      provider: redis   # Adds object caching
      database: 0

  # Development site (no caching)
  dev.com:
    cache:
      enabled: false

Advanced Redis Configurations

Custom Redis Settings

wordpress_sites:
  example.com:
    cache:
      enabled: true
    object_cache:
      enabled: true
      provider: redis
      host: 127.0.0.1
      port: 6379
      database: 0
      password: secret_password
      prefix: mysite_

Memcached Alternative

Using Memcached instead of Redis:

wordpress_sites:
  example.com:
    cache:
      enabled: true
    object_cache:
      enabled: true
      provider: memcached
      host: 127.0.0.1
      port: 11211
      prefix: mysite_

Global Redis Configuration

Customize Redis server settings in group_vars/all/main.yml:

Increase Memory

redis_maxmemory: 512mb

Enable Password Protection

redis_requirepass: your_secure_password

Enable Persistence

redis_appendonly: "yes"
redis_save:
  - "900 1"
  - "300 10"
  - "60 10000"

Custom Configuration

redis_extra_config:
  tcp-backlog: 511
  tcp-keepalive: 300
  supervised: systemd

@retlehs retlehs self-assigned this Aug 3, 2025
@retlehs retlehs changed the title 🚧 Add Redis object cache support ✨ Add Redis object cache support Aug 3, 2025
@retlehs retlehs marked this pull request as ready for review August 3, 2025 17:57
@retlehs retlehs requested a review from swalkinshaw August 3, 2025 17:57
@tangrufus
Copy link
Member

Question: Which redis plugin do we recommand?

@retlehs
Copy link
Member Author

retlehs commented Aug 5, 2025

The Redis Cache one for now, https://gist.github.com/retlehs/c2bcfedd2fac32e1c7759e2ae10a671e#wordpress-plugin-installation is going to be used for docs FYI

@swalkinshaw

This comment was marked as resolved.

@retlehs retlehs requested review from swalkinshaw and removed request for swalkinshaw August 10, 2025 19:47
@retlehs
Copy link
Member Author

retlehs commented Aug 10, 2025

Updated πŸ‘

@retlehs retlehs requested a review from tangrufus August 11, 2025 03:15
Copy link
Member

@swalkinshaw swalkinshaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸŽ‰

@retlehs retlehs merged commit 2517385 into master Aug 15, 2025
2 checks passed
@retlehs retlehs deleted the redis-cache branch August 15, 2025 01:16
@strarsis
Copy link
Contributor

I use this deploy-hooks/finalize-after/99-flush-cache.yml:

- name: Flush cache/object-cache (as with Redis)
  command: wp cache flush
  args:
    chdir: "{{ deploy_helper.current_path }}"

Would this be helpful?

@retlehs
Copy link
Member Author

retlehs commented Aug 18, 2025

@strarsis Thanks for bringing that up! I think that might be helpful for us to add to the deployment process regardless of object cache being setup on a site? πŸ‘€

@strarsis
Copy link
Contributor

Yes, clearing the cache solved many strange issues after deployment for me.

@retlehs
Copy link
Member Author

retlehs commented Aug 18, 2025

Want to do a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants