Ejemplo n.º 1
7
<?php

require 'vendor/autoload.php';
Predis\Autoloader::register();
$client = new Predis\Client(array('host' => '127.0.0.1', 'port' => 6379), array('prefix' => 'php:'));
$client->set("string:my_key", "Hello World");
$client->get("string:my_key");
# "Hello World"
$client->incr("string:counter");
$client->mget(array("string:my_key", "string:counter"));
# array('Hello World', '2')
$client->rpush("list:my_list", "item1", "item2");
$client->lpop("list:my_list");
# 'item1'
$client->hset("set:redis_book", "title", "Redis Essentials");
$client->hgetall("set:redis_book");
# array('title' => 'Redis Essentials')
$client->sadd("set:users", "alice", "bob");
$client->smembers("set:users");
# array('bob', 'alice')
$client->zadd("sorted_set:programmers", 1940, "Alan Kay");
$client->zadd("sorted_set:programmers", 1912, "Alan Turing");
$client->zrange("sorted_set:programmers", 0, -1, "withscores");
# array('Alan Turing' => 1912, 'Alan Kay' => 1940)
Ejemplo n.º 2
0
<table id="myTable" class="display">
    <thead>
        <tr>
            <th>info_hash</th>
            <th>peer_id</th>
            <th>ip4</th>
            <th>ip6</th>
            <th>port</th>
            <th>seed</th>
        </tr>
    </thead>
    <tbody>
        <?php 
require 'vendor/autoload.php';
$r = new Predis\Client();
$torrents = $r->smembers('torrents');
foreach ($torrents as $info_hash) {
    $peers = $r->smembers($info_hash);
    foreach ($peers as $peer_id) {
        $temp = $r->hmget($info_hash . ':' . $peer_id, 'ip4', 'ip6', 'port', 'seed');
        if (!$temp[3]) {
            $temp[3] = '0';
        }
        echo '<tr>';
        echo '<td>' . bin2hex($info_hash) . '</td>', '<td>' . bin2hex($peer_id) . '</td>', '<td>' . $temp[0] . '</td>', '<td>' . $temp[1] . '</td>', '<td>' . $temp[2] . '</td>', '<td>' . $temp[3] . '</td>';
        echo '</tr>';
    }
}
?>
    </tbody>
</table>
Ejemplo n.º 3
0
    $ip6 = $ip;
}
//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
Ejemplo n.º 4
0
<?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 sets
 *
 * @author changdi
 */
require "../shared.php";
$predis = new Predis\Client($single_server);
var_dump($predis->sadd('set-key', 'a', 'b', 'c'));
var_dump($predis->srem('set-key', 'c', 'd'));
var_dump($predis->srem('set-key', 'c', 'd'));
var_dump($predis->scard('set-key'));
var_dump($predis->smembers('set-key'));
var_dump($predis->smove('set-key', 'set-key2', 'a'));
var_dump($predis->smove('set-key', 'set-key2', 'c'));
var_dump($predis->smembers('set-key'));