// Check entry value. echo ">>> Value for 'k1': " . $redis->get('k1') . "\n"; // Change entry's value. if ($redis->set('k1', 'new_value')) { echo ">>> Successfully put entry in cache. \n"; } // Check entry value. echo ">>> Value for 'k1': " . $redis->get('k1') . "\n"; // Put entry to cache. if ($redis->set('k2', '2')) { echo ">>> Successfully put entry in cache. \n"; } // Check entry value. echo ">>> Value for 'k2': " . $redis->get('k2') . "\n"; // Get two entries. $val = $redis->mget('k1', 'k2'); echo ">>> Value for 'k1' and 'k2': " . var_dump($val) . "\n"; // Delete on entry. if ($redis->del('k1')) { echo ">>> Successfully deleted 'k1'. \n"; } // Db size. echo ">>> Db size: " . $redis->dbsize() . "\n"; // Increment. echo ">>> Incremented: " . $redis->incr("inc_k") . "\n"; // Increment by 5. echo ">>> Incremented: " . $redis->incrby("inc_k", 5) . "\n"; } catch (Exception $e) { echo ">>> Couldn't connected to Redis."; echo $e->getMessage(); }
<?php /* * ===================================== * Website: http://netkiller.github.com * Author: neo <*****@*****.**> * Email: netkiller@msn.com * ===================================== */ require 'SharedConfigurations.php'; $single_server = array('host' => '127.0.0.1', 'port' => 6379, 'database' => 0); $multiple_servers = array(array('host' => '127.0.0.1', 'port' => 6379, 'database' => 15, 'alias' => 'first'), array('host' => '127.0.0.1', 'port' => 6380, 'database' => 15, 'alias' => 'second')); $client = new Predis\Client($single_server, array('prefix' => 'fw:')); $key = $_SERVER['REMOTE_ADDR']; if (!$client->exists($key)) { $client->setex($key, 20, 1); } else { $client->incrby($key, 1); } $counter = $client->get($key); if ($counter > 10) { echo 'Deny'; } print_r($client->get($key)); //var_dump($client->keys('*'));