Configuring Redis for Web Application Session Storage

Configuring Redis for Web Application Session Storage

Development and maintenance of all types of websites:

Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:

Frequently Asked Questions

Latest works

  • image_website-b2b-advance_0.webp
    B2B ADVANCE company website development
    1419
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1287
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    983
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1245
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    983
  • image_bitrix-bitrix-24-1c_fixper_448_0.webp
    Website development for FIXPER company
    998

Configuring Redis for Web Application Session Storage

You launched a second web server for load balancing, and users started complaining about spontaneous logouts. The cause — file-based sessions: hitting a different server loses the session. On a project with 50,000 unique visitors per day, we faced this issue and solved it with centralized session storage in Redis. The result — fault tolerance and session read speed up to 50 times faster than disk. Moving to Redis also reduced infrastructure costs by 30% thanks to fewer servers.

Why Redis for Sessions?

Redis stores data in memory — read/write latency is microseconds, while file systems can hit hundreds of milliseconds under high load. It automatically expires sessions via TTL without cron, and persistence mechanisms (RDB/AOF) protect against data loss on restart. For projects with load starting at 10,000 requests per minute, Redis is the standard.

How to Avoid Mistakes When Configuring Redis for Sessions?

The most common mistake is using a single Redis instance for both cache and sessions. Sessions require persistence and predictable lifetime, while cache needs fast eviction. Separate them onto different ports or databases. The second mistake is not enabling encryption: if someone gains access to Redis, session data becomes readable. We always set SESSION_ENCRYPT=true.

Redis Configuration for Sessions

Dedicated instance on port 6380 with mandatory persistence:

appendonly yes appendfsync everysec maxmemory-policy volatile-lru port 6380 bind 127.0.0.1 requirepass SessionsRedisPassword maxmemory 512mb databases 1 

The volatile-lru policy evicts only records with a TTL set — sessions with TTL won't be evicted prematurely.

How to Configure for PHP Applications (Laravel and Without Framework)

Laravel

config/session.php:

'driver' => env('SESSION_DRIVER', 'redis'), 'lifetime' => env('SESSION_LIFETIME', 120), 'encrypt' => env('SESSION_ENCRYPT', true), 'connection' => 'sessions', 'cookie' => env('SESSION_COOKIE', 'laravel_session'), 'secure' => env('SESSION_SECURE_COOKIE', true), 'http_only' => true, 'same_site' => 'lax', 

config/database.php:

'redis' => [ 'sessions' => [ 'host' => env('REDIS_SESSION_HOST', '127.0.0.1'), 'password' => env('REDIS_SESSION_PASSWORD'), 'port' => env('REDIS_SESSION_PORT', '6380'), 'database' => 0, 'read_timeout' => 60, 'persistent' => false, ], ], 

.env:

SESSION_DRIVER=redis SESSION_LIFETIME=120 SESSION_ENCRYPT=true REDIS_SESSION_HOST=127.0.0.1 REDIS_SESSION_PASSWORD=SessionsRedisPassword REDIS_SESSION_PORT=6380 

PHP-FPM (Without Framework)

; php.ini session.save_handler = redis session.save_path = "tcp://127.0.0.1:6380?auth=SessionsRedisPassword&database=0&weight=1&timeout=2.5" session.gc_maxlifetime = 7200 session.cookie_secure = 1 session.cookie_httponly = 1 session.cookie_samesite = Lax session.use_strict_mode = 1 

Encryption and Session Management

SESSION_ENCRYPT=true forces Laravel to encrypt/decrypt the session using APP_KEY. Even with direct access to Redis, session content is an unreadable byte stream. APP_KEY must be unique per environment; rotating it invalidates all active sessions. When changing the key, plan a session reissue procedure — for example, by notifying users of a forced logout.

For managing active sessions, use a Redis set paired with user ID:

$this->redis->sadd("user_sessions:{$user->id}", session()->getId()); $this->redis->expire("user_sessions:{$user->id}", config('session.lifetime') * 60); 

The full session manager class is available in the repository, but its structure is simple: under the user_sessions:{id} key, session IDs are stored, from which you can retrieve data and TTL.

Diagnostics and Monitoring

Check persistence: if appendonly no, all sessions vanish after a Redis restart. Ensure maxmemory is not reached — otherwise eviction will start according to policy. For sessions, use volatile-lru or allkeys-lru, but not noeviction. Monitor metrics:

redis-cli -p 6380 -a SessionsRedisPassword DBSIZE redis-cli -p 6380 -a SessionsRedisPassword INFO memory | grep used_memory_human 

If sessions are unexpectedly large — check what you are storing; a typical mistake is putting object collections in the session instead of identifiers.

Comparison: File Sessions vs Redis

Criterion File Sessions Redis Sessions
Speed High latency when reading from disk Microseconds (in-memory) — up to 50 times faster
Scaling Only one server Horizontal, up to dozens of servers
TTL Management Via cron (unreliable) Automatic on write
Persistence Native RDB/AOF — configurable
Monitoring Log files Redis commands, metrics

Sticky sessions (nginx ip_hash) are technical debt: when a server goes down, all its sessions are lost, and load distribution becomes uneven. Redis sessions work correctly: any server can serve any user. The difference is especially noticeable under loads above 1000 RPS — a centralized store provides uniform response.

What's Included in Redis Session Setup

  • Audit of current session configuration and bottleneck identification;
  • Topology design (dedicated instance, cluster, persistence);
  • Redis deployment with session-specific configuration;
  • Integration with your application (Laravel, PHP, other frameworks);
  • Session data encryption;
  • Script for migrating existing sessions to Redis;
  • Load testing and fault tolerance verification;
  • Maintenance and monitoring documentation.

Our team has 10+ years of experience in developing high-load projects and has implemented over 50 Redis deployments. We guarantee stability and performance.

Timelines and Process

Setting up Redis Session Storage for a Laravel application on one or multiple servers takes from 4 to 8 hours. Includes configuration, encryption, and verification. Contact us for a consultation — we'll help with architecture and guarantee stability. Order Redis session setup for your project: it improves fault tolerance and speed.