_id
stringlengths 2
7
| title
stringlengths 3
151
| partition
stringclasses 3
values | text
stringlengths 83
13k
| language
stringclasses 1
value | meta_information
dict |
---|---|---|---|---|---|
q257400 | SEOEditorAdmin.removeEmptyAttributes | test | private function removeEmptyAttributes(SS_List $list, $type)
{
$pageAttributes = $list->map('ID', $type)->toArray();
$emptyAttributess = array_map(function ($value) {
return $value == '';
}, $pageAttributes);
if (!count($emptyAttributess)) {
return $list;
}
return $list->filter([
'ID:not' => array_keys(
array_filter($emptyAttributess, function ($value) {
return $value == 1;
})
)
]);
} | php | {
"resource": ""
} |
q257401 | SEOEditorCSVLoader.processRecord | test | public function processRecord($record, $columnMap, &$results, $preview = false)
{
$page = $this->findExistingObject($record, $columnMap);
if (!$page || !$page->exists()) {
return false;
}
foreach ($record as $fieldName => $val) {
if ($fieldName == 'MetaTitle' || $fieldName == 'MetaDescription') {
$sqlValue = Convert::raw2sql($val);
DB::query("UPDATE SiteTree SET {$fieldName} = '{$sqlValue}' WHERE ID = {$page->ID}");
if ($page->isPublished()) {
DB::query("UPDATE SiteTree_Live SET {$fieldName} = '{$sqlValue}' WHERE ID = {$page->ID}");
}
}
}
return $page->ID;
} | php | {
"resource": ""
} |
q257402 | Authorize.handle | test | public function handle($request, $next)
{
return resolve(AllReleases::class)->authorize($request) ? $next($request) : abort(403);
} | php | {
"resource": ""
} |
q257403 | Rediska_Profiler_Profile.getElapsedTime | test | public function getElapsedTime($decimals = null)
{
if (!$this->hasStopped()) {
return false;
}
$elapsedTime = $this->_stopTime - $this->_startTime;
if ($decimals) {
return number_format($elapsedTime, $decimals);
} else {
return $elapsedTime;
}
} | php | {
"resource": ""
} |
q257404 | Rediska_Command_Abstract.read | test | public function read()
{
$responses = array();
if (!$this->_isWritten) {
throw new Rediska_Command_Exception('You need write before');
}
foreach ($this->_execs as $exec) {
$responses[] = $exec->read();
}
if (isset($responses[0]) && $responses[0] === self::QUEUED) {
$this->_isQueued = true;
return true;
} else {
$this->_isWritten = false;
return $this->parseResponses($responses);
}
} | php | {
"resource": ""
} |
q257405 | Rediska_Command_Abstract._argumentsToString | test | protected function _argumentsToString($arguments)
{
$strings = array();
foreach($arguments as $name => $value) {
$key = !is_integer($name) ? "'$name' => " : '';
if (is_object($value)) {
$argument = get_class($value) . ' $' . $name;
} else if (is_numeric($value)) {
$argument = $value;
} else if (is_string($value)) {
$argument = "'$value'";
} else if (is_array($value)) {
$argument = 'array(' . $this->_argumentsToString($value) . ')';
} else if (is_null($value)) {
$argument = 'null';
} else if ($value === true) {
$argument = 'true';
} else if ($value === false) {
$argument = 'false';
}
$strings[] = $key . $argument;
}
return implode(', ', $strings);
} | php | {
"resource": ""
} |
q257406 | Rediska_Command_Abstract._getAndValidateArguments | test | protected function _getAndValidateArguments($arguments)
{
$className = get_class($this);
if (!isset(self::$_argumentNames[$className])) {
$reflection = new ReflectionMethod($this, 'create');
self::$_argumentNames[$className] = array();
foreach($reflection->getParameters() as $parameter) {
self::$_argumentNames[$className][] = $parameter;
}
}
$count = 0;
$argumentNamesAndValues = array();
foreach(self::$_argumentNames[$className] as $parameter) {
if (array_key_exists($count, $arguments)) {
$value = $arguments[$count];
} else if ($parameter->isOptional()) {
$value = $parameter->getDefaultValue();
} else {
throw new Rediska_Command_Exception("Argument '{$parameter->getName()}' not present for command '$this->_name'");
}
$argumentNamesAndValues[$parameter->getName()] = $value;
$count++;
}
return $argumentNamesAndValues;
} | php | {
"resource": ""
} |
q257407 | Rediska_Command_Abstract._throwExceptionIfNotSupported | test | protected function _throwExceptionIfNotSupported($version = null)
{
if (null === $version) {
$version = $this->_version;
}
$redisVersion = $this->_rediska->getOption('redisVersion');
if (version_compare($version, $redisVersion) == 1) {
throw new Rediska_Command_Exception("Command '{$this->_name}' requires {$version}+ version of Redis server. Current version is {$redisVersion}. To change it specify 'redisVersion' option.");
}
} | php | {
"resource": ""
} |
q257408 | Rediska_Autoloader.register | test | public static function register($prepend = false)
{
if (self::isRegistered()) {
return false;
}
if (!is_bool($prepend)) {
$prepend = (bool) $prepend;
}
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
self::$_isRegistered = spl_autoload_register(self::$_callback);
} else {
self::$_isRegistered = spl_autoload_register(
self::$_callback,
true,
$prepend
);
}
return self::$_isRegistered;
} | php | {
"resource": ""
} |
q257409 | Rediska_Autoloader.unregister | test | public static function unregister()
{
if (!self::isRegistered()) {
return false;
}
self::$_isRegistered = !spl_autoload_unregister(self::$_callback);
return self::$_isRegistered;
} | php | {
"resource": ""
} |
q257410 | Rediska_Autoloader.getRediskaPath | test | public static function getRediskaPath()
{
if (!self::$_rediskaPath) {
self::$_rediskaPath = realpath(dirname(__FILE__) . '/..');
}
return self::$_rediskaPath;
} | php | {
"resource": ""
} |
q257411 | Rediska_KeyDistributor_ConsistentHashing.getConnectionsByKeyName | test | public function getConnectionsByKeyName($name, $count)
{
// If we have only one backend, return it.
if ($this->_backendsCount == 1) {
return array_keys($this->_backends);
}
if (!$this->_hashringIsInitialized) {
$this->_initializeHashring();
$this->_hashringIsInitialized = true;
}
// If the key has already been mapped, return the cached entry.
if ($this->_cacheMax > 0 && isset($this->_cache[$name])) {
return $this->_cache[$name];
}
// If $count is greater than or equal to the number of available backends, return all.
if ($count >= $this->_backendsCount) return array_keys($this->_backends);
// Initialize the return array.
$return = array();
$crc32 = crc32($name);
// Select the slice to begin with.
$slice = floor($crc32 / $this->_slicesDiv) + $this->_slicesHalf;
// This counter prevents going through more than 1 loop.
$looped = false;
while (true) {
// Go through the hashring, one slice at a time.
foreach ($this->_hashring[$slice] as $position => $backend) {
// If we have a usable backend, add to the return array.
if ($position >= $crc32) {
// If $count = 1, no more checks are necessary.
if ($count === 1) {
$return = array($backend);
break 2;
} elseif (!in_array($backend, $return)) {
$return[] = $backend;
if (count($return) >= $count) break 2;
}
$return = array($backend);
break 1;
}
}
// Continue to the next slice.
$slice++;
// If at the end of the hashring.
if ($slice >= $this->_slicesCount) {
// If already looped once, something is wrong.
if ($looped) {
break;
}
// Otherwise, loop back to the beginning.
$crc32 = -2147483648;
$slice = 0;
$looped = true;
}
}
// Cache the result for quick retrieval in the future.
if ($this->_cacheMax > 0) {
// Add to internal cache.
$this->_cache[$name] = $return;
$this->_cacheCount++;
// If the cache is getting too big, clear it.
if ($this->_cacheCount > $this->_cacheMax) {
$this->_cleanCache();
}
}
// Return the result.
return $return;
} | php | {
"resource": ""
} |
q257412 | Rediska_PubSub_Connections.getConnectionByChannelName | test | public function getConnectionByChannelName($name)
{
// Get connection
if ($this->_specifiedConnection) {
$connection = $this->_specifiedConnection;
} else {
$connection = $this->_channel->getRediska()->getConnectionByKeyName($name);
}
if (!array_key_exists($connection->getAlias(), $this->_connections)) {
$this->_connections[$connection->getAlias()] = clone $connection;
// If more than one - move to non blocking mode
if (count($this->_connections) > 1) {
foreach($this->_connections as $connection) {
if ($connection->getOption('blockingMode')) {
$connection->setOption('blockingMode', false);
}
}
}
}
$connection = $this->_connections[$connection->getAlias()];
return $connection;
} | php | {
"resource": ""
} |
q257413 | Rediska_PubSub_Connections.getChannelsByConnection | test | public function getChannelsByConnection(Rediska_Connection $connection)
{
if (!isset($this->_channelsByConnections[$connection->getAlias()])) {
throw new Rediska_PubSub_Exception("Channels by this connection not present");
}
return $this->_channelsByConnections[$connection->getAlias()];
} | php | {
"resource": ""
} |
q257414 | Rediska_Config.get | test | public function get($nameOrPattern)
{
$configGet = new Rediska_Connection_Exec($this->_connection, array('CONFIG', 'GET', $nameOrPattern));
$valuesAfterNames = $configGet->execute();
if (preg_match('/\W/i', $nameOrPattern)) { // Pattern
$isParameter = true;
$namesAndValues = array();
foreach($valuesAfterNames as $nameOrValue) {
if ($isParameter) {
$name = $nameOrValue;
} else {
$namesAndValues[$name] = $this->_sanitizeValue($nameOrValue);
}
$isParameter = !$isParameter;
}
return $namesAndValues;
} else { // Parameter name
if (empty($valuesAfterNames)) {
return null;
} else {
return $this->_sanitizeValue($valuesAfterNames[1]);
}
}
} | php | {
"resource": ""
} |
q257415 | Rediska_Config.set | test | public function set($name, $value)
{
$exec = new Rediska_Connection_Exec($this->_connection, array('CONFIG', 'SET', $name, $value));
$exec->execute();
return $this;
} | php | {
"resource": ""
} |
q257416 | Rediska_Config._throwIfNotSupported | test | protected function _throwIfNotSupported()
{
$version = '2.0';
$redisVersion = $this->_rediska->getOption('redisVersion');
if (version_compare($version, $this->_rediska->getOption('redisVersion')) == 1) {
throw new Rediska_Transaction_Exception("Transaction requires {$version}+ version of Redis server. Current version is {$redisVersion}. To change it specify 'redisVersion' option.");
}
} | php | {
"resource": ""
} |
q257417 | Rediska_Zend_Queue_Adapter_Redis.create | test | public function create($name, $timeout = null)
{
$this->_queues->add($name);
$this->_queueObjects[$name] = new Rediska_Key_List($this->_getKeyName("queue_$name"), array('rediska' => $this->_rediska));
return true;
} | php | {
"resource": ""
} |
q257418 | Rediska_Zend_Queue_Adapter_Redis.delete | test | public function delete($name)
{
if ($this->_queues->remove($name)) {
if (isset($this->_queueObjects[$name])) {
unset($this->_queueObjects[$name]);
}
return $this->_rediska->delete($this->_getKeyName("queue_$name"));
}
} | php | {
"resource": ""
} |
q257419 | Rediska_Zend_Queue_Adapter_Redis.count | test | public function count(Zend_Queue $queue=null)
{
if ($queue === null) {
$queue = $this->_queue;
}
$queueName = $queue->getName();
if (!$this->isExists($queueName)) {
require_once 'Zend/Queue/Exception.php';
throw new Zend_Queue_Exception('Queue does not exist:' . $queueName);
}
if (!isset($this->_queueObjects[$queueName])) {
$this->_queueObjects[$queueName] = new Rediska_Key_List($this->_getKeyName("queue_$queueName"), array('rediska' => $this->_rediska));
}
return count($this->_queueObjects[$queueName]);
} | php | {
"resource": ""
} |
q257420 | Rediska_Zend_Queue_Adapter_Redis.send | test | public function send($message, Zend_Queue $queue=null)
{
if ($queue === null) {
$queue = $this->_queue;
}
$queueName = $queue->getName();
if (!$this->isExists($queueName)) {
require_once 'Zend/Queue/Exception.php';
throw new Zend_Queue_Exception('Queue does not exist:' . $queueName);
}
if (!isset($this->_queueObjects[$queueName])) {
$this->_queueObjects[$queueName] = new Rediska_Key_List($this->_getKeyName("queue_$queueName"), array('rediska' => $this->_rediska));
}
$result = $this->_queueObjects[$queueName]->prepend($message);
if ($result === false) {
require_once 'Zend/Queue/Exception.php';
throw new Zend_Queue_Exception('Failed to insert message into queue:' . $queueName);
}
$options = array(
'queue' => $queue,
'data' => array('body' => $message),
);
$classname = $queue->getMessageClass();
if (!class_exists($classname)) {
require_once 'Zend/Loader.php';
Zend_Loader::loadClass($classname);
}
return new $classname($options);
} | php | {
"resource": ""
} |
q257421 | Rediska_Zend_Queue_Adapter_Redis.receive | test | public function receive($maxMessages=null, $timeout=null, Zend_Queue $queue=null)
{
if ($maxMessages === null) {
$maxMessages = 1;
}
if ($queue === null) {
$queue = $this->_queue;
}
$queueName = $queue->getName();
if (!$this->isExists($queueName)) {
require_once 'Zend/Queue/Exception.php';
throw new Zend_Queue_Exception('Queue does not exist:' . $queueName);
}
if (!isset($this->_queueObjects[$queueName])) {
$this->_queueObjects[$queueName] = new Rediska_Key_List($this->_getKeyName("queue_$queueName"), array('rediska' => $this->_rediska));
}
$messages = array();
for ($i = 0; $i < $maxMessages; $i++) {
$message = $this->_queueObjects[$queueName]->pop();
if (!is_null($message)) {
$messages[] = array('body' => $message);
}
}
$options = array(
'queue' => $queue,
'data' => $messages,
'messageClass' => $queue->getMessageClass(),
);
$classname = $queue->getMessageSetClass();
if (!class_exists($classname)) {
require_once 'Zend/Loader.php';
Zend_Loader::loadClass($classname);
}
return new $classname($options);
} | php | {
"resource": ""
} |
q257422 | Rediska_Zend_Queue_Adapter_Redis.deleteMessage | test | public function deleteMessage(Zend_Queue_Message $message)
{
$queueName = $this->_queue->getName();
if (!isset($this->_queueObjects[$queueName])) {
$this->_queueObjects[$queueName] = new Rediska_Key_List($this->_getKeyName("queue_$queueName"), array('rediska' => $this->_rediska));
}
return (boolean)$this->_queueObjects[$queueName]->remove($message->body);
} | php | {
"resource": ""
} |
q257423 | Rediska_Profiler.getTotalElapsedTime | test | public function getTotalElapsedTime($decimals = null)
{
$totalElapsedTime = 0;
foreach ($this->getProfiles() as $profile) {
if ($profile->hasStopped()) {
$totalElapsedTime += $profile->getElapsedTime();
}
}
if ($decimals) {
return number_format($totalElapsedTime, $decimals);
} else {
return $totalElapsedTime;
}
} | php | {
"resource": ""
} |
q257424 | Rediska_Key_Hash.set | test | public function set($fieldOrData, $value = null, $overwrite = true)
{
$result = $this->_getRediskaOn()->setToHash($this->getName(), $fieldOrData, $value, $overwrite);
if (!is_null($this->getExpire()) && ((!$overwrite && $result) || ($overwrite))) {
$this->expire($this->getExpire(), $this->isExpireTimestamp());
}
return $result;
} | php | {
"resource": ""
} |
q257425 | Rediska_Key_Hash.offsetSet | test | public function offsetSet($field, $value)
{
if (is_null($field)) {
throw new Rediska_Key_Exception('Field must be present');
}
$this->set($field, $value);
return $value;
} | php | {
"resource": ""
} |
q257426 | Rediska_Key_Hash.increment | test | public function increment($field, $amount = 1)
{
$result = $this->_getRediskaOn()->incrementInHash($this->getName(), $field, $amount);
if (!is_null($this->getExpire()) && $result) {
$this->expire($this->getExpire(), $this->isExpireTimestamp());
}
return $result;
} | php | {
"resource": ""
} |
q257427 | Rediska_Key_Hash.remove | test | public function remove($field)
{
$result = $this->_getRediskaOn()->deleteFromHash($this->getName(), $field);
if (!is_null($this->getExpire()) && $result) {
$this->expire($this->getExpire(), $this->isExpireTimestamp());
}
return $result;
} | php | {
"resource": ""
} |
q257428 | Rediska_Zend_Session_SaveHandler_Redis.write | test | public function write($id, $data)
{
try {
$timestamp = time();
$this->_set[$timestamp] = $id;
} catch (Rediska_Connection_Exec_Exception $e) {
$this->_deleteSetOrThrowException($e);
}
return $this->getRediska()->setAndExpire(
$this->_getKeyName($id),
$data,
$this->getOption('lifetime')
);
} | php | {
"resource": ""
} |
q257429 | Rediska_PubSub_Channel.subscribe | test | public function subscribe($channelOrChannels)
{
if (!is_array($channelOrChannels)) {
$channels = array($channelOrChannels);
} else {
$channels = $channelOrChannels;
}
$this->_execCommand(self::SUBSCRIBE, $channels);
return $this;
} | php | {
"resource": ""
} |
q257430 | Rediska_PubSub_Channel.publish | test | public function publish($message)
{
$rediska = $this->getRediska();
if ($this->getServerAlias() !== null) {
$rediska = $rediska->on($this->getServerAlias());
}
return $rediska->publish($this->_subscriptions, $message);
} | php | {
"resource": ""
} |
q257431 | Rediska_PubSub_Channel._addMessageToBuffer | test | protected function _addMessageToBuffer(Rediska_PubSub_Response_Message $message)
{
$key = "{$message->getConnection()->getAlias()}-{$message->getChannel()}";
if (!isset(self::$_messages[$key])) {
self::$_messages[$key] = array();
}
self::$_messages[$key][] = $message;
} | php | {
"resource": ""
} |
q257432 | Rediska_PubSub_Channel._throwIfNotSupported | test | protected function _throwIfNotSupported()
{
$version = '1.3.8';
$redisVersion = $this->getRediska()->getOption('redisVersion');
if (version_compare($version, $this->getRediska()->getOption('redisVersion')) == 1) {
throw new Rediska_PubSub_Exception("Publish/Subscribe requires {$version}+ version of Redis server. Current version is {$redisVersion}. To change it specify 'redisVersion' option.");
}
} | php | {
"resource": ""
} |
q257433 | Rediska_Serializer_Adapter_PhpSerialize.catchUnserializeNotice | test | public function catchUnserializeNotice($errno, $errstr, $errfile, $errline, $errcontext)
{
if (!error_reporting() && strpos($errstr, 'unserialize()') !== false) {
$this->_unserialized = false;
return true;
} else {
return false;
}
} | php | {
"resource": ""
} |
q257434 | Rediska_Zend_Queue_Adapter_Redis_Queues.add | test | public function add($name)
{
$result = $this->_queuesSet->add($name);
if ($result) {
$queuesCache = $this->_getQueuesCache();
$queuesCache[] = $name;
$this->_setQueuesCache($queuesCache);
}
return $result;
} | php | {
"resource": ""
} |
q257435 | Rediska_Zend_Queue_Adapter_Redis_Queues.remove | test | public function remove($name)
{
$result = $this->_queuesSet->remove($name);
if ($result) {
$queuesCache = $this->_getQueuesCache();
$key = array_search($name, $queuesCache);
unset($queuesCache[$key]);
$this->_setQueuesCache($queuesCache);
}
return $result;
} | php | {
"resource": ""
} |
q257436 | Rediska_Zend_Queue_Adapter_Redis_Queues._getQueuesCache | test | protected function _getQueuesCache()
{
if ($this->_queuesCache === null) {
$this->_queuesCache = $this->_queuesSet->toArray();
}
return $this->_queuesCache;
} | php | {
"resource": ""
} |
q257437 | Rediska_Transaction.watch | test | public function watch($keyOrKeys)
{
$this->_throwIfNotSupported('Watch', '2.1');
$command = array('WATCH');
if (!is_array($keyOrKeys)) {
$keys = array($keyOrKeys);
} else {
$keys = $keyOrKeys;
}
foreach($keys as $key) {
$command[] = $this->_rediska->getOption('namespace') . $key;
}
$exec = new Rediska_Connection_Exec($this->_connection, $command);
$exec->execute();
$this->_isWatched = true;
return $this;
} | php | {
"resource": ""
} |
q257438 | Rediska_Transaction.unwatch | test | public function unwatch()
{
$this->_throwIfNotSupported('Unwatch', '2.1');
$command = 'UNWATCH';
$exec = new Rediska_Connection_Exec($this->_connection, $command);
$exec->execute();
$this->_isWatched = false;
return $this;
} | php | {
"resource": ""
} |
q257439 | Rediska_Transaction._addCommand | test | protected function _addCommand($name, $args = array())
{
$this->_specifiedConnection->setConnection($this->_connection);
$command = Rediska_Commands::get($this->_rediska, $name, $args);
$command->initialize();
if (!$command->isAtomic()) {
throw new Rediska_Exception("Command '$name' doesn't work properly (not atomic) in transaction on multiple servers");
}
$this->_commands[] = $command;
$this->_specifiedConnection->resetConnection();
return $this;
} | php | {
"resource": ""
} |
q257440 | PostController.newAction | test | public function newAction()
{
$currentUser = Zend_Auth::getInstance()->getStorage()->read();
$form = new Form_Post;
if ($this->getRequest()->isPost() && $form->isValid($this->getRequest()->getPost())) {
$postData = $form->getValues();
$postData['id'] = Post::fetchNextId();
$postData['userId'] = $currentUser['id'];
// save post
$post = new Post($postData['id']);
$post->setValue($postData);
$userPosts = new UserPosts($currentUser['id']);
$userPosts->add($postData['id']);
// save post in the follower feeds
$followers = new Followers($currentUser['id']);
foreach ($followers as $followerId) {
$feed = new Feed($followerId);
$feed->prepend($postData['id']);
}
$this->_redirect('/post/my');
}
$this->view->form = $form;
} | php | {
"resource": ""
} |
q257441 | PostController.indexAction | test | public function indexAction()
{
$currentUser = Zend_Auth::getInstance()->getStorage()->read();
$feed = new Feed($currentUser['id']);
$this->view->posts = array();
// just for example, better use multiget
foreach ($feed as $postId) {
$post = new Post($postId);
$postData = $post->getValue();
$user = new User($postData['userId']);
$userData = $user->getValue();
$this->view->posts[] = array('post' => $postData, 'user' => $userData);
}
} | php | {
"resource": ""
} |
q257442 | Rediska_Zend_Log_Writer_Redis.factory | test | static public function factory($config)
{
$config = self::_parseConfig($config);
if (!isset($config['keyName'])) {
throw new Zend_Log_Exception('keyName not present');
}
if (!isset($config['rediska'])) {
$config['rediska'] = Rediska::DEFAULT_NAME;
}
return new self($config['keyName'], $config['rediska']);
} | php | {
"resource": ""
} |
q257443 | Rediska_Key_SortedSet.add | test | public function add($value, $score)
{
$result = $this->_getRediskaOn()->addToSortedSet($this->getName(), $value, $score);
if (!is_null($this->getExpire()) && $result) {
$this->expire($this->getExpire(), $this->isExpireTimestamp());
}
return $result;
} | php | {
"resource": ""
} |
q257444 | Rediska_Key_SortedSet.getLengthByScore | test | public function getLengthByScore($min, $max)
{
return $this->_getRediskaOn()->getSortedSetLengthByScore($this->getName(), $min, $max);
} | php | {
"resource": ""
} |
q257445 | Rediska_Key_SortedSet.getByScore | test | public function getByScore($min, $max, $withScores = false, $limit = null, $offset = null, $revert = false)
{
return $this->_getRediskaOn()->getFromSortedSetByScore($this->getName(), $min, $max, $withScores, $limit, $offset, $revert);
} | php | {
"resource": ""
} |
q257446 | Rediska_Key_SortedSet.removeByScore | test | public function removeByScore($min, $max)
{
return $this->_getRediskaOn()->DeleteFromSortedSetByScore($this->getName(), $min, $max);
} | php | {
"resource": ""
} |
q257447 | Rediska_Key_SortedSet.incrementScore | test | public function incrementScore($value, $score)
{
return $this->_getRediskaOn()->incrementScoreInSortedSet($this->getName(), $value, $score);
} | php | {
"resource": ""
} |
q257448 | Rediska_Key_SortedSet.getByRank | test | public function getByRank($withScores = false, $start = 0, $end = -1, $revert = false, $responseIterator = false)
{
return $this->_getRediskaOn()->getSortedSet($this->getName(), $withScores, $start, $end, $revert, $responseIterator);
} | php | {
"resource": ""
} |
q257449 | Rediska_Key_SortedSet.removeByRank | test | public function removeByRank($start, $end)
{
return $this->_getRediskaOn()->deleteFromSortedSetByRank($this->getName(), $start, $end);
} | php | {
"resource": ""
} |
q257450 | Rediska_Key_SortedSet.getRank | test | public function getRank($value, $revert = false)
{
return $this->_getRediskaOn()->getRankFromSortedSet($this->getName(), $value, $revert);
} | php | {
"resource": ""
} |
q257451 | Rediska_Key_SortedSet.union | test | public function union($setOrSets, $storeKeyName, $aggregation = 'sum')
{
$sets = $this->_prepareSetsForComapre($setOrSets);
return $this->_getRediskaOn()->unionSortedSets($sets, $storeKeyName, $aggregation);
} | php | {
"resource": ""
} |
q257452 | Rediska_Key_SortedSet.intersect | test | public function intersect($setOrSets, $storeKeyName, $aggregation = 'sum')
{
$sets = $this->_prepareSetsForComapre($setOrSets);
return $this->_getRediskaOn()->intersectSortedSets($sets, $storeKeyName, $aggregation);
} | php | {
"resource": ""
} |
q257453 | Rediska_Key_SortedSet.toArray | test | public function toArray($withScores = false, $start = 0, $end = -1, $revert = false, $responseIterator = false)
{
return $this->getByRank($withScores, $start, $end, $revert, $responseIterator);
} | php | {
"resource": ""
} |
q257454 | Rediska_Key_SortedSet.fromArray | test | public function fromArray(array $array)
{
$pipeline = $this->_getRediskaOn()->pipeline();
foreach($array as $score => $value) {
$pipeline->addToSortedSet($this->getName(), $value, $score);
}
if (!is_null($this->getExpire())) {
$pipeline->expire($this->getName(), $this->getExpire(), $this->isExpireTimestamp());
}
$pipeline->execute();
return true;
} | php | {
"resource": ""
} |
q257455 | Rediska.setName | test | public function setName($name)
{
$this->_options['name'] = $name;
if ($this->_options['addToManager']) {
Rediska_Manager::add($this);
}
return $this;
} | php | {
"resource": ""
} |
q257456 | Rediska.getConnectionByKeyName | test | public function getConnectionByKeyName($name)
{
if ($this->_specifiedConnection->getConnection()) {
$connection = $this->_specifiedConnection->getConnection();
} elseif (count($this->_connections) == 1) {
$connections = array_values($this->_connections);
$connection = $connections[0];
} else {
$alias = $this->_keyDistributor->getConnectionByKeyName($name);
$connection = $this->_connections[$alias];
}
return $connection;
} | php | {
"resource": ""
} |
q257457 | Rediska.getConnections | test | public function getConnections()
{
if ($this->_specifiedConnection->getConnection()) {
return array($this->_specifiedConnection->getConnection());
} else {
return array_values($this->_connections);
}
} | php | {
"resource": ""
} |
q257458 | Rediska.on | test | public function on($aliasOrConnection)
{
if ($aliasOrConnection instanceof Rediska_Connection) {
$connection = $aliasOrConnection;
} else {
$alias = $aliasOrConnection;
$connection = $this->getConnectionByAlias($alias);
}
$this->_specifiedConnection->setConnection($connection);
return $this->_specifiedConnection;
} | php | {
"resource": ""
} |
q257459 | Rediska.subscribe | test | public function subscribe($channelOrChannels, $timeout = null)
{
return new Rediska_PubSub_Channel($channelOrChannels, array(
'rediska' => $this,
'timeout' => $timeout,
'serverAlias' => $this->_specifiedConnection->getConnection()
));
} | php | {
"resource": ""
} |
q257460 | Rediska.config | test | public function config($aliasOrConnection = null)
{
if ($aliasOrConnection instanceof Rediska_Connection) {
$connection = $aliasOrConnection;
} elseif ($aliasOrConnection !== null) {
$connection = $this->getConnectionByAlias($aliasOrConnection);
} elseif ($this->_specifiedConnection->getConnection()) {
$connection = $this->_specifiedConnection->getConnection();
} else {
$connections = $this->getConnections();
if (count($connections) == 1) {
$connection = $connections[0];
} else {
throw new Rediska_Transaction_Exception('You must specify connection by $aliasOrConnection argument!');
}
}
return new Rediska_Config($this, $connection);
} | php | {
"resource": ""
} |
q257461 | Rediska.setKeyDistributor | test | public function setKeyDistributor($name)
{
$this->_options['keyDistributor'] = $name;
if (is_object($name)) {
$this->_keyDistributor = $name;
} else if (in_array($name, array('crc32', 'consistentHashing'))) {
$name = ucfirst($name);
$className = "Rediska_KeyDistributor_$name";
$this->_keyDistributor = new $className;
} else {
if (!@class_exists($name)) {
throw new Rediska_Exception("Key distributor '$name' not found. You need include it before or setup autoload.");
}
$this->_keyDistributor = new $name;
}
if (!$this->_keyDistributor instanceof Rediska_KeyDistributor_Interface) {
throw new Rediska_Exception("'$name' must implement Rediska_KeyDistributor_Interface");
}
// Add available connections
foreach($this->_connections as $connectionString => $connection) {
$this->_keyDistributor->addConnection($connectionString);
}
return $this;
} | php | {
"resource": ""
} |
q257462 | Rediska.getSerializer | test | public function getSerializer()
{
if ($this->_serializer === null) {
$this->_serializer = new Rediska_Serializer($this->_options['serializerAdapter']);
}
return $this->_serializer;
} | php | {
"resource": ""
} |
q257463 | Rediska_Commands.get | test | public static function get(Rediska $rediska, $name, $arguments)
{
$lowerName = self::_getCommandLowerNameAndThrowIfNotPresent($name);
return new self::$_commands[$lowerName]($rediska, $name, $arguments);
} | php | {
"resource": ""
} |
q257464 | Rediska_Commands._getCommandLowerNameAndThrowIfNotPresent | test | protected static function _getCommandLowerNameAndThrowIfNotPresent($name)
{
$lowerName = strtolower($name);
if (!isset(self::$_commands[$lowerName])) {
throw new Rediska_Exception("Command '$name' not found");
}
return $lowerName;
} | php | {
"resource": ""
} |
q257465 | Rediska_Pipeline.execute | test | public function execute()
{
$results = array();
if (!empty($this->_commands)) {
$this->_rediska->getProfiler()->start($this);
foreach($this->_commands as $command) {
$command->write();
}
foreach($this->_commands as $command) {
$results[] = $command->read();
}
$this->_rediska->getProfiler()->stop();
}
return $results;
} | php | {
"resource": ""
} |
q257466 | Rediska_Pipeline._addCommand | test | protected function _addCommand($name, $args = array())
{
if ($this->_oneTimeConnection) {
$connection = $this->_oneTimeConnection;
$this->_oneTimeConnection = null;
} else {
$connection = $this->_defaultConnection;
}
if ($connection !== null) {
$this->_specifiedConnection->setConnection($connection);
} else {
$this->_specifiedConnection->resetConnection();
}
$command = Rediska_Commands::get($this->_rediska, $name, $args);
$command->initialize();
if (!$command->isAtomic()) {
throw new Rediska_Exception("Command '$name' doesn't work properly (not atomic) in pipeline on multiple servers");
}
$this->_commands[] = $command;
$this->_specifiedConnection->resetConnection();
return $this;
} | php | {
"resource": ""
} |
q257467 | Rediska_Connection_Exec.write | test | public function write()
{
$result = $this->getConnection()->write($this->getCommand());
$this->_isWritten = true;
return $result;
} | php | {
"resource": ""
} |
q257468 | Rediska_Connection_Exec.setResponseCallback | test | public function setResponseCallback($callback)
{
if ($callback !== null && !is_callable($callback)) {
throw new Rediska_Connection_Exec_Exception('Bad callback');
}
$this->_responseCallback = $callback;
return $this;
} | php | {
"resource": ""
} |
q257469 | Rediska_Connection_Exec.transformMultiBulkCommand | test | public static function transformMultiBulkCommand(array $command)
{
$commandString = self::REPLY_MULTY_BULK . count($command) . Rediska::EOL;
foreach($command as $argument) {
$commandString .= self::REPLY_BULK . strlen($argument) . Rediska::EOL . $argument . Rediska::EOL;
}
return $commandString;
} | php | {
"resource": ""
} |
q257470 | Rediska_Key_List.append | test | public function append($value, $createIfNotExists = true)
{
$result = $this->_getRediskaOn()->appendToList($this->getName(), $value, $createIfNotExists);
if (!is_null($this->getExpire()) && $result) {
$this->expire($this->getExpire(), $this->isExpireTimestamp());
}
return $result;
} | php | {
"resource": ""
} |
q257471 | Rediska_Key_List.prepend | test | public function prepend($value, $createIfNotExists = true)
{
$result = $this->_getRediskaOn()->prependToList($this->getName(), $value, $createIfNotExists);
if (!is_null($this->getExpire()) && $result) {
$this->expire($this->getExpire(), $this->isExpireTimestamp());
}
return $result;
} | php | {
"resource": ""
} |
q257472 | Rediska_Key_List.truncate | test | public function truncate($start, $end)
{
$result = $this->_getRediskaOn()->truncateList($this->getName(), $start, $end);
if (!is_null($this->getExpire()) && $result) {
$this->expire($this->getExpire(), $this->isExpireTimestamp());
}
return $result;
} | php | {
"resource": ""
} |
q257473 | Rediska_Key_List.set | test | public function set($index, $value)
{
$result = $this->_getRediskaOn()->setToList($this->getName(), $index, $value);
if (!is_null($this->getExpire()) && $result) {
$this->expire($this->getExpire(), $this->isExpireTimestamp());
}
return $result;
} | php | {
"resource": ""
} |
q257474 | Rediska_Key_List.insertAfter | test | public function insertAfter($referenceValue, $value)
{
return $this->_getRediskaOn()->insertToListAfter($this->getName(), $referenceValue, $value);
} | php | {
"resource": ""
} |
q257475 | Rediska_Key_List.insertBefore | test | public function insertBefore($referenceValue, $value)
{
return $this->_getRediskaOn()->insertToListBefore($this->getName(), $referenceValue, $value);
} | php | {
"resource": ""
} |
q257476 | Rediska_Key_List.insert | test | public function insert($position, $referenceValue, $value)
{
return $this->_getRediskaOn()->insertToList($this->getName(), $position, $referenceValue, $value);
} | php | {
"resource": ""
} |
q257477 | Rediska_Key_List.remove | test | public function remove($value, $count = 0)
{
$result = $this->_getRediskaOn()->deleteFromList($this->getName(), $value, $count);
if (!is_null($this->getExpire()) && $result) {
$this->expire($this->getExpire(), $this->isExpireTimestamp());
}
return $result;
} | php | {
"resource": ""
} |
q257478 | Rediska_Key_List.shift | test | public function shift()
{
$result = $this->_getRediskaOn()->shiftFromList($this->getName());
if (!is_null($this->getExpire()) && $result) {
$this->expire($this->getExpire(), $this->isExpireTimestamp());
}
return $result;
} | php | {
"resource": ""
} |
q257479 | Rediska_Key_List.shiftBlocking | test | public function shiftBlocking($timeout = 0)
{
$result = $this->_getRediskaOn()->shiftFromListBlocking($this->getName(), $timeout);
if (!is_null($this->getExpire()) && $result) {
$this->expire($this->getExpire(), $this->isExpireTimestamp());
}
return $result;
} | php | {
"resource": ""
} |
q257480 | Rediska_Key_List.pop | test | public function pop($pushTo = null)
{
if ($pushTo instanceof Rediska_Key_List) {
$pushTo = $pushTo->getName();
}
$result = $this->_getRediskaOn()->popFromList($this->getName(), $pushTo);
if (!is_null($this->getExpire()) && $result) {
$this->expire($this->getExpire(), $this->isExpireTimestamp());
}
return $result;
} | php | {
"resource": ""
} |
q257481 | Rediska_Key_List.popBlocking | test | public function popBlocking($timeout = 0, $pushToKey = null)
{
$result = $this->_getRediskaOn()->popFromListBlocking($this->getName(), $timeout, $pushToKey);
if (!is_null($this->getExpire()) && $result) {
$this->expire($this->getExpire(), $this->isExpireTimestamp());
}
return $result;
} | php | {
"resource": ""
} |
q257482 | Rediska_Key_List.fromArray | test | public function fromArray(array $array)
{
$pipeline = $this->_getRediskaOn()->pipeline();
foreach($array as $item) {
$pipeline->appendToList($this->getName(), $item);
}
if (!is_null($this->getExpire())) {
$pipeline->expire($this->getName(), $this->getExpire(), $this->isExpireTimestamp());
}
$pipeline->execute();
return true;
} | php | {
"resource": ""
} |
q257483 | Rediska_Zend_Cache_Backend_Redis.load | test | public function load($id, $doNotTestCacheValidity = false)
{
$id = (array) $id;
foreach ($id as $key){
$key = $this->_options['storage']['prefix_key'] . $key;
$this->_getTransactionByKey($key)
->getFromHash(
$key,
self::FIELD_DATA
);
}
$oldSerializaerAdapter = $this->getRediska()->getSerializer()->getAdapter();
$this->getRediska()->setSerializerAdapter('toString');
$result = $this->_execTransactions();
$this->getRediska()->getSerializer()->setAdapter($oldSerializaerAdapter);
if(count($result) == 1){
if(null === ($result = array_shift($result))){
return false;
} else {
return $result;
}
} else {
return $result;
}
} | php | {
"resource": ""
} |
q257484 | Rediska_Zend_Cache_Backend_Redis.save | test | public function save($data, $id, $tags = array(), $specificLifetime = false)
{
if(!is_array($tags)) $tags = array($tags);
$lifetime = $this->getLifetime($specificLifetime);
$oldTags = explode(
',', $this->getRediska()->getFromHash(
$this->_options['storage']['prefix_key'].$id, self::FIELD_TAGS
)
);
$this->_getTransactionByKey($this->_options['storage']['prefix_key'].$id)
->setToHash(
$this->_options['storage']['prefix_key'].$id, array(
self::FIELD_DATA => $data,
self::FIELD_TAGS => implode(',',$tags),
self::FIELD_MTIME => time(),
self::FIELD_INF => $lifetime ? 0 : 1)
);
$this->_getTransactionByKey($this->_options['storage']['prefix_key'].$id)
->expire($this->_options['storage']['prefix_key'].$id, $lifetime ? $lifetime : self::MAX_LIFETIME);
if ($addTags = ($oldTags ? array_diff($tags, $oldTags) : $tags)) {
foreach ($addTags as $add) {
$this->_getTransactionByKey($this->_options['storage']['set_tags'])
->addToSet($this->_options['storage']['set_tags'], $add);
}
foreach($addTags as $tag){
$this->_getTransactionByKey($this->_options['storage']['prefix_tag_ids'] . $tag)
->addToSet($this->_options['storage']['prefix_tag_ids'] . $tag, $id);
}
}
if ($remTags = ($oldTags ? array_diff($oldTags, $tags) : false)){
foreach($remTags as $tag){
$this->_getTransactionByKey($this->_options['storage']['prefix_tag_ids'] . $tag)
->deleteFromSet($this->_options['storage']['prefix_tag_ids'] . $tag, $id);
}
}
$this->_getTransactionByKey($this->_options['storage']['set_ids'])
->addToSet($this->_options['storage']['set_ids'], $id);
try {
$this->_execTransactions();
return true;
} catch(Rediska_Transaction_Exception $e){
$this->_log($e->getMessage(), Zend_Log::ERR);
return false;
}
} | php | {
"resource": ""
} |
q257485 | Rediska_Zend_Cache_Backend_Redis.remove | test | public function remove($id)
{
$tags = explode(
',', $this->getRediska()->getFromHash(
$this->_options['storage']['prefix_key'].$id, self::FIELD_TAGS
)
);
$this->_getTransactionByKey($this->_options['storage']['prefix_key'].$id)
->delete($this->_options['storage']['prefix_key'].$id);
$this->_getTransactionByKey($this->_options['storage']['set_ids'], $id)
->deleteFromSet( $this->_options['storage']['set_ids'], $id );
foreach($tags as $tag) {
$this->_getTransactionByKey($this->_options['storage']['prefix_tag_ids'] . $tag)
->deleteFromSet($this->_options['storage']['prefix_tag_ids'] . $tag, $id);
}
$result = $this->_execTransactions();
if(count($result)){
return array_shift($result);
} else {
return false;
}
} | php | {
"resource": ""
} |
q257486 | Rediska_Zend_Cache_Backend_Redis.clean | test | public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
{
if( $tags && ! is_array($tags)) {
$tags = array($tags);
}
$result = true;
switch ($mode) {
case Zend_Cache::CLEANING_MODE_ALL:
$this->_removeIds($this->getIds());
break;
case Zend_Cache::CLEANING_MODE_OLD:
break;
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
$this->_removeIdsByMatchingTags($tags);
break;
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
$this->_removeIdsByNotMatchingTags($tags);
break;
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
$this->_removeIdsByMatchingAnyTags($tags);
break;
default:
Zend_Cache::throwException('Invalid mode for clean() method: '.$mode);
}
return $this->_collectGarbage();
} | php | {
"resource": ""
} |
q257487 | Rediska_Zend_Cache_Backend_Redis.setDirectives | test | public function setDirectives($directives)
{
parent::setDirectives($directives);
$lifetime = $this->getLifetime(false);
if ($lifetime > self::MAX_LIFETIME) {
$this->_log(
'redis backend has a limit of 30 days (' . self::MAX_LIFETIME
. ' seconds) for the lifetime'
);
}
} | php | {
"resource": ""
} |
q257488 | Rediska_Zend_Cache_Backend_Redis.getIdsNotMatchingTags | test | public function getIdsNotMatchingTags($tags = array())
{
$sets = $this->_preprocessTagIds($tags);
array_unshift($sets, $this->_options['storage']['set_ids']);
$data = $this->getRediska()->diffSets($sets);
return $data;
} | php | {
"resource": ""
} |
q257489 | Rediska_Zend_Cache_Backend_Redis.getMetadatas | test | public function getMetadatas($id)
{
$metaData = $this->getRediska()->getFromHash(
$this->_options['storage']['prefix_key'].$id,
array(self::FIELD_DATA, self::FIELD_TAGS, self::FIELD_MTIME, self::FIELD_INF)
);
if(!$metaData[self::FIELD_MTIME]) {
return false;
}
$lifetime = $this->getRediska()
->getLifetime($this->_options['storage']['prefix_key'] . $id);
$tags = explode(',', $metaData[self::FIELD_TAGS]);
$expire = $metaData[self::FIELD_INF] === '1' ? false : time() + $lifetime;
return array(
'expire' => $expire,
'tags' => $tags,
'mtime' => $metaData[self::FIELD_MTIME],
);
} | php | {
"resource": ""
} |
q257490 | Rediska_Zend_Cache_Backend_Redis._collectGarbage | test | protected function _collectGarbage()
{
$exists = array();
$tags = $this->getTags();
foreach($tags as $tag){
$prefix_tag_ids = $this->_options['storage']['prefix_tag_ids'] . $tag;
$tagMembers = $this->getRediska()->getSet($prefix_tag_ids);
$this->_getTransactionByKey($prefix_tag_ids)->watch($prefix_tag_ids);
$expired = array();
if(count($tagMembers)) {
foreach($tagMembers as $id) {
if( ! isset($exists[$id])) {
$exists[$id] = $this->getRediska()
->exists($this->_options['storage']['prefix_key'].$id);
}
if(!$exists[$id]) {
$expired[] = $id;
}
}
if(!count($expired)) continue;
}
if(!count($tagMembers) || count($expired) == count($tagMembers)) {
$this->_getTransactionByKey($this->_options['storage']['set_tags'])
->deleteFromSet($this->_options['storage']['set_tags'], $tag);
$this->_getTransactionByKey($this->_options['storage']['prefix_tag_ids'] . $tag)
->delete($this->_options['storage']['prefix_tag_ids'] . $tag);
} else {
$this->_getTransactionByKey($this->_options['storage']['prefix_tag_ids'] . $tag)
->deleteFromSet( $this->_options['storage']['prefix_tag_ids'] . $tag, $expired);
}
$this->_getTransactionByKey($this->_options['storage']['set_ids'])
->deleteFromSet( $this->_options['storage']['set_ids'], $expired);
}
try{
return (bool) $this->_execTransactions();
} catch (Rediska_Transaction_AbortedException $e ){
$this->_log($e->getMessage(), Zend_Log::ERR);
return false;
}
} | php | {
"resource": ""
} |
q257491 | Rediska_Key_Set.add | test | public function add($value)
{
$result = $this->_getRediskaOn()->addToSet($this->getName(), $value);
if (!is_null($this->getExpire()) && $result) {
$this->expire($this->getExpire(), $this->isExpireTimestamp());
}
return $result;
} | php | {
"resource": ""
} |
q257492 | Rediska_Key_Set.remove | test | public function remove($value)
{
$result = $this->_getRediskaOn()->deleteFromSet($this->getName(), $value);
if (!is_null($this->getExpire()) && $result) {
$this->expire($this->getExpire(), $this->isExpireTimestamp());
}
return $result;
} | php | {
"resource": ""
} |
q257493 | Rediska_Key_Set.move | test | public function move($set, $value)
{
if ($set instanceof Rediska_Key_Set) {
$set = $set->getName();
}
return $this->_getRediskaOn()->moveToSet($this->getName(), $set, $value);
} | php | {
"resource": ""
} |
q257494 | Rediska_Key_Set.intersect | test | public function intersect($setOrSets, $storeKeyName = null)
{
$sets = $this->_prepareSetsForCompare($setOrSets);
return $this->_getRediskaOn()->intersectSets($sets, $storeKeyName);
} | php | {
"resource": ""
} |
q257495 | Rediska_Key_Set.union | test | public function union($setOrSets, $storeKeyName = null)
{
$sets = $this->_prepareSetsForCompare($setOrSets);
return $this->_getRediskaOn()->unionSets($sets, $storeKeyName);
} | php | {
"resource": ""
} |
q257496 | Rediska_Key_Set.diff | test | public function diff($setOrSets, $storeKeyName = null)
{
$sets = $this->_prepareSetsForCompare($setOrSets);
return $this->_getRediskaOn()->diffSets($sets, $storeKeyName);
} | php | {
"resource": ""
} |
q257497 | Rediska_Options_RediskaInstance.getRediska | test | public function getRediska()
{
if (!is_object($this->_rediska)) {
$this->_rediska = self::getRediskaInstance($this->_rediska, $this->_optionsException, $this->_rediskaOptionName);
}
return $this->_rediska;
} | php | {
"resource": ""
} |
q257498 | Rediska_Key.setValue | test | public function setValue($value)
{
if ($this->getExpire() !== null && !$this->isExpireTimestamp()) {
$reply = $this->setAndExpire($value, $this->getExpire());
} else {
$reply = $this->_getRediskaOn()->set($this->getName(), $value);
if ($reply && !is_null($this->getExpire())) {
$this->expire($this->getExpire(), $this->isExpireTimestamp());
}
}
return $reply;
} | php | {
"resource": ""
} |
q257499 | Rediska_Key.setAndExpire | test | public function setAndExpire($value, $seconds)
{
return $this->_getRediskaOn()->setAndExpire($this->getName(), $value, $seconds);
} | php | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.