Redis and Caching

3 min read Updated 1 year ago

Caching Services

Ploi Cloud supports both Redis and Valkey for in-memory caching and session storage.

Redis vs Valkey

  • Redis: In-memory data structure store
  • Valkey: High-performance key-value store with full Redis compatibility

Adding a Cache Service

  1. Navigate to your application's overview
  2. Find the "Cache" card
  3. Click "Create" to add your first cache service (or "Add cache" if you already have services)
  4. Select Redis or Valkey as the cache type
  5. Configure resources using the CPU slider
  6. Set storage size for data persistence (cannot be changed after creation)
  7. Optionally select a specific version or leave blank for latest

Laravel Configuration

For Laravel applications, the following environment variables are automatically injected:

Redis

  • REDIS_URL - Full connection URL with authentication
  • REDIS_HOST - Redis hostname
  • REDIS_PORT - Redis port
  • REDIS_PASSWORD - Redis password

Valkey

  • VALKEY_URL - Full connection URL with authentication
  • VALKEY_HOST - Valkey hostname
  • VALKEY_PORT - Valkey port
  • VALKEY_PASSWORD - Valkey password

With "Expose env variables as Redis" turned on, a Valkey service injects REDIS_URL, REDIS_HOST, REDIS_PORT and REDIS_PASSWORD instead. See below.

Using Valkey as Redis

Valkey speaks the Redis protocol, but Laravel and most Redis clients read REDIS_* variables. If your application only sees VALKEY_*, it connects without a password and the server answers with NOAUTH Authentication required.

The "Expose env variables as Redis" option fixes this. When it is on, the Valkey service injects its connection details under the REDIS_* names, so no remapping is needed.

  • Default: new Valkey services on Laravel and Statamic applications have it turned on, unless the application already has a Redis service. Other application types default to VALKEY_*. Existing services keep whatever they had.
  • In the panel: the checkbox is in the dialog for adding a cache service and in the service's edit dialog.
  • Through the API: send settings.expose_as_redis as true or false when you create or update the Valkey service.
  • Infrastructure as code: add expose_as_redis: true to the Valkey service's settings.

Changing the option takes effect on your next deployment. Only one set of variables is injected: with the option on, VALKEY_* is no longer set, so update anything in your application that reads those names.

If you prefer to keep VALKEY_*, you can map it yourself in an environment secret, for example REDIS_PASSWORD set to ${VALKEY_PASSWORD}, or point config/database.php at the VALKEY_* names.

Update your Laravel cache configuration to use these variables:

  CACHE_DRIVER=redis
  SESSION_DRIVER=redis

Resource Configuration

When creating a cache service, you can configure:

  • CPU: Adjustable via slider (from 0.25 to multiple cores)
  • Memory: Configurable based on your needs
  • Storage: Persistent volume for data (e.g., "8Gi", "10Gi")

Service Management

Manage your cache service through the application dashboard:

  • View service logs for troubleshooting
  • Restart the service when needed
  • Enable temporary debug access for direct connections
  • Monitor service status (active, stopped, failed)
  • Edit resources to scale up or down