forked from predis/predis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename examples and update some comments.
[ci skip]
- Loading branch information
Showing
16 changed files
with
112 additions
and
94 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Predis package. | ||
* | ||
* (c) Daniele Alessandri <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
require __DIR__.'/shared.php'; | ||
|
||
// This example demonstrates how to use Predis to save PHP sessions on Redis. | ||
// | ||
// The value of `session.gc_maxlifetime` in `php.ini` will be used by default as | ||
// the TTL for keys holding session data but this value can be overridden when | ||
// creating the session handler instance using the `gc_maxlifetime` option. | ||
// | ||
// NOTE: this class requires PHP >= 5.4 but can be used on PHP 5.3 if a polyfill | ||
// for SessionHandlerInterface is provided either by you or an external package | ||
// like `symfony/http-foundation`. | ||
// | ||
// See https://www.php.net/class.sessionhandlerinterface.php for more details. | ||
// | ||
|
||
if (!interface_exists('SessionHandlerInterface')) { | ||
die("ATTENTION: the session handler implemented by Predis requires PHP >= 5.4.0 ". | ||
"or a polyfill for SessionHandlerInterface provided by an external package.\n"); | ||
} | ||
|
||
// Instantiate a new client just like you would normally do. Using a prefix for | ||
// keys will effectively prefix all session keys with the specified string. | ||
$client = new Predis\Client($single_server, array('prefix' => 'sessions:')); | ||
|
||
// Set `gc_maxlifetime` to specify a time-to-live of 5 seconds for session keys. | ||
$handler = new Predis\Session\Handler($client, array('gc_maxlifetime' => 5)); | ||
|
||
// Register the session handler. | ||
$handler->register(); | ||
|
||
// We just set a fixed session ID only for the sake of our example. | ||
session_id('example_session_id'); | ||
|
||
session_start(); | ||
|
||
if (isset($_SESSION['foo'])) { | ||
echo "Session has `foo` set to {$_SESSION['foo']}", PHP_EOL; | ||
} else { | ||
$_SESSION['foo'] = $value = mt_rand(); | ||
echo "Empty session, `foo` has been set with $value", PHP_EOL; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters