<?php

require dirname(__FILE__) . '/redis.php';
define('NL', PHP_SAPI == 'cli' ? "\n" : '<br />');
$redis = new redis_cli('127.0.0.1', 6379);
//$redis -> cmd ( 'SELECT', 9 );
/////////////////////////////////////////////////////////////
$redis->cmd('SET', 'foo', 'bar')->set();
$foo = $redis->cmd('GET', 'foo')->get();
var_dump($foo);
echo NL . str_repeat('-', 20) . NL . NL;
/////////////////////////////////////////////////////////////
$redis->cmd('HSET', 'hash', 'foo', 'bar')->cmd('HSET', 'hash', 'abc', 'def')->cmd('HSET', 'hash', '123', '456')->set();
$vals = $redis->cmd('HGETALL', 'hash')->get();
var_dump($vals);
$total = $redis->cmd('HVALS', 'hash')->get_len();
var_dump($total);
echo NL . str_repeat('-', 20) . NL . NL;
/////////////////////////////////////////////////////////////
$redis->cmd('INCR', 'online_foo')->cmd('INCR', 'online_bar')->cmd('INCRBY', 'online_foo', 3)->set();
$total_online = $redis->cmd('KEYS', 'online*')->get_len();
var_dump($total_online);
$foo_online = $redis->cmd('GET', 'online_foo')->get();
var_dump($foo_online);
echo NL . str_repeat('-', 20) . NL . NL;
/////////////////////////////////////////////////////////////
$hash = 'GO-' . date('dHi');
$redis->cmd('SADD', $hash, 'Some data')->cmd('SADD', $hash, 'More data')->cmd('SADD', $hash, 'Even more data')->cmd('EXPIRE', $hash, 900)->set();
$expiration = $redis->cmd('TTL', $hash)->get();
var_dump($expiration);
$total = $redis->cmd('SCARD', $hash)->get();
Esempio n. 2
0
if ($avgTemp >= 28 && $lastAvgValue < 28) {
    $pushMessage = "AVG temp now OVER 28°C! (" . $avgTemp . ")";
    sendPushMessage($pushMessage, $apiUrl, $apiToken, $apiUser);
}
##########################################################
#         Check online status and temperature            #
##########################################################
# get temperatures again, this time only the target temperatures of valves
$temperatures = array();
foreach ($devices as $device) {
    if ($device["type"] == "valve") {
        $temperatures[] = $device["targetTemp"];
    }
}
# fetch all online status keys from redis
$onlineStatusKeys = $redis->cmd("KEYS", "online-*")->get();
$someoneHome = false;
if (is_array($onlineStatusKeys)) {
    foreach ($onlineStatusKeys as $key) {
        $value = $redis->cmd("GET", $key)->get();
        if ($value == "1") {
            # stop on the first positive match (no need to look further)
            $someoneHome = true;
            break;
        }
    }
}
# if nobody seems to be home, check valve temperatures and notify
if (!$someoneHome) {
    $tempOk = true;
    foreach ($temperatures as $temperature) {