Last active
March 11, 2020 04:32
-
-
Save naveed125/d33a7e043824540cead3548a31a8c9aa to your computer and use it in GitHub Desktop.
A simple get and set example of using redis key value store
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
<?php | |
// use Predis https://github.com/nrk/predis | |
$client = new Predis\Client(); | |
// connect to the local redis server | |
$client->connect(); | |
// set a value in redis with expiration | |
$client->setex('a_key', 10, 'a_value'); | |
// get that value back | |
$value = $client->get('a_key'); | |
echo ("{$value}\n"); | |
// sleep 10 seconds | |
sleep(10); | |
// get that value again | |
$value = $client->get('a_key'); | |
echo ("{$value}\n"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment