当前位置: 首页>>代码示例>>PHP>>正文


PHP MongoCursor::slaveOkay方法代码示例

本文整理汇总了PHP中MongoCursor::slaveOkay方法的典型用法代码示例。如果您正苦于以下问题:PHP MongoCursor::slaveOkay方法的具体用法?PHP MongoCursor::slaveOkay怎么用?PHP MongoCursor::slaveOkay使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MongoCursor的用法示例。


在下文中一共展示了MongoCursor::slaveOkay方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getCollection

 public function getCollection($collectionName)
 {
     MongoCursor::$slaveOkay = true;
     //if empty($this->dbName) throw error;
     $dbName = $this->dbName;
     Yii::import('application.extensions.mp.db.mongodb.*');
     $this->_collection = new MongoMSCollection($this->_writeServer->{$dbName}, $collectionName);
     $this->_collection->addSlaves($this->_readServers);
     return $this->_collection;
 }
开发者ID:hukumonline,项目名称:yii,代码行数:10,代码来源:MPMongoDbManager.php

示例2: fetch

 public function fetch($key, &$value, $timeout_version = null)
 {
     MongoCursor::$slaveOkay = true;
     $store = self::$_mongodb->findOne(array('key' => $this->create_key($key)));
     if (!is_null($store) && $timeout_version < $store['dateline']) {
         if ($store['ttl'] > 0 && $store['dateline'] + $store['ttl'] < time()) {
             return false;
         }
         $value = $store['value'];
         return true;
     }
     return false;
 }
开发者ID:sss201413,项目名称:ecstore,代码行数:13,代码来源:mongodb.php

示例3: setMongoCursorSlaveOkay

 /**
  * Set whether secondary read queries are allowed for this cursor.
  *
  * This method wraps setSlaveOkay() for driver versions before 1.3.0. For
  * newer drivers, this method either wraps setReadPreference() method and
  * specifies SECONDARY_PREFERRED or does nothing, depending on whether
  * setReadPreference() exists.
  *
  * @param boolean $ok
  */
 public function setMongoCursorSlaveOkay($ok)
 {
     if (version_compare(phpversion('mongo'), '1.3.0', '<')) {
         $this->mongoCursor->slaveOkay($ok);
         return;
     }
     /* MongoCursor::setReadPreference() may not exist until 1.4.0. Although
      * we could throw an exception here, it's more user-friendly to NOP.
      */
     if (!method_exists($this->mongoCursor, 'setReadPreference')) {
         return;
     }
     if ($ok) {
         // Preserve existing tags for non-primary read preferences
         $readPref = $this->mongoCursor->getReadPreference();
         $tags = !empty($readPref['tagsets']) ? ReadPreference::convertTagSets($readPref['tagsets']) : array();
         $this->mongoCursor->setReadPreference(\MongoClient::RP_SECONDARY_PREFERRED, $tags);
     } else {
         $this->mongoCursor->setReadPreference(\MongoClient::RP_PRIMARY);
     }
 }
开发者ID:ne0h12,项目名称:mongodb,代码行数:31,代码来源:Cursor.php

示例4: activemongo2_service

/**
 *  @Service(activemongo, {
 *      host: {default: 'localhost'},
 *      user: {default: NULL},
 *      pass: {default: NULL},
 *      replicaSet: {default: NULL},
 *      db: {required: true},
 *      opts: { default:{}, type: 'hash'},
 *      path: { require: true, type: array_dir},
 *      temp_dir: { default: '/tmp', type: dir },
 *      w: {default: 1},
 *      devel: {default: true}
 *  }, { shared: true })
 */
function activemongo2_service($config)
{
    if (!$config['replicaSet']) {
        $conn = new \MongoClient($config['host'], $config['opts']);
    } else {
        $conn = new \MongoClient($config['host'], array("replicaSet" => $config['replicaSet']), $config['opts']);
        $conn->setReadPreference(\MongoClient::RP_SECONDARY);
        \MongoCursor::$slaveOkay = true;
    }
    $db = $conn->selectDB($config['db']);
    if ($config['user'] || $config['pass']) {
        $db->authenticate($config['user'], $config['pass']);
    }
    $conf = new \ActiveMongo2\Configuration($config['temp_dir'] . "/activemongo2__" . $db . ".php");
    foreach ((array) $config['path'] as $path) {
        $conf->addModelPath($path);
    }
    if ($config['devel']) {
        $conf->development();
    }
    $conf->setWriteConcern($config['w']);
    $mongo = new \ActiveMongo2\Connection($conf, $conn, $db);
    return $mongo;
}
开发者ID:agpmedia,项目名称:activemongo2,代码行数:38,代码来源:service.php

示例5: catch

} catch (Exception $e) {
    var_dump($e->getCode(), $e->getMessage());
}
echo "STRING:\n";
try {
    $m = new MongoClient("mongodb://localhost/?readPreference");
} catch (Exception $e) {
    var_dump($e->getCode(), $e->getMessage());
}
try {
    $m = new MongoClient("mongodb://localhost/?=true");
} catch (Exception $e) {
    var_dump($e->getCode(), $e->getMessage());
}
try {
    $m = new MongoClient("mongodb://localhost/?timeou=4");
} catch (Exception $e) {
    var_dump($e->getCode(), $e->getMessage());
}
try {
    $m = new MongoClient("mongodb://localhost/?readPreference=nearest;slaveOkay=true");
} catch (Exception $e) {
    var_dump($e->getCode(), $e->getMessage());
}
echo "OTHERS:\n";
MongoCursor::$slaveOkay = true;
try {
    $m = new MongoClient("localhost", array("connect" => false, "readPreference" => "nearest"));
} catch (Exception $e) {
    var_dump($e->getCode(), $e->getMessage());
}
开发者ID:badlamer,项目名称:hhvm,代码行数:31,代码来源:bug00617.php

示例6: find

 /**
  * 查找记录
  * @param string $dbname
  * @param string $table_name 表名
  * @param array $query_condition 字段查找条件
  * @param array $result_condition 查询结果限制条件-limit/sort等
  * @param array $fields 获取字段
  * @return array
  */
 public function find($dbname, $table_name, $query_condition, $result_condition = array(), $fields = array())
 {
     $this->initSlavesConnection();
     MongoCursor::$slaveOkay = true;
     //从查询必备
     $cursor = $this->slaves->{$dbname}->{$table_name}->find($query_condition, $fields)->slaveOkay(true);
     if (!empty($result_condition['start'])) {
         $cursor->skip($result_condition['start']);
     }
     if (!empty($result_condition['limit'])) {
         $cursor->limit($result_condition['limit']);
     }
     if (!empty($result_condition['sort'])) {
         $cursor->sort($result_condition['sort']);
     }
     $result = array();
     try {
         while ($cursor->hasNext()) {
             $result[] = $cursor->getNext();
         }
     } catch (MongoConnectionException $e) {
         $this->error = $e->getMessage();
         return false;
     } catch (MongoCursorTimeoutException $e) {
         $this->error = $e->getMessage();
         return false;
     }
     return $result;
 }
开发者ID:huoshi5151,项目名称:i18nadmin,代码行数:38,代码来源:MongoHelper.php

示例7: testSlaveOkay2

 public function testSlaveOkay2()
 {
     $this->assertFalse(MongoCursor::$slaveOkay);
     MongoCursor::$slaveOkay = true;
     $this->assertTrue(MongoCursor::$slaveOkay);
 }
开发者ID:redmeadowman,项目名称:mongo-php-driver,代码行数:6,代码来源:MongoCursorTest.php

示例8: slaveOkay

 public function slaveOkay($okay = true)
 {
     parent::slaveOkay($okay);
     return $this;
 }
开发者ID:lisong,项目名称:incubator,代码行数:5,代码来源:Cursor.php

示例9: slaveOkay

 /**
  * 设置此次查询是否可以在从db上执行
  * @param Boolean $okay
  * @return muMongoCursor
  */
 public function slaveOkay($okay = true)
 {
     $this->oMongoCursor->slaveOkay($okay);
     return $this;
 }
开发者ID:diandengs,项目名称:RechoPHP,代码行数:10,代码来源:class.Mumongo.php


注:本文中的MongoCursor::slaveOkay方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。