Skip to content

Instantly share code, notes, and snippets.

@arielallon
Last active February 11, 2016 21:19
Show Gist options
  • Save arielallon/8841e499202f5eb48689 to your computer and use it in GitHub Desktop.
Save arielallon/8841e499202f5eb48689 to your computer and use it in GitHub Desktop.
<?php
function wasteMemory($redis, $runs, $multi=false, $echoEvery=10000) {
if ($multi) {
$redis->multi();
}
for ($i=0; $i <= $runs; $i++) {
$redis->set('key'.$i, 'value'.$i);
if ($i % $echoEvery === 0) {
echo memory_get_peak_usage();
echo "\n";
}
}
if ($multi) {
$redis->exec();
}
}
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
wasteMemory($redis, 100000);
/** shell output
241608
241608
241608
241608
241608
241608
241608
241608
241608
241608
241608
*/
wasteMemory($redis, 100000, true);
/** shell output
245840
245840
245840
245840
245840
245840
245840
245840
245840
245840
245840
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment