if (!in_array($ball, $validBalls)) { return 'Invalid ballId'; } $min = 0; $max = 255; if ($red < $min || $red > $max) { return 'Invalid red value...should be between 0 and 255'; } if ($green < $min || $green > $max) { return 'Invalid green value...should be between 0 and 255'; } if ($blue < $min || $blue > $max) { return 'Invalid blue value...should be between 0 and 255'; } $data = array('action' => 'color', 'red' => $red, 'green' => $green, 'blue' => $blue, 'ball' => $ball); $redis->lpush('spheroCommands', json_encode($data)); return 'Your command has been sent. You command is currently the ' . $redis->llen('spheroCommands') . ' command. Watch they ball it will excute shortly.'; } catch (Exception $E) { return $E->getMessage(); } }); /** * register route * * @param {Request} data used to register account * @return {String} */ $app->post('/register', function (Request $Request) { // create hash $hash = md5($Request->email . $Request->firstName . $Request->lastName . $Request->position); // gather data
/** * Utility method to to an LPUSH of some unordered values on a key. * * @param Predis\Client $redis Redis client instance. * @param string $key Target key * @return array */ protected function lpushUnorderedList(Predis\Client $redis, $key) { $list = array(2, 100, 3, 1, 30, 10); $redis->lpush($key, $list); return $list; }
<?php require 'vendor/autoload.php'; Predis\Autoloader::register(); $client = new Predis\Client(array('host' => '127.0.0.1', 'port' => 6379), array('prefix' => 'php:')); $client->lpush('blocking:queue', 'first'); $client->lpush('blocking:queue', 'second'); $client->blpop(['blocking:queue'], 0); # array('php:blocking:queue', 'second') $client->brpop(['blocking:queue'], 0); # array('php:blocking:queue', 'first') $client->rpush('blocking:source', 'message'); $client->brpoplpush('blocking:source', 'blocking:destination', 0); # 'message'
while ($body = $redis->brpoplpush('dflydev-git-subsplit:incoming', 'dflydev-git-subsplit:processing', 0)) { $data = json_decode($body, true); $name = null; $project = null; $data['dflydev_git_subsplit'] = array('processed_at' => time()); foreach ($config['projects'] as $testName => $testProject) { if ($testProject['url'] === $data['repository']['url']) { $name = $testName; $project = $testProject; break; } } if (null === $name) { print sprintf('Skipping request for URL %s (not configured)', $data['repository']['url']) . "\n"; $redis->lrem('dflydev-git-subsplit:processing', 1, $body); $redis->lpush('dflydev-git-subspilt:failures', json_encode($data)); continue; } $data['dflydev_git_subsplit']['name'] = $name; $data['dflydev_git_subsplit']['project'] = $project; $ref = $data['ref']; $publishCommand = array('git subsplit publish', escapeshellarg(implode(' ', $project['splits']))); if (preg_match('/refs\\/tags\\/(.+)$/', $ref, $matches)) { $publishCommand[] = escapeshellarg('--rebuild-tags'); $publishCommand[] = escapeshellarg('--no-heads'); $publishCommand[] = escapeshellarg(sprintf('--tags=%s', $matches[1])); } elseif (preg_match('/refs\\/heads\\/(.+)$/', $ref, $matches)) { $publishCommand[] = escapeshellarg('--no-tags'); $publishCommand[] = escapeshellarg(sprintf('--heads=%s', $matches[1])); } else { print sprintf('Skipping request for URL %s (unexpected reference detected: %s)', $data['repository']['url'], $ref) . "\n";
<?php require __DIR__ . '/../vendor/autoload.php'; $configFilename = file_exists(__DIR__ . '/../config.json') ? __DIR__ . '/../config.json' : __DIR__ . '/../config.json.dist'; $config = json_decode(file_get_contents($configFilename), true); $allowedIps = isset($config['allowed-ips']) ? $config['allowed-ips'] : array('207.97.227.253', '50.57.128.197', '108.171.174.178'); if (!in_array($_SERVER['REMOTE_ADDR'], $allowedIps)) { header('HTTP/1.1 403 Forbidden'); echo sprintf("Host %s is not allowed to connect.\n", $_SERVER['REMOTE_ADDR']); exit; } $body = $_POST['payload']; $redis = new Predis\Client(); $redis->lpush('dflydev-git-subsplit:incoming', $body); echo "Thanks.\n";
function redisLog($title, $data, $key = 'express-log') { $log = ['time' => timeFormat(time()), 'title' => $title, 'data' => $data]; $redis = new Predis\Client(['scheme' => 'tcp', 'host' => 'redis', 'port' => 6379]); $redis->lpush($key, json_encode($log)); }