Redis
The Redis service is used to install and run Redis, a fast key/value store often used to improve the performance of websites for (fast) internal caching.
The installation is configured as a temporary cache, no data is stored persistently to disk.
Installation / Configuration
You can fully configure Redis through the Custom JSON Server Level Configuration.
Enable Redis
To install Redis, set redis::ensure
to present
.
Memory Ratio
By default, a redis::memory_ratio
of 4 is used, which means Redis will take up to 1/4 of the servers total memory.
Memory Limit
redis::maxmemory_policy
is configured to noeviction
by default.
Read more about eviction policies at Redis.
protected
redis::protected
is configured to true
by default.
If redis::protected
is configured to false
, redis::password
must be set (if no password is defined, Redis will fail to start!).
Read more about protected-mode at Redis.
password
redis::password
is not set by default.
Your password must be at least 16 characters long, contain lower and uppercase letters, numbers and symbols.
Read more about authentication at Redis.
Full example
{
"redis::ensure": "present",
"redis::memory_ratio": "4",
"redis::maxmemory_policy": "noeviction",
"redis::protected": false,
"redis::password": "sbVGHJKVHvgh78g1$?"
}
Usage
By default, Redis listens on localhost, port 6379 (127.0.0.1:6379
).
PHP
Depending on your applications requirements, you might need the phpredis extension to use Redis from PHP. The extension is precompiled and installed, but not loaded by default.
To load phpredis in your environment, specify the extension in ~/cnf/php.ini
:
extension = redis.so
Don’t forget to activate the new configuration by running php-restart
.
Debugging
For debugging purposes, use redis-cli
to connect to the Redis server:
$ redis-cli set key1 test
OK
$ redis-cli --scan
key1
$ redis-cli get key1
"test"
Tip
For details, see the redis-cli documentation.