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

时间:2014-12-15 23:22:56

标签: php riak

我刚刚开始使用Riak(用于大学项目),我们得到了一台带有Riak 1.4.2的CentOS机器。

我制作了一个名为“testbucket”的桶,其中包括键,值对“helloworld”,“Hello World!”使用卷曲。然后我尝试使用curl和浏览器获取数据,一切都很好,我得到了“Hello World!”按预期回来。

问题是我需要使用PHP创建一个Web项目,并且我坚持使用以下内容:

<?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打印以下内容:

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

当然,尝试执行$ object-&gt; getData()会导致异常。 我完全感到困惑,因为数据显然存在(通过curl和浏览器检查)但我似乎无法以这种方式访问​​它。这看起来很奇怪,特别是因为“'content-length'=&gt;字符串'38'(长度= 2)”“说明显然身体中应该有一些数据。

1 个答案:

答案 0 :(得分:1)

由于get用于json编码数据,根据docs,请尝试使用getBinary