Configuring Redis for 1C-Bitrix data caching

Our company is engaged in the development, support and maintenance of Bitrix and Bitrix24 solutions of any complexity. From simple one-page sites to complex online stores, CRM systems with 1C and telephony integration. The experience of developers is confirmed by certificates from the vendor.
Our competencies:
Development stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1175
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    811
  • image_bitrix-bitrix-24-1c_development_of_an_online_appointment_booking_widget_for_a_medical_center_594_0.webp
    Development based on Bitrix, Bitrix24, 1C for the company Development of an Online Appointment Booking Widget for a Medical Center
    564
  • image_bitrix-bitrix-24-1c_mirsanbel_458_0.webp
    Development based on 1C Enterprise for MIRSANBEL
    747
  • image_crm_dolbimby_434_0.webp
    Website development on CRM Bitrix24 for DOLBIMBY
    655
  • image_crm_technotorgcomplex_453_0.webp
    Development based on Bitrix24 for the company TECHNOTORGKOMPLEKS
    976

Configuring Redis for Data Caching in 1C-Bitrix

Bitrix's standard cache writes data to files in /bitrix/cache/. On a loaded site, this becomes thousands of small files, whose operations hit disk IOPS limits. Redis as an in-memory store provides microsecond access to cache and removes load from the file system.

Connecting Redis as Cache Backend

In /bitrix/.settings.php, add or modify the cache section:

'cache' => [
    'value' => [
        'type' => [
            'class_name' => '\\Bitrix\\Main\\Data\\CacheEngineRedis',
            'extension'  => 'redis',
        ],
        'sid'  => 'site1',  // unique prefix for data separation
    ],
],

Redis connection settings are configured in a separate file /bitrix/php_interface/redis.php or through configuration:

// /bitrix/php_interface/init.php
define('BX_CACHE_TYPE', 'redis');
define('BX_CACHE_SID', 'site1');

$GLOBALS['CACHE_REDIS'] = [
    'host'     => '127.0.0.1',
    'port'     => 6379,
    'database' => 2,  // separate database from sessions
    'timeout'  => 2,
];

Separating Cache and Sessions

Use different Redis databases (the database parameter):

  • Database 0 — reserved by default
  • Database 1 — sessions
  • Database 2 — Bitrix data cache
  • Database 3 — HTML page cache (if used)

This allows clearing cache independently from sessions: redis-cli -n 2 FLUSHDB clears only data cache.

Redis Configuration for Data Cache

# /etc/redis/redis.conf
bind 127.0.0.1
port 6379
maxmemory 1gb
maxmemory-policy allkeys-lru    # evict least recently used when memory full
activerehashing yes
tcp-keepalive 300

allkeys-lru is the right policy for cache: when memory fills up, rarely-used keys are evicted. For sessions, volatile-lru is better (only evicts keys with TTL).

Tagged Cache with Redis

Bitrix uses tagged cache for invalidating groups of related data. When an infoblock element changes, the iblock_id_N tag invalidates all cache related to that infoblock. Redis stores tags more efficiently than the file system — no issue with thousands of small files.

Verify that tagged cache works:

redis-cli -n 2 KEYS "BITRIX_CACHE_TAG_*" | head -20

If there are no keys — tagged cache isn't being used or data hasn't been cached yet.

Cache Monitoring

# Usage statistics
redis-cli -n 2 INFO stats | grep -E "keyspace_hits|keyspace_misses"

# Hit rate = hits / (hits + misses)
# Goal: > 90%

# Number of keys
redis-cli -n 2 DBSIZE

# Memory usage
redis-cli INFO memory | grep used_memory_human

Low hit rate (< 70%) means cache is being flushed too often or TTL is too small. Check frequency of tag invalidation: if infoblock data changes every 10 seconds, the entire infoblock cache is flushed every 10 seconds — caching is pointless.