douliangli6407 2014-12-15 23:22
浏览 59
已采纳

$ object-> getData()返回null,即使在DB中有数据

I just started using Riak (for a college project) and we got a CentOS machine with Riak 1.4.2 on it.

I made a bucket called "testbucket" and in it key,value pair "helloworld", "Hello World!" using curl. Then I tried fetching the data using curl and browser, and everything was fine, I got "Hello World!" back as intended.

The problem was that I need to make a web project using PHP and I'm stuck with the following:

<?php

require_once('riak-php-client-master/src/Basho/Riak/Riak.php');
require_once('riak-php-client-master/src/Basho/Riak/Bucket.php');
require_once('riak-php-client-master/src/Basho/Riak/Exception.php');
require_once('riak-php-client-master/src/Basho/Riak/Link.php');
require_once('riak-php-client-master/src/Basho/Riak/MapReduce.php');
require_once('riak-php-client-master/src/Basho/Riak/Object.php');
require_once('riak-php-client-master/src/Basho/Riak/StringIO.php');
require_once('riak-php-client-master/src/Basho/Riak/Utils.php');
require_once('riak-php-client-master/src/Basho/Riak/Link/Phase.php');
require_once('riak-php-client-master/src/Basho/Riak/MapReduce/Phase.php');

$connection = new Basho\Riak\Riak('192.168.56.12', 10018);

$bucket = new Basho\Riak\Bucket($connection, 'testbucket');
$object = $bucket->get('helloworld');
var_dump($object);

?>

var_dump prints the following:

object(Basho\Riak\Object)[3]
  protected 'meta' => 
    array (size=0)
      empty
  protected 'indexes' => 
    array (size=0)
      empty
  protected 'autoIndexes' => 
    array (size=0)
      empty
  public 'client' => 
    object(Basho\Riak\Riak)[1]
      public 'host' => string '192.168.56.12' (length=13)
      public 'port' => int 10018
      public 'prefix' => string 'riak' (length=4)
      public 'mapred_prefix' => string 'mapred' (length=6)
      public 'indexPrefix' => string 'buckets' (length=7)
      public 'clientid' => string 'php_us1pa7' (length=10)
      public 'r' => int 2
      public 'w' => int 2
      public 'dw' => int 2
  public 'bucket' => 
    object(Basho\Riak\Bucket)[2]
      public 'client' => 
        object(Basho\Riak\Riak)[1]
          public 'host' => string '192.168.56.12' (length=13)
          public 'port' => int 10018
          public 'prefix' => string 'riak' (length=4)
          public 'mapred_prefix' => string 'mapred' (length=6)
          public 'indexPrefix' => string 'buckets' (length=7)
          public 'clientid' => string 'php_us1pa7' (length=10)
          public 'r' => int 2
          public 'w' => int 2
          public 'dw' => int 2
      public 'name' => string 'testbucket' (length=10)
      public 'r' => null
      public 'w' => null
      public 'dw' => null
  public 'key' => string 'helloworld' (length=10)
  public 'jsonize' => boolean true
  public 'headers' => 
    array (size=10)
      'http_code' => int 200
      'x-riak-vclock' => string 'a85hYGBgzGDKBVIcKlYHQkK6OW9mMCUy5bEyBGgwn+PLAgA=' (length=48)
      'vary' => string 'Accept-Encoding' (length=15)
      'server' => string 'MochiWeb/1.1 WebMachine/1.10.0 (never breaks eye contact)' (length=57)
      'link' => string '</riak/testbucket>; rel="up"' (length=28)
      'last-modified' => string 'Mon, 15 Dec 2014 09:39:28 GMT' (length=29)
      'etag' => string '"y0akdKQCeEWM2HBgOp0tK"' (length=23)
      'date' => string 'Mon, 15 Dec 2014 13:56:54 GMT' (length=29)
      'content-type' => string 'text/html' (length=9)
      'content-length' => string '38' (length=2)
  public 'links' => 
    array (size=0)
      empty
  public 'siblings' => null
  public 'exists' => boolean true
  public 'data' => null

Of course, trying to do $object->getData() results in Exception. I'm completely baffled as the data clearly exists (checked with both curl and through browser) and yet I can't seem to access it this way. It seems weird especially as the line "'content-length' => string '38' (length=2)" says that obviously there should be some data in the body.

  • 写回答

1条回答 默认 最新

  • dou91808 2014-12-15 23:32
    关注

    Since get is for json-encoded data, according to the docs, try using getBinary

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Macbookpro 连接热点正常上网,连接不了Wi-Fi。
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析