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

*/
// Simplest demo how to use Redis
/*
$redis->set("hello_world", "Hi from php!");
$value = $redis->get("hello_world");
echo $value;
*/
// 123 - id of property
$redis->hmset("123", array("type" => "нерухомість поза містом", "name" => "Приватний будинок поза містом", "location" => "с. Ульянівка", "description" => "Приватний будинок поза містом. Приватизована земельна ділянка. Світло, вода, газ - присутні. Є місце для будівництва.", "sdelka" => "Продаж", "rooms" => 5, "floors" => 2, "area" => 90, "price" => "12000\$"));
$res = $redis->hgetall('123');
//echo var_dump($res);
?>
  <div class="container" style="margin-top: 15%;">
  <div class="comments-list">
	<div class="media">
	  <p class="price pull-right"><span class="label label-primary"><?php 
echo $res['sdelka'];
?>
</span></p>
	  <a class="media-left" href="#">
	    <img class="ob-img" src="../img/no-image.png">
	  </a>
	  <div class="media-body" style="padding-top: 5px;">
예제 #2
0
//Did the client stop the torrent?
//We dont care about other events
if (isset($_GET['event']) && $_GET['event'] === 'stopped') {
    $r->srem($info_hash, $peer_id);
    die(track(array()));
    //The RFC says its OK to return whatever we want when the client stops downloading,
    //however, some clients will complain about the tracker not working, hence we return
    //an empty bencoded peer list
}
//Update information of this peer and get all the other peers downloading the same file.
$map = $info_hash . ':' . $peer_id;
$r->sadd('torrents', $info_hash);
$r->sadd($info_hash, $peer_id);
$pid_list = $r->smembers($info_hash);
if (isset($ip4)) {
    $r->hmset($map, 'ip4', $ip4, 'port', $port, 'seed', $is_seed);
} else {
    $r->hmset($map, 'ip6', $ip6, 'port', $port, 'seed', $is_seed);
}
$r->expire($map, __INTERVAL + __CLIENT_TIMEOUT);
$peers = array();
$i = $s = $l = 0;
foreach ($pid_list as $pid) {
    if ($pid == $peer_id) {
        continue;
    }
    $temp = $r->hmget($info_hash . ':' . $pid, 'ip4', 'ip6', 'port', 'seed');
    if (!$temp[0] && !$temp[1]) {
        //Remove the peer infomation if it's expired
        $r->srem($info_hash, $pid);
    } else {
예제 #3
0
파일: hashes.php 프로젝트: cdandy/code-lib
<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 * Description of hashes
 *
 * @author changdi
 */
require "../shared.php";
$predis = new Predis\Client($single_server);
//some common 常见的
/*
var_dump($predis->hmset('hash-key',array('k1'=>'v1','k2'=>'v2','k3'=>'v3')));
var_dump($predis->hmget('hash-key',array ('k2','k3')));

var_dump($predis->hlen('hash-key'));
var_dump($predis->hdel('hash-key',array('k1','k3')));
*/
//some more advanced 更高级的
var_dump($predis->hmset('hash-key2', array('short' => 'hello', 'long' => 1000 * '1')));
var_dump($predis->hkeys('hash-key2'));
var_dump($predis->hexists('hash-key2', 'num'));
//var_dump($predis->hincrby('hash-key2','num'));
var_dump($predis->hexists('hash-key2', 'num'));
예제 #4
0
Predis\Autoloader::register();
$redis = new Predis\Client();
// Really simple way to set a key/value pair
$redis->set('foo', 'bar');
$value = $redis->get('foo');
echo $value . "\n";
// There's no UPDATE commands where we're going! Just set it again.
$redis->set('foo', 'baz');
$value = $redis->get('foo');
echo $value . "\n";
// Here we go incrementing unset values. No need to run messy UPSERT stuff.
echo "You've run this script " . $redis->incr('counter') . " times btw.\n";
// Tom is a simple associative array
$tom = array('name' => 'Thomas Hunter', 'age' => 27, 'height' => 165);
// The predis library makes setting hashes easy
$redis->hmset('tom', $tom);
// Now lets load that hash
$tom = $redis->hgetall('tom');
// As you can see, the object is exactly the same
var_dump($tom);
echo "\n";
// We can get a single field from our hash if we want
$tomsage = $redis->hget('tom', 'age');
echo "Tom is {$tomsage} years old.\n";
// We can increment a single field from the hash as well
$redis->hincrby('tom', 'age', '10');
$tom = $redis->hgetall('tom');
var_dump($tom);
echo "\n";
// Here's another simple associative array
$jessica = array('name' => 'Jessica Rabbit', 'age' => 30, 'height' => 140);
 */
require 'SharedConfigurations.php';
// Operations such as LRANGE, ZRANGE and others can potentially generate replies
// containing a huge number of items. In some corner cases, such replies might
// end up exhausting the maximum allowed memory allocated for a PHP process.
// Multibulk iterators can be handy because they allow you to stream multibulk
// replies using plain old PHP iterators, making it possible to iterate them with
// a classic `foreach` loop and avoiding to consume an excessive amount of memory.
//
// PS: please note that multibulk iterators are supported only by the standard
// connection backend class (Predis\Connection\StreamConnection) and not the
// phpiredis-based one (Predis\Connection\PhpiredisConnection).
// Create a client and force the connection to use iterable multibulk responses.
$client = new Predis\Client($single_server + array('iterable_multibulk' => true));
// Prepare an hash with some fields and their respective values.
$client->hmset('metavars', array('foo' => 'bar', 'hoge' => 'piyo', 'lol' => 'wut'));
// By default multibulk iterators iterate over the reply as a list of items...
foreach ($client->hgetall('metavars') as $index => $item) {
    echo "[{$index}] {$item}\n";
}
/* OUTPUT:
[0] foo
[1] bar
[2] hoge
[3] piyo
[4] lol
[5] wut
*/
// ... but certain multibulk replies are better represented as lists of tuples.
foreach ($client->hgetall('metavars')->asTuple() as $index => $kv) {
    list($key, $value) = $kv;
예제 #6
0
파일: index.php 프로젝트: mssmello/tokbox2
    }
    if (strlen($customerName) > 50) {
        $errorMessage = 'Campo customer_name é muito longo';
    }
    if (strlen($problemText) > 200) {
        $errorMessage = 'Campo problem_text é muito longo';
    }
    if (!empty($errorMessage)) {
        $app->response->setStatus(400);
        $app->response->setBody($errorMessage);
        return;
    }
    $session = $opentok->createSession();
    $responseData = array('apiKey' => $config->opentok('key'), 'sessionId' => $session->getSessionId(), 'token' => $session->generateToken());
    // Save the help session details
    $redisResponse = $redis->hmset(PREFIX_HELP_SESSION_KEY . $session->getSessionId(), 'customerName', $customerName, 'problemText', $problemText, 'sessionId', $session->getSessionId());
    // Handle errors
    if (!handleRedisError($redisResponse, $app, 'Não foi possível criar a sessão de vídeo chat.')) {
        return;
    }
    $app->response->headers->set('Content-Type', 'application/json');
    $app->response->setBody(json_encode($responseData));
});
// B) Enqueue in service queue
//    Request: (URL encoded)
//    *  `session_id`: The session which is ready to be enqueued
//
//    Response: (JSON encoded)
//    *  `queueId`: An identifier for the session's position in the queue
$app->post('/help/queue', function () use($app, $redis) {
    $sessionId = $app->request->params('session_id');
예제 #7
0
파일: N-RR.php 프로젝트: skunkwerks/netinf
    }
    exit(0);
}
// stage zero or one, both have this
$urival = filter_input(INPUT_POST, 'URI');
// update/add a record
if ($stage == "zero") {
    // read other stuff from HTTP POST form data
    $hint1 = filter_input(INPUT_POST, 'hint1');
    $hint2 = filter_input(INPUT_POST, 'hint2');
    $loc1 = filter_input(INPUT_POST, 'loc1');
    $loc2 = filter_input(INPUT_POST, 'loc2');
    $meta = filter_input(INPUT_POST, 'meta');
    // replace any values provided that aren't empty
    if (strlen($loc1) > 0) {
        $redis->hmset($urival, "loc1", $loc1);
    }
    if (strlen($loc2) > 0) {
        $redis->hmset($urival, "loc2", $loc2);
    }
    if (strlen($hint1) > 0) {
        $redis->hmset($urival, "hint1", $hint1);
    }
    if (strlen($hint2) > 0) {
        $redis->hmset($urival, "hint2", $hint2);
    }
    if (strlen($meta) > 0) {
        $redis->hmset($urival, "meta", $meta);
    }
    // $redis->hmset($urival,"loc1",$loc1,"loc2",$loc2,"hint1",$hint1,"hint2",$hint2,"meta",$meta);
}
예제 #8
0
파일: index.php 프로젝트: dima056359/oselya
<?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);