Skip to content

Instantly share code, notes, and snippets.

@naveed125
Last active March 11, 2020 04:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naveed125/d33a7e043824540cead3548a31a8c9aa to your computer and use it in GitHub Desktop.
Save naveed125/d33a7e043824540cead3548a31a8c9aa to your computer and use it in GitHub Desktop.
A simple get and set example of using redis key value store
<?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