Пример #1
0
 /**
  * Handle a GET request.
  *
  * @param string $key
  * @return void
  * @throws TCException
  */
 private function handleGet($key)
 {
     if (($data = $this->hdb->get($key)) === null) {
         $this->returnStatus(404, "'{$key}' not found.");
     } else {
         $this->returnResponse(200, $data, 'application/octet-stream');
     }
 }
Пример #2
0
<?php

extension_loaded('tokyocabinet') || dl('tokyocabinet.so') || exit(1);
try {
    $hdb = new TCHDB(TCBDB::KTINT64);
    $hdb->open('casket-i64.hdb', TCHDB::OWRITER | TCHDB::OCREAT);
    $hdb->put(2, 'hop');
    $hdb->put(0, 'step');
    $hdb->put(1, 'jump');
    echo $hdb->get(2), "\n";
    echo "-\n";
    foreach ($hdb as $key => $value) {
        printf("%s(%s):%s\n", gettype($key), $key, $value);
    }
    echo "-\n";
    printf("%s (%d records, %d bytes)\n", $hdb->path(), $hdb->rnum(), $hdb->fsiz());
} catch (TCException $e) {
    echo $e->getMessage(), "\n";
}
Пример #3
0
<?php

extension_loaded('tokyocabinet') || dl('tokyocabinet.so') || exit(1);
try {
    $hdb = new TCHDB(TCHDB::KTBINARY, TCHDB::VTSERIALIZED);
    $hdb->open('casket-s.hdb', TCHDB::OWRITER | TCHDB::OCREAT);
    $hdb->put('foo', array('hop'));
    $hdb->put('bar', array('step', 'Step'));
    $hdb->put('baz', array('jump', 'Jump', 'JUMP'));
    print_r($hdb->get('foo'));
    echo "-\n";
    foreach ($hdb as $key => $value) {
        printf("%s:%s", $key, print_r($value, true));
    }
    echo "-\n";
    printf("%s (%d records, %d bytes)\n", $hdb->path(), $hdb->rnum(), $hdb->fsiz());
    $hdb->sync();
    unset($hdb);
    // destruct
    echo "--\n";
    $raw = new TCHDB();
    $raw->open('casket-s.hdb', TCHDB::OREADER);
    foreach ($raw as $key => $value) {
        printf("%s:%s\n", $key, $value);
    }
} catch (TCException $e) {
    echo $e->getMessage(), "\n";
}
Пример #4
0
<?php

extension_loaded('tokyocabinet') || dl('tokyocabinet.so') || exit(1);
try {
    $hdb = new TCHDB(TCBDB::KTINT64);
    $hdb->open('casket-i64s.hdb', TCHDB::OWRITER | TCHDB::OCREAT);
    // big number string representations
    $hdb->put('98765432102', 'hop');
    $hdb->put('98765432100', 'step');
    $hdb->put('98765432101', 'jump');
    echo $hdb->get('98765432102'), "\n";
    echo "-\n";
    foreach ($hdb as $key => $value) {
        printf("%s(%s):%s\n", gettype($key), $key, $value);
    }
    echo "-\n";
    printf("%s (%d records, %d bytes)\n", $hdb->path(), $hdb->rnum(), $hdb->fsiz());
} catch (TCException $e) {
    echo $e->getMessage(), "\n";
}
Пример #5
0
<?php

extension_loaded('tokyocabinet') || dl('tokyocabinet.so') || exit(1);
try {
    $hdb = new TCHDB(TCBDB::KTINT64);
    $hdb->open('casket-i64f.hdb', TCHDB::OWRITER | TCHDB::OCREAT);
    // big number (more than 2147483647)
    // On 32-bit system, will be treated as a float.
    // On 64-bit system, will be treated as an integer.
    $hdb->put(98765432102.0, 'hop');
    $hdb->put(98765432100.0, 'step');
    $hdb->put(98765432101.0, 'jump');
    echo $hdb->get(98765432102.0), "\n";
    echo "-\n";
    foreach ($hdb as $key => $value) {
        printf("%s(%s):%s\n", gettype($key), $key, $value);
    }
    echo "-\n";
    printf("%s (%d records, %d bytes)\n", $hdb->path(), $hdb->rnum(), $hdb->fsiz());
} catch (TCException $e) {
    echo $e->getMessage(), "\n";
}
Пример #6
0
<?php

extension_loaded('tokyocabinet') || dl('tokyocabinet.so') || exit(1);
try {
    $hdb = new TCHDB();
    $hdb->open('casket.hdb', TCHDB::OWRITER | TCHDB::OCREAT);
    $hdb->put('foo', 'hop');
    $hdb->put('bar', 'step');
    $hdb->put('baz', 'jump');
    echo $hdb->get('foo'), "\n";
    echo "-\n";
    foreach ($hdb as $key => $value) {
        printf("%s:%s\n", $key, $value);
    }
    echo "-\n";
    printf("%s (%d records, %d bytes)\n", $hdb->path(), $hdb->rnum(), $hdb->fsiz());
} catch (TCException $e) {
    echo $e->getMessage(), "\n";
}