redisconnection.php (736B)
1 <?php 2 $redis = new Redis(); 3 $redis->connect('127.0.0.1', 6379); 4 5 //$redis->flushAll(); //Dit cleart de hele database :) 6 7 $newValue = 28; 8 9 if(!$redis->exists('values')) { 10 $redis->lpush('values', $newValue); 11 $redis->lpush('average', $newValue); 12 } 13 else { 14 if($redis->llen('values') < 30) { 15 $avg = ($redis->rpop('average') * $redis->llen('values') + $newValue) / ($redis->llen('values') + 1); 16 $redis->lpush('average', $avg); 17 $redis->lpush('values', $newValue); 18 } 19 else { 20 $avg = ($redis->rpop('average') * 30 - $redis->rpop('values') + $newValue) / 30; 21 $redis->lpush('average', $avg); 22 $redis->lpush('values', $newValue); 23 } 24 } 25 26 echo $redis->lIndex('average', 0); 27 28 29 30 31 32 33 34 35 36