Problem/Motivation

Some Drupal users may want to use Redis as a caching solution, but have no experience at all with setting it up.

Perhaps we can list the minimal steps required to get Redis up and running in popular environments, such as DDEV and a standard Debian Apache server?

Steps to reproduce

Look at the documentation and feel overwhelmed.

Proposed resolution

List the basic steps to set up Redis in popular environments, such as DDEV and a standard Debian Apache server.

The text below is adapted from these articles:

Setting up Redis in DDEV

Install Redis, as you would normally install a Drupal module.

Install the DDEV Redis add-on and restart DDEV. A new service is created, and the required Redis settings files are added automatically in web/sites/default/settings.ddev.redis.php:

$ ddev get ddev/ddev-redis
$ ddev restart

You should be good to go; Drupal will store its cache in the Redis database. Check by visiting a cached page, then open the Redis command line with ddev redis-cli, type KEYS *, and press "Enter" (you should see many lines):

user@my-os:~/d11$ ddev redis-cli
redis:6379> KEYS *
  1) "drupal.redis.11.1.2..9d1624a8107bff73ae7af14c80a445f594b449fda83e3d7aec06b888c9966d1e:data:route_provider [...]

Verify if Redis is used by issuing the MONITOR command in the Redis CLI tool. Browse the site, and you should see a lot of queries:

user@my-os:~/d11$ ddev redis-cli
redis:6379> MONITOR
1759182999.868342 [0 172.19.0.5:60202] "HGETALL" "drupal.redis.11.1.2..9d1624a8107bff73ae7af14c80a445f594b [...]

Adapted from https://cyberschorsch.dev/drupal/elevating-drupals-capabilities-redis-ad....

Setting up Redis on Debian/Apache server

Install the Redis package (which creates a new service) and the PHP Redis extension on the server, and enable it:

$ sudo apt install redis-server php-redis
$ sudo phpenmod redis

Check if it is running:

$ sudo service redis status

Make it start automatically after every boot:

$ sudo systemctl enable redis-server

Redis settings

To set up Redis settings on the server, copy the content of https://git.drupalcode.org/project/redis/-/blob/2.x/settings.redis.examp... into the web/sites/default/settings.php file (leave out the first line, with <?php).

It sets up the basic settings for Redis, and includes additional optional settings.

Verify with redis-cli that Redis is working and caching content. Congratulations, you are now caching with Redis!

Additional information

For more background on installation and configuration, for example Redis performance tuning:

Remaining tasks

Decide if this can be added in a documentation page?

User interface changes

API changes

Data model changes

Issue fork redis-3549366

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

ressa created an issue. See original summary.

ressa’s picture

Issue summary: View changes
ressa’s picture

Issue summary: View changes
ressa’s picture

Issue summary: View changes
ressa’s picture

Issue summary: View changes
ressa’s picture

Issue summary: View changes
berdir’s picture

You're welcome to extend the readme files that come with this module, they are used to generate the docs.

The default/example configuration is already documented and exists as an example, I don't think that needs to be duplicated, just linked.

ressa’s picture

Thanks for a fast and positive reply, that sounds great.

With "The default/example configuration", do you mean this file, or is it another one?

https://git.drupalcode.org/project/redis/-/blob/2.x/settings.redis.examp...

Because if that's the one, it's not clear which parts are necessary, and which are not ... I envision having a simple chunk of settings (as in the proposal) which can be copy-pasted. But of course, the settings.redis.example.php file should certainly be linked to, for details.

berdir’s picture

Yes, that file, and every line there is documented and explained. That's the recommended starting point. No change is necessary for a local setup with redis on default port. Several lines in your snippet are unnecessary/the default.

ressa’s picture

Issue summary: View changes

I see, thanks for clarifying, I greatly appreciate it! I only skimmed that file quickly, and the content didn't look like something I could paste into a settings.php file ... But having now read it, and glanced over the README.md also, I got a better understanding, and got it -- it should be copy-pasted "as is", and I updated the proposed text in the Issue Summary.

I envision this to be a Quick Start style section, to get new users started quickly, so they can take a deeper dive afterwards, for more options.

ressa’s picture

Status: Active » Needs work

I added it now, but at the very top ... Do you think it's too much? From my perspective, it's always about giving new users a head start, the experienced Redis user can always scroll further down. And with that though, I added a table of contents, to help make it clearer, which information is available in the README ... I also streamlined the format, to align a bit more with the README template.

I haven't yet tested the Debian-flavor server set up part, but will do that and change to "Needs review" as soon as I have.

ressa’s picture

Status: Needs work » Needs review

I have now gone through the Debian server part, and it's ready for a review.

ressa’s picture

I added a new Clear caches and disable snapshots section and some parts are not Drupal specific ... but would it be all right to include them? I think it can help new users.

Or it could be added under a new https://www.drupal.org/docs/extending-drupal/contributed-modules/redis documentation Guide -- though having documentation in one place, in GitLab README's is also nice.

berdir’s picture

Status: Needs review » Needs work

Added comments. This is the canonical documentation for this module and linked from the project page, there is no documentation guide and no plans to add that.

ressa’s picture

Status: Needs work » Needs review

Thanks @berdir for your patience explaining things to me, and a fast and thorough review. I love how I can simplify things, and it was really great for me to be able to use a single settings.redis.php file, and remove the one from DDEV.

I agree with all your suggestions, and have tried to implement them in the README, and look forward to your feedback.

ressa’s picture

I needed to do some Redis debugging today, and was reminded about this MR, and it helped me :)

Wouldn't it be great to complete this, since it's probably close to ready? If it would help getting this MR over the finishing line, if I added answers to the comments in your review, I'll of course do that, but I basically attempted to implement all your suggestions.

berdir’s picture

Status: Needs review » Needs work

Did another review, all I have time for now, I'll probably do a last pass myself if you can address the feedback

ressa’s picture

Status: Needs work » Needs review

Great feedback, thanks! I have updated the MR, and I think the README looks pretty good now.

berdir’s picture

Title: Document the most basic set up for DDEV and server » Document the most basic set up for DDEV, improve documentation.

I did a full pass on the README.md and restructured it. All things that are configured in Drupal are now in one section and all things for redis itself in another.

I also added docs on igbinary, updated and elaborated on the expiration policy and TTL configuration and recommendations for that.

  • berdir committed ee28d473 on 2.x authored by ressa
    [#3549366] feat: Document the most basic set up for DDEV, improve...
berdir’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • berdir committed 49a19a6a on 8.x-1.x authored by ressa
    [#3549366] feat: Document the most basic set up for DDEV, improve...
ressa’s picture

Looks great, thanks @berdir.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.