mirror of
https://github.com/predis/predis.git
synced 2026-08-18 15:54:38 +00:00
... and here finally comes Predis!
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
require_once 'SharedConfigurations.php';
|
||||
|
||||
// when you have a whole set of consecutive commands to send to
|
||||
// a redis server, you can use a pipeline to improve performances.
|
||||
|
||||
$redis = new Predis\Client(REDIS_HOST, REDIS_PORT);
|
||||
$redis->select(REDIS_DB);
|
||||
|
||||
$replies = $redis->pipeline(function($pipe) {
|
||||
$pipe->ping();
|
||||
$pipe->flushdb();
|
||||
$pipe->incrby('counter', 10);
|
||||
$pipe->incrby('counter', 30);
|
||||
$pipe->exists('counter');
|
||||
$pipe->get('counter');
|
||||
$pipe->mget('does_not_exist', 'counter');
|
||||
});
|
||||
|
||||
print_r($replies);
|
||||
|
||||
/* OUTPUT:
|
||||
Array
|
||||
(
|
||||
[0] => 1
|
||||
[1] => 1
|
||||
[2] => 10
|
||||
[3] => 40
|
||||
[4] => 1
|
||||
[5] => 40
|
||||
[6] => Array
|
||||
(
|
||||
[0] =>
|
||||
[1] => 40
|
||||
)
|
||||
|
||||
)
|
||||
*/
|
||||
?>
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
require_once 'SharedConfigurations.php';
|
||||
|
||||
// redis can set keys and their relative values in one go
|
||||
// using MSET, then the same values can be retrieved with
|
||||
// a single command using MGET.
|
||||
|
||||
$mkv = array(
|
||||
'usr:0001' => 'First user',
|
||||
'usr:0002' => 'Second user',
|
||||
'usr:0003' => 'Third user'
|
||||
);
|
||||
|
||||
$redis = new Predis\Client(REDIS_HOST, REDIS_PORT);
|
||||
$redis->select(REDIS_DB);
|
||||
|
||||
$redis->mset($mkv);
|
||||
$retval = $redis->mget(array_keys($mkv));
|
||||
|
||||
print_r($retval);
|
||||
|
||||
/* OUTPUT:
|
||||
Array
|
||||
(
|
||||
[0] => First user
|
||||
[1] => Second user
|
||||
[2] => Third user
|
||||
)
|
||||
*/
|
||||
?>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
require_once '../lib/Predis.php';
|
||||
|
||||
const REDIS_HOST = '192.168.1.205';
|
||||
const REDIS_PORT = 6379;
|
||||
const REDIS_DB = 15;
|
||||
?>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
require_once 'SharedConfigurations.php';
|
||||
|
||||
// simple set and get scenario
|
||||
|
||||
$redis = new Predis\Client(REDIS_HOST, REDIS_PORT);
|
||||
$redis->select(REDIS_DB);
|
||||
|
||||
$redis->set('library', 'predis');
|
||||
$retval = $redis->get('library');
|
||||
|
||||
print_r($retval);
|
||||
|
||||
/* OUTPUT
|
||||
predis
|
||||
*/
|
||||
?>
|
||||
Reference in New Issue
Block a user