How Redis works on Servbase
- A Redis database is a key prefix. A database named
user0000_cacheowns every key that starts withuser0000_cache:. - A Redis user signs in with a username and password and can use only the keys of its own databases.
- Redis is reachable only from your apps at
127.0.0.1:6390. It is not exposed to the internet. - Redis runs separately from the Servbase platform, and every customer is isolated from every other customer.
Create a Redis database
1
Create a Redis user
Open Databases, select Create Database User, choose Redis, then enter a username and password.
2
Create the database
Select Create Database, choose the Redis user, and enter a name such as
cache. The final name, for example user0000_cache, is the key prefix.3
Add the variables to your app
Open your app, go to Settings, then Variables, and add:
Use it in your code
Every key must start with your prefix. The examples set the prefix once so the rest of your code does not need to.Laravel
Set these in your app’s variables, then use theredis cache, session or queue driver:
Example: cache an API response (Express)
Commands that are not available
To keep customers isolated, commands that could see or change data outside your prefix, or affect the whole server, are disabled. These includeKEYS, SCAN, RANDOMKEY, DBSIZE, INFO, SELECT, FLUSHDB, FLUSHALL, CONFIG, MONITOR, SORT, PUBSUB and FUNCTION.
- To remove a group of keys, keep their names in a set, or give them an expiry time.
- Laravel’s
php artisan cache:clearusesFLUSHDBand is not available. Use cache tags or expiry times instead. - Pub/Sub channel names must also start with your prefix.
- Libraries that call
INFOwhile connecting may need that check turned off (for exampleenableReadyCheck: falsein ioredis).
Change the password or delete
- Change password: in Database Users, select the key icon. Apps using the old password are disconnected, so update
REDIS_PASSWORDin your app variables. - Delete a database: removes every key with that prefix.
- Delete the user: removes the user and all keys of its databases.
