Pasar al contenido principal
www.keopx.net

Navegación principal

  • Inicio
  • Talks
  • Freelance Drupal Bilbao
  • Acerca de Keopx
  • Contacto
Menú de cuenta de usuario
  • Iniciar sesión

Sobrescribir enlaces de ayuda a la navegación

  1. Inicio

Cómo instalar y configurar Redis en Drupal 8

By keopx, 18 Junio, 2017

Voy a explicar cómo instalar y configurar Redis en Drupal 8. 

Redis es una base de datos popular basado en key-value.

En el caso de Drupal se usa como sistema de cache para la parte (backend) de gestión de contenidos, donde el sistema de cachea "estático" de las paginas no es suficiente.

Con Redis notaremos rápidamente la fluidez y rapidez con la que se puede gestionar toda la parte que requiere de usuarios autenticados.

  1. Instalar Redis:
    sudo apt-get install redis-server

    También puedes ver Dockerfile

  2. Instalar soporte de Redis para PHP:
    sudo apt-get install php7.0-redis
    sudo a2enmod php7.0-redis

    También puedes ver Dockerfile

  3. Instalar el modulo redis de Drupal:
    composer require drupal/redis

    o

    drush dl redis
  4. Configurar redis para Drupal:

En el settings.php o mejor en el drush añadir lo siguiente:

<?php

/**
 * Set redis configuration.
 */
/** @see: https://docs.platform.sh/frameworks/drupal8/redis.html */
if (extension_loaded('redis')) {

  // Set Redis as the default backend for any cache bin not otherwise specified.
  // $settings['cache']['default'] = 'cache.backend.redis';
  $settings['redis.connection']['interface'] = 'PhpRedis'; // Can be "Predis".
  $settings['redis.connection']['host'] = 'redis';
  $settings['redis.connection']['port'] = '6379';
  // $settings['redis.connection']['password'] = "mypassword"; // If you are using passwords, otherwise, omit

  // Apply changes to the container configuration to better leverage Redis.
  // This includes using Redis for the lock and flood control systems, as well
  // as the cache tag checksum. Alternatively, copy the contents of that file
  // to your project-specific services.yml file, modify as appropriate, and
  // remove this line.
  $settings['container_yamls'][] = 'modules/contrib/redis/example.services.yml';

  // Allow the services to work before the Redis module itself is enabled.
  $settings['container_yamls'][] = 'modules/contrib/redis/redis.services.yml';

  // Manually add the classloader path, this is required for the container cache bin definition below
  // and allows to use it without the redis module being enabled.
  $class_loader->addPsr4('Drupal\\redis\\', 'modules/contrib/redis/src');

  // Use redis for container cache.
  // The container cache is used to load the container definition itself, and
  // thus any configuration stored in the container itself is not available
  // yet. These lines force the container cache to use Redis rather than the
  // default SQL cache.
  $settings['bootstrap_container_definition'] = [
    'parameters' => [],
    'services' => [
      'redis.factory' => [
        'class' => 'Drupal\redis\ClientFactory',
      ],
      'cache.backend.redis' => [
        'class' => 'Drupal\redis\Cache\CacheBackendFactory',
        'arguments' => ['@redis.factory', '@cache_tags_provider.container', '@serialization.phpserialize'],
      ],
      'cache.container' => [
        'class' => '\Drupal\redis\Cache\PhpRedis',
        'factory' => ['@cache.backend.redis', 'get'],
        'arguments' => ['container'],
      ],
      'cache_tags_provider.container' => [
        'class' => 'Drupal\redis\Cache\RedisCacheTagsChecksum',
        'arguments' => ['@redis.factory'],
      ],
      'serialization.phpserialize' => [
        'class' => 'Drupal\Component\Serialization\PhpSerialize',
      ],
    ],
  ];

  /** Optional prefix for cache entries */
  $settings['cache_prefix'] = 'any-text-you-want';

  /** @see: https://pantheon.io/docs/redis/ */
  // Always set the fast backend for bootstrap, discover and config, otherwise
  // this gets lost when redis is enabled.
  $settings['cache']['bins']['bootstrap'] = 'cache.backend.chainedfast';
  $settings['cache']['bins']['discovery'] = 'cache.backend.chainedfast';
  $settings['cache']['bins']['config'] = 'cache.backend.chainedfast';

  /** @see: https://github.com/md-systems/redis */
  // Use for all bins otherwise specified.
  $settings['cache']['default'] = 'cache.backend.redis';

  // Use this to only use it for specific cache bins.
  $settings['cache']['bins']['render'] = 'cache.backend.redis';

  // Use for all queues unless otherwise specified for a specific queue.
  $settings['queue_default'] = 'queue.redis';

  // Or if you want to use reliable queue implementation.
  $settings['queue_default'] = 'queue.redis_reliable';

  // Use this to only use Redis for a specific queue (aggregator_feeds in this case).
  $settings['queue_service_aggregator_feeds'] = 'queue.redis';

  // Or if you want to use reliable queue implementation.
  $settings['queue_service_aggregator_feeds'] = 'queue.redis_reliable';
}

Ver https://gist.github.com/keopx/7d5fe4d7a890c792c43bb79cf56718e0

Una ves hecho esto ir a la pagina de estado (/admin/reports/status) para comprobar que todo esta bien.

Drupal Redis Setup

NOTA: si veis que cualquier parametrización es mejor, por favor comentadlo. Gracias.

Referencias:

  • https://gist.github.com/keopx/7d5fe4d7a890c792c43bb79cf56718e0
  • https://docs.platform.sh/frameworks/drupal8/redis.html
  • https://pantheon.io/docs/redis/
  • https://github.com/md-systems/redis
  • https://github.com/keopx/docker-lamp

 

 

Categoria
Drupal 8.x
Redis
Drupal
Drupal Planeta
Tag
Drupal
Drupal 8.x
Redis
php

Comentarios

El contenido de este campo se mantiene privado y no se mostrará públicamente.
Acerca de formatos de texto

HTML Restringido

  • Etiquetas HTML permitidas: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Saltos automáticos de líneas y de párrafos.
  • Las direcciones de correos electrónicos y páginas web se convierten en enlaces automáticamente.

Forcontu Master in Drupal 9

DrupalAssoc member

DrupalCampSpain2022: Introducción al desarrollo de módulos en Drupal 9

Seville Drupal Developer Days Individual Sponsor - 2017

I am speaker DrupalCamp Alicante 2018

I am speaker DrupalCamp Madrid 2017

I am speaker DrupalCamp Valencia 2014

I am Rules Ruler

Sponsored by

Isarea

Soy Ruben Egiguren a.k.a. keopx, actualmente soy freelance experto en Drupal de Bilbao

  • Reinicializar su contraseña
RSS feed
Powered by www.keopx.net