Skip to content

Instantly share code, notes, and snippets.

@kervinpierre
Last active February 7, 2017 21:31
Show Gist options
  • Save kervinpierre/92a7ecd126e29a317639637c67917aef to your computer and use it in GitHub Desktop.
Save kervinpierre/92a7ecd126e29a317639637c67917aef to your computer and use it in GitHub Desktop.
A simple PHP example for PRedis library
<?php
// Redis example by Kervin
// Each time the script runs it will check if a previous run left
// information for it
// This is general PHP and is useful for debugging
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// clone the library and use it
// git clone git://github.com/nrk/predis.git
require 'predis/autoload.php';
Predis\Autoloader::register();
try
{
// Create your redis object
$redis = new Predis\Client();
// This counter will be incremented and stored
// in Redis for all future scripts to use
$count = $redis->incr("kervin-counter");
// Get the past date from a previous run
$msg1 = $redis->get("kervin-message");
echo "Last #$count Run at $msg1";
// Save the last run date for the next run
$redis->set('kervin-message', date(DATE_RFC2822));
}
catch (Exception $ex)
{
die($ex->getMessage());
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment