-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark-redis-test.php
50 lines (38 loc) · 1.29 KB
/
benchmark-redis-test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
declare(strict_types=1);
const KEYS_COUNT = 1000000;
const PAYLOAD = '{"type":"Product","id":493842,"attributes":{"pickup_point":{"available":true},"courier":{"available":true}}}';
//Connecting to Redis server on localhost
$redis = new Redis();
$redis->connect('redis', 6379);
echo "Connection to Redis is successfully" . PHP_EOL . PHP_EOL;
echo "Redis' keys is generating..." . PHP_EOL;
$pipeline = $redis->pipeline();
for ($i = 1; $i <= KEYS_COUNT; $i++) {
$key = 'test:' . $i;
$pipeline->set($key, PAYLOAD);
}
$pipeline->exec();
echo "Generation is successfully" . PHP_EOL . PHP_EOL;
$keys = [];
for ($i = 1; $i <= 60; $i++) {
$keys[] = sprintf('test:%d', random_int(1, KEYS_COUNT));
}
$milliseconds1 = microtime(true);
foreach ($keys as $key) {
$redis->get($key);
}
$time = (microtime(true) - $milliseconds1) * 1000;
echo "Time get x60: $time ms" . PHP_EOL . PHP_EOL;
$milliseconds1 = microtime(true);
$pipeline = $redis->pipeline();
foreach ($keys as $key) {
$pipeline->get($key);
}
$res = $pipeline->exec();
$time = (microtime(true) - $milliseconds1) * 1000;
echo "Time get x60 with pipeline : $time ms" . PHP_EOL . PHP_EOL;
$milliseconds1 = microtime(true);
$redis->mGet($keys);
$time = (microtime(true) - $milliseconds1) * 1000;
echo "Time mget x1: $time ms" . PHP_EOL . PHP_EOL;