Beispiel #1
1
 /**
  * 保存记录至redis
  * @access private
  * @param  string $value 保存值
  * @return boolean       成功返回true,失败返回false
  */
 private function save_item_in_redis($value = '')
 {
     require './include/Predis/Autoloader.php';
     Predis\Autoloader::register();
     try {
         $r = new Predis\Client();
         $r->connect('127.0.0.1', 6379);
         $my_log_len = $r->llen($this->config->item('encryption_key'));
         if ($my_log_len < 21) {
             $r->rpush($this->config->item('encryption_key'), $value);
         } else {
             $r->lpop($this->config->item('encryption_key'));
             $r->rpush($this->config->item('encryption_key'), $value);
         }
         return TRUE;
     } catch (Exception $e) {
         echo $e->getMessage();
         return FALSE;
     }
 }
Beispiel #2
0
 /**
  * 获取动态出入金、转账记录
  * @return mixed 成功返回对应记录,失败返回false
  */
 private function get_my_log()
 {
     require_once './include/Predis/Autoloader.php';
     Predis\Autoloader::register();
     try {
         $r = new Predis\Client();
         $r->connect('127.0.0.1', 6379);
         $my_log_len = $r->llen($this->config->item('encryption_key'));
         return $my_log_len == 0 ? false : $r->lrange($this->config->item('encryption_key'), 0, $my_log_len - 1);
     } catch (Exception $e) {
         return false;
     }
 }
Beispiel #3
0
            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
    $data = array('email' => $Request->email, 'firstName' => $Request->firstName, 'lastName' => $Request->lastName, 'position' => $Request->position, 'intersted' => $Request->intersted);
Beispiel #4
0
<?php

require_once __DIR__ . '/vendor/autoload.php';
if (!file_exists('config/podisum.yml')) {
    die("No config file");
}
$config = \Symfony\Component\Yaml\Yaml::parse('config/podisum.yml');
if (class_exists('MongoClient')) {
    $mongo = new \MongoClient($config['mongo']);
} else {
    $mongo = new \Mongo($config['mongo']);
}
$podisum = new Podisum($mongo, $config);
$podisum->ensureIndexes();
$redis = new Predis\Client($config['redis']);
$len = $redis->llen($config['redis_key']);
echo "Found {$len} entries waiting on list...\n";
$processed = 0;
$sleep = $podisum->getConfig('default_sleep', 1);
while (1) {
    $value = $redis->rpop($config['redis_key']);
    if (null === $value) {
        echo "no more data, sleeping...\n";
        sleep($sleep);
        continue;
    }
    $data = json_decode($value, true);
    if (!$data) {
        echo "Invalid json string " . $value;
        continue;
    }
Beispiel #5
0
<?php

header('Content-Type: text/html; charset=utf-8', true);
error_reporting(E_ALL);
require "predis/autoload.php";
Predis\Autoloader::register();
$redis = new Predis\Client();
/*  If uses external server

	$client = new Predis\Client([
	    'scheme' => 'tcp',
	    'host'   => '127.0.0.1',
	    'port'   => 6379,
	]);

*/
//29392
// id объекта недвижимости. Он есть ключом для всего хэша. По запросу именно id будут выдаваться все данные объекта из базы.
$prop_id = rand(00, 99999);
echo 'GENERATED PROPERTY ID: ', $prop_id, '<br>';
// создаем хэш (объект недвижимости) с генерированным id в качестве ключа.
$redis->hmset($prop_id, array("type" => "Новобудови", "name" => "Двокімнатна квартира", "location" => "м.Чернігів, просп. Миру", "description" => "Продається двокімнатна квартира в центрі Чернігова", "sdelka" => "Продаж", "rooms" => 2, "floor" => 5, "floors_total" => 9, "area" => 32, "price" => "22000\$"));
// и запишем этот ключ в отдельную базу, где будем хранить все id всех объявлений.
$list = 'Properties';
$redis->rpush($list, $prop_id);
echo '<br>Properties in list: ', $redis->llen($list), '<br><br>';
echo '<br>There are: <pre>', print_r($redis->lrange($list, 0, -1)), '</pre><br><br>';
//echo '<br>', var_dump($res), '<br><br>';
$res1 = $redis->hgetall($prop_id);
echo var_dump($res1);