本文整理汇总了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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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());
}
示例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;
}
示例7: testSlaveOkay2
public function testSlaveOkay2()
{
$this->assertFalse(MongoCursor::$slaveOkay);
MongoCursor::$slaveOkay = true;
$this->assertTrue(MongoCursor::$slaveOkay);
}
示例8: slaveOkay
public function slaveOkay($okay = true)
{
parent::slaveOkay($okay);
return $this;
}
示例9: slaveOkay
/**
* 设置此次查询是否可以在从db上执行
* @param Boolean $okay
* @return muMongoCursor
*/
public function slaveOkay($okay = true)
{
$this->oMongoCursor->slaveOkay($okay);
return $this;
}