Implement Redis extension

PHP implementation of Redis
Esse commit está contido em:
Sara Golemon
2013-06-25 10:50:07 -07:00
commit 2811e9da94
25 arquivos alterados com 1903 adições e 0 exclusões
+3
Ver Arquivo
@@ -44,6 +44,8 @@ hphp/system/php/filter/filter_input_array.php
hphp/system/php/sessions/SessionHandlerInterface.php
hphp/system/php/sessions/session_set_save_handler.php
hphp/system/php/redis/RedisException.php
# If you have no inheritance relationship, go here in alphabetical order
hphp/system/php/DebuggerCommand.php
hphp/system/php/XhprofFrame.php
@@ -57,6 +59,7 @@ hphp/system/php/file_system/Directory.php
hphp/system/php/json/JsonSerializable.php
hphp/system/php/lang/ErrorException.php
hphp/system/php/pdo/PDOException.php
hphp/system/php/redis/Redis.php
hphp/system/php/reflection/reflection.php
hphp/system/php/sessions/session_register_shutdown.php
hphp/system/php/soap/SoapFault.php
Diferenças do arquivo suprimidas por serem muito extensas Carregar Diff
+3
Ver Arquivo
@@ -0,0 +1,3 @@
<?php
class RedisException extends RuntimeException { }
+20
Ver Arquivo
@@ -0,0 +1,20 @@
<?php
include (__DIR__ . '/redis.inc');
$r = NewRedisTestInstance();
$r->setOption(Redis::OPT_PREFIX, GetTestKeyName(__FILE__) . ':');
$r->set("A", "\x01\x02\x03\x04");
$r->set("B", "\x01\x01\x01\x01");
foreach (['AND', 'OR', 'XOR'] as $op) {
$r->bitop($op, 'C', 'A', 'B');
var_dump(bin2hex($r->get('C')));
}
$r->bitop('NOT', 'C', 'A');
var_Dump(bin2hex($r->get('C')));
$r->delete('A', 'B', 'C');
+4
Ver Arquivo
@@ -0,0 +1,4 @@
string(8) "01000100"
string(8) "01030305"
string(8) "00030205"
string(8) "fefdfcfb"
+5
Ver Arquivo
@@ -0,0 +1,5 @@
<?php
if (!getenv('REDIS_TEST_HOST')) {
echo 'skip';
}
+14
Ver Arquivo
@@ -0,0 +1,14 @@
<?php
include (__DIR__ . '/redis.inc');
$r = NewRedisTestInstance();
var_dump($r->echo("This is a test"));
$r->multi(Redis::MULTI);
var_dump($r->echo("This is a multi test") instanceof Redis);
var_dump($r->exec());
$r->multi(Redis::PIPELINE);
var_dump($r->echo("This is a pipeline test") instanceof Redis);
var_dump($r->exec());
+11
Ver Arquivo
@@ -0,0 +1,11 @@
string(14) "This is a test"
bool(true)
array(1) {
[0]=>
string(20) "This is a multi test"
}
bool(true)
array(1) {
[0]=>
string(23) "This is a pipeline test"
}
+19
Ver Arquivo
@@ -0,0 +1,19 @@
<?php
include (__DIR__ . '/redis.inc');
$r = NewRedisTestInstance();
$r->setOption(Redis::OPT_PREFIX, GetTestKeyName(__FILE__) . ':');
$r->delete('A');
$r->hSet('A', 'foo', 'bar');
var_dump($r->hLen('A'));
$r->hSet('A', 'baz', 'boom');
var_dump($r->hLen('A'));
var_dump($r->hKeys('A'));
var_dump($r->hVals('A'));
var_dump($r->hGetAll('A'));
var_dump($r->hGet('A', 'foo'));
var_dump($r->hGet('A', 'baz'));
$r->delete('A');
+22
Ver Arquivo
@@ -0,0 +1,22 @@
int(1)
int(2)
array(2) {
[0]=>
string(3) "foo"
[1]=>
string(3) "baz"
}
array(2) {
[0]=>
string(3) "bar"
[1]=>
string(4) "boom"
}
array(2) {
["foo"]=>
string(3) "bar"
["baz"]=>
string(4) "boom"
}
string(3) "bar"
string(4) "boom"
+10
Ver Arquivo
@@ -0,0 +1,10 @@
<?php
require(__DIR__ . '/redis.inc');
$r = NewRedisTestInstance(true);
$info = $r->info();
var_dump(is_array($info));
var_dump(count($info) > 35);
var_dump($info['tcp_port'] == REDIS_PORT);
$r->client('setname', 'hhvm-redis-client');
var_dump($r->client('getname'));
+6
Ver Arquivo
@@ -0,0 +1,6 @@
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
string(17) "hhvm-redis-client"
+20
Ver Arquivo
@@ -0,0 +1,20 @@
<?php
include (__DIR__ . '/redis.inc');
$r = NewRedisTestInstance();
$r->setOption(Redis::OPT_PREFIX, GetTestKeyName(__FILE__) . ':');
$r->delete('A');
$r->lpush('A', "abc", "easy as 123", "apple", "pear");
var_dump($r->lSize('A'));
var_dump($r->lRange('A', 1, 3));
var_dump($r->lpop('A'));
var_dump($r->rpop('A'));
var_dump($r->lSize('A'));
var_dump($r->rpoplpush('A', 'B'));
var_dump($r->lget('A', 0));
var_dump($r->lget('B', 0));
$r->delete('A', 'B');
+15
Ver Arquivo
@@ -0,0 +1,15 @@
int(4)
array(3) {
[0]=>
string(5) "apple"
[1]=>
string(11) "easy as 123"
[2]=>
string(3) "abc"
}
string(4) "pear"
string(3) "abc"
int(2)
string(11) "easy as 123"
string(5) "apple"
string(11) "easy as 123"
+15
Ver Arquivo
@@ -0,0 +1,15 @@
<?php
include (__DIR__ . '/redis.inc');
$r = NewRedisTestInstance();
$r->setOption(Redis::OPT_PREFIX, GetTestKeyName(__FILE__) . ':');
$r->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
foreach ([null, true, false, 123, 456.0,
"A string of words", [1,2,3]] as $val) {
$r->set('A', $val);
var_dump($r->get('A'));
}
$r->delete('A');
@@ -0,0 +1,14 @@
NULL
bool(true)
bool(false)
int(123)
float(456)
string(17) "A string of words"
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
+12
Ver Arquivo
@@ -0,0 +1,12 @@
<?php
include (__DIR__ . '/redis.inc');
$r = NewRedisTestInstance();
$key = GetTestKeyName(__FILE__);
var_dump($r->setOption(Redis::OPT_PREFIX, "{$key}:"));
var_dump($r->set("foo", "bar{$key}baz"));
var_dump($r->setOption(Redis::OPT_PREFIX, ""));
var_dump($r->get("{$key}:foo") == "bar{$key}baz");
var_dump($r->delete("{$key}:foo"));
+5
Ver Arquivo
@@ -0,0 +1,5 @@
bool(true)
bool(true)
bool(true)
bool(true)
int(1)
+27
Ver Arquivo
@@ -0,0 +1,27 @@
<?php
/**
* Test configuration
*/
define('REDIS_HOST', getenv('REDIS_TEST_HOST'));
define('REDIS_PORT', getenv('REDIS_TEST_PORT')
? (int)getenv('REDIS_TEST_PORT')
: Redis::DEFAULT_PORT);
define('REDIS_PASS', getenv('REDIS_TEST_PASS')
? getenv('REDIS_TEST_PASS')
: null);
function NewRedisTestInstance($status = false) {
$r = new Redis();
$conn = $r->connect(REDIS_HOST, REDIS_PORT);
if ($status) var_dump($conn);
$authok = REDIS_PASS ? $r->auth(REDIS_PASS) : true;
if ($status) var_dump($authok);
return $r;
}
function GetTestKeyName($test, $rand = false) {
$name = 'REDIS_TEST:' . preg_replace('/[^a-zA-Z0-9]/', '-', $test);
if ($rand) $name .= ':' . rand(0,1000000);
return $name;
}
+17
Ver Arquivo
@@ -0,0 +1,17 @@
<?php
include (__DIR__ . '/redis.inc');
$r = NewRedisTestInstance();
$r->setOption(Redis::OPT_PREFIX, GetTestKeyName(__FILE__) . ':');
$r->delete('colors','reds');
var_dump($r->sAdd('colors', 'red', 'orange', 'yellow',
'green', 'blue', 'violet'));
var_dump($r->sSize('colors'));
var_dump($r->sContains('colors', 'red'));
var_dump($r->sContains('colors', 'aqua'));
var_dump($r->sAdd('reds', 'red', 'pink', 'crimson'));
var_dump($r->sInterStore('red-colors', 'colors', 'reds'));
var_dump($r->sMembers('red-colors'));
+10
Ver Arquivo
@@ -0,0 +1,10 @@
int(6)
int(6)
bool(true)
bool(false)
int(3)
int(1)
array(1) {
[0]=>
string(3) "red"
}
@@ -0,0 +1,39 @@
<?php
include (__DIR__ . '/redis.inc');
$r = NewRedisTestInstance();
$key = GetTestKeyName(__FILE__);
$r->delete($key);
echo "Atomic\n";
var_dump($r->exists($key));
var_dump($r->set($key, "The quick brown fox jumped over the lazy dog."));
var_dump($r->exists($key));
var_dump($r->get($key));
var_dump($r->strlen($key));
var_dump($r->delete($key));
var_dump($r->exists($key));
echo "Multi\n";
var_dump($r->multi()
->exists($key)
->set($key, "The quick brown fox jumped over the lazy dog.")
->exists($key)
->get($key)
->strlen($key)
->delete($key)
->exists($key)
->exec());
echo "Pipeline\n";
var_dump($r->pipeline()
->exists($key)
->set($key, "The quick brown fox jumped over the lazy dog.")
->exists($key)
->get($key)
->strlen($key)
->delete($key)
->exists($key)
->exec());
@@ -0,0 +1,42 @@
Atomic
bool(false)
bool(true)
bool(true)
string(45) "The quick brown fox jumped over the lazy dog."
int(45)
int(1)
bool(false)
Multi
array(7) {
[0]=>
bool(false)
[1]=>
bool(true)
[2]=>
bool(true)
[3]=>
string(45) "The quick brown fox jumped over the lazy dog."
[4]=>
int(45)
[5]=>
int(1)
[6]=>
bool(false)
}
Pipeline
array(7) {
[0]=>
bool(false)
[1]=>
bool(true)
[2]=>
bool(true)
[3]=>
string(45) "The quick brown fox jumped over the lazy dog."
[4]=>
int(45)
[5]=>
int(1)
[6]=>
bool(false)
}
+12
Ver Arquivo
@@ -0,0 +1,12 @@
<?php
include (__DIR__ . '/redis.inc');
$r = NewRedisTestInstance();
$tm = $r->time();
var_dump(count($tm));
$tm = $tm[0] + ($tm[1] / 1000000);
$now = microtime(true);
$delta = abs($now - $tm);
// Server should be within five seconds of client
var_dump($delta < 5);
+2
Ver Arquivo
@@ -0,0 +1,2 @@
int(2)
bool(true)