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:
- https://cyberschorsch.dev/drupal/elevating-drupals-capabilities-redis-ad...
- https://blog.oloma.dev/redis-server-and-php-extension-installation-on-ub...
- https://davidloor.com/en/blog/drupal-caching-opcache-apcu-redis-memcache...
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 restartYou 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, typeKEYS *, 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 redisCheck if it is running:
$ sudo service redis statusMake it start automatically after every boot:
$ sudo systemctl enable redis-serverRedis 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.phpfile (leave out the first line, with<?php).It sets up the basic settings for Redis, and includes additional optional settings.
Verify with
redis-clithat 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
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
Comment #2
ressaComment #3
ressaComment #4
ressaComment #5
ressaComment #6
ressaComment #7
berdirYou'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.
Comment #8
ressaThanks 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.phpfile should certainly be linked to, for details.Comment #9
berdirYes, 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.
Comment #10
ressaI 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.
Comment #12
ressaI 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.
Comment #13
ressaI have now gone through the Debian server part, and it's ready for a review.
Comment #14
ressaI 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.
Comment #15
berdirAdded 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.
Comment #16
ressaThanks @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.phpfile, 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.
Comment #17
ressaI 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.
Comment #18
berdirDid another review, all I have time for now, I'll probably do a last pass myself if you can address the feedback
Comment #19
ressaGreat feedback, thanks! I have updated the MR, and I think the README looks pretty good now.
Comment #20
berdirI 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.
Comment #22
berdirComment #25
ressaLooks great, thanks @berdir.