PHP code example of jeankassio / php-redis-session-manager

1. Go to this page and download the library: Download jeankassio/php-redis-session-manager library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jeankassio / php-redis-session-manager example snippets




use JeanKassio\RedisSessionManager;

$redisSessionManager = new RedisSessionManager('127.0.0.1', 6379, 'Password'); // Password is optional

$redisSessionManager->start(); // Starts the session and sets Redis as handler

if (!$redisSessionManager->checkRedis()) {
    // Handle Redis connection failure
}

// Set session values
$_SESSION['anything'] = 'anything';

// Get session values
$anything = $_SESSION['anything'];




use JeanKassio\RedisSessionManager;

$redisSessionManager = new RedisSessionManager('127.0.0.1', 6379, 'Password'); // Password is optional

// Get session ID from your WebSocket logic
$sessionId = 'your-session-id';
$redisSessionManager->setSessionId($sessionId);

// Get full session as array
$session = $redisSessionManager->getSession();

// Set session data
$newSession = [
    'anything' => 'anything',
    'data' => $data,
    'username' => 'jeankassio'
];

$success = $redisSessionManager->setSession($newSession);

// Delete user session completely
$redisSessionManager->delSession();

bash
cd /vendor/jeankassio/php-redis-session-manager
bash
PHPUnit 10.5.47 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.22
Configuration: /www/wwwroot/----/session/vendor/jeankassio/php-redis-session-manager/phpunit.xml

.....                                                               5 / 5 (100%)

Time: 00:00.038, Memory: 24.94 MB

OK, but there were issues!
Tests: 5, Assertions: 8, PHPUnit Deprecations: 1.