本文整理汇总了PHP中Predis\Client::lpush方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::lpush方法的具体用法?PHP Client::lpush怎么用?PHP Client::lpush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Predis\Client
的用法示例。
在下文中一共展示了Client::lpush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: returnMessage
public function returnMessage(QueueMessage $message)
{
// re-add the message to the queue, as the first element
$this->predis->lpush($message->getQueueId(), $message->getMessage());
// forget we received the message
$this->completeMessage($message);
}
示例2: addMessage
/**
* @param Message $message
*/
public function addMessage(Message $message)
{
/**
* @todo
* add message to channel
*/
$this->client->lpush($this->getName(), $message->getAsString());
}
示例3: submit
/**
* Publish a message to the queue
*
* @param \Flowpack\JobQueue\Common\Queue\Message $message
* @return void
*/
public function submit(\Flowpack\JobQueue\Common\Queue\Message $message)
{
if ($message->getIdentifier() !== NULL) {
$added = $this->client->sadd("queue:{$this->name}:ids", $message->getIdentifier());
if (!$added) {
return;
}
}
$encodedMessage = $this->encodeMessage($message);
$this->client->lpush("queue:{$this->name}:messages", $encodedMessage);
$message->setState(\Flowpack\JobQueue\Common\Queue\Message::STATE_SUBMITTED);
}
示例4: handle
/**
* @param EventInterface $event
*/
public function handle(EventInterface $event)
{
$this->redis->lpush(self::BUFFER_LIST_KEY, json_encode($event->toArray()));
if ($this->redis->exists(self::BUFFER_TIMER_KEY)) {
$this->redis->pexpire(self::BUFFER_TIMER_KEY, self::BUFFER_TIMEOUT_MILLISECONDS);
} else {
$this->redis->psetex(self::BUFFER_TIMER_KEY, self::BUFFER_TIMEOUT_MILLISECONDS, '1');
while ($this->redis->exists(self::BUFFER_TIMER_KEY)) {
usleep(self::BUFFER_SLEEP_MILLISECONDS);
}
$this->handleBufferedEvents();
}
}
示例5: tweet
/**
* @param string $status
*/
public function tweet($status)
{
$postId = $this->redisClient->incr("global:nextPostId");
$userId = $this->session->get('userId');
$post = $userId . "|" . (new \DateTime())->format('d/m/y') . "|" . $status;
$this->redisClient->set("post:{$postId}", $post);
$followers = $this->redisClient->smembers("uid:" . $userId . ":followers");
if ($followers === false) {
$followers = [];
}
$followers[] = $userId;
foreach ($followers as $fid) {
$this->redisClient->lpush("uid:{$fid}:posts", [$postId]);
}
$this->redisClient->lpush("global:timeline", [$postId]);
$this->redisClient->ltrim("global:timeline", 0, 1000);
}
示例6: storeAssociation
/**
* Store association until its expiration time in Redis server.
* Overwrites any existing association with same server_url and
* handle. Handles list of associations for every server.
*/
function storeAssociation($server_url, $association)
{
// create Redis keys for association itself
// and list of associations for this server
$associationKey = $this->associationKey($server_url, $association->handle);
$serverKey = $this->associationServerKey($server_url);
// save association to server's associations' keys list
$this->redis->lpush($serverKey, $associationKey);
// Will touch the association list expiration, to avoid filling up
$newExpiration = $association->issued + $association->lifetime;
$expirationKey = $serverKey . '_expires_at';
$expiration = $this->redis->get($expirationKey);
if (!$expiration || $newExpiration > $expiration) {
$this->redis->set($expirationKey, $newExpiration);
$this->redis->expireat($serverKey, $newExpiration);
$this->redis->expireat($expirationKey, $newExpiration);
}
// save association itself, will automatically expire
$this->redis->setex($associationKey, $newExpiration - time(), serialize($association));
}
示例7: atomicPush
/**
* Push job to redis
*
* @param string $jobId
* @param string $class
* @param array $args
* @param string $queue
* @param bool $retry
* @param float|null $doAt
* @throws exception Exception
*/
private function atomicPush($jobId, $class, $args = [], $queue = self::QUEUE, $retry = true, $doAt = null)
{
if (array_values($args) !== $args) {
throw new Exception('Associative arrays in job args are not allowed');
}
if (!is_null($doAt) && !is_float($doAt) && is_string($doAt)) {
throw new Exception('at argument needs to be in a unix epoch format. Use microtime(true).');
}
$job = $this->serializer->serialize($jobId, $class, $args, $retry);
if ($doAt === null) {
$this->redis->sadd($this->name('queues'), $queue);
$this->redis->lpush($this->name('queue', $queue), $job);
} else {
$this->redis->zadd($this->name('schedule'), [$job => $doAt]);
}
}
示例8: Job_Lookup_Word
public function Job_Lookup_Word()
{
$word = $this->job_details->word;
$this->status = 'working';
$this->Report();
try {
$url = 'http://www.dictionaryapi.com/api/v1/references/collegiate/xml/' . urlencode($word) . '?key=' . DICTIONARY_API_KEY;
$contents = @file_get_contents($url);
/*
* I really don't know how to manipulate very complex XML easily in PHP,
* so please ignore the hideous hacks that you are about to see.
*/
$xml = new SimpleXMLElement($contents);
$results = $xml->xpath('/entry_list/entry[1]//dt');
$return = '';
foreach ($results as $node) {
/* @var $node SimpleXMLElement */
$string = $node->asXML();
// Please ignore the developer behind the curtain
$string = str_replace('<dt>:', '', $string);
$string = str_replace(':</dt>', '', $string);
$def = trim(strip_tags($string));
// Return the longest definition
if (strlen($def) > strlen($return)) {
$return = $def;
}
}
} catch (Exception $ex) {
$def = "{$word} failed: " . $ex->getMessage();
}
// Okay, you can start paying attention again now.
$json = json_encode(array('word' => $word, 'def' => $def));
$this->last_word = $word;
$this->last_def = $def;
echo "\n {$word}: {$return} \n";
$this->redis->lpush('word.defs', $json);
$this->redis->ltrim('word.defs', 0, 20);
$this->beanstalk->delete($this->job);
// Wait 2 seconds so we don't overload the API
usleep(2000000);
}
示例9: lpushUnorderedList
/**
* Utility method to to an LPUSH of some unordered values on a key.
*
* @param Client $redis Redis client instance.
* @param string $key Target key
*
* @return array
*/
protected function lpushUnorderedList(Client $redis, $key)
{
$list = array(2, 100, 3, 1, 30, 10);
$redis->lpush($key, $list);
return $list;
}
示例10: putFirst
/**
* @param $queueName
* @param $workload
*/
public function putFirst($queueName, $workload)
{
$this->predis->lpush($queueName, serialize($workload));
}
示例11: listSave
private function listSave()
{
return $this->client->lpush($this->key_header, array($this->message->getJsonFormat()));
}
示例12: put
public function put($job)
{
$job['id'] = $this->redis->incr("job_id");
$this->redis->lpush("jobs", serialize($job));
return $job['id'];
}
示例13: count
$winners = $app['random']->getRandomNumbers(0, count($checkins) - 1);
return $app['twig']->render('event.html.twig', array('event' => $event, 'winners' => $winners, 'checkins' => $checkins));
})->bind('event');
// Check-in page for Event
$app->get('/event/{id}/checkin', function ($id, Request $request) use($app) {
$event = $app['meetup']->getEvent($id);
$client = new Client();
$checkins = array_filter($client->lrange('checkin_' . $id, 0, 300));
return $app['twig']->render('event_checkin.html.twig', array('event' => $event, 'checkins' => $checkins));
})->bind('event_checkin');
// Checks a user into an event
$app->post('/user/checkin', function (Request $request) use($app) {
$userId = $request->get('user_id');
$eventId = $request->get('event_id');
$client = new Client();
$client->lpush('checkin_' . $eventId, $userId);
return new Response(json_encode(array('result' => 'ok')), 200, array('Content-Type' => 'application/json'));
})->bind('user_checkin');
// Error page
$app->error(function (\Exception $e, $code) use($app) {
if ($app['debug']) {
return;
}
$page = 404 == $code ? '404.html' : '500.html';
return new Response($app['twig']->render($page, array('code' => $code)), $code);
});
// Oauth Handshake
$app->get('/oauth/authorize', function (Request $request) use($app) {
/** @var MeetupOauthHandler $oauthHandler */
$oauthHandler = $app['meetup_oauth_handler'];
$oauthHandler->clearSessionToken();
示例14: Client
<?php
$loader = (require __DIR__ . '/../vendor/autoload.php');
$loader->add('Activity', __DIR__);
use Predis\Client;
use TylerKing\Activity\Broadcast;
use TylerKing\Activity\Feed;
use Activity\Status;
use Activity\PhotoLike;
$redis = new Client();
// Setup some friends and the current user (you can use a database for this).
$redis->del('uid:1:friends');
$redis->del('feed:2');
$redis->lpush('uid:1:friends', 2);
$redis->lpush('uid:1:friends', 3);
$friends = $redis->lrange('uid:1:friends', 0, -1);
// Make a status.
$status = new Status($redis);
$status->setCreator(1);
$status->setStatus('Hey, I just joined this site!');
// Broadcast status to user's friends...
$broadcast = new Broadcast($redis);
$broadcast->setActivity($status);
$broadcast->setTo($friends);
$broadcast->flush();
// Make a photo like.
$like = new PhotoLike($redis);
$like->setCreator(1);
$like->setPhotoId(5);
$like->setPhoto('http://i.imgur.com/pcS7V.jpg');
// Broadcast photo like to user's friends...
示例15: lpush
public function lpush($key, $value)
{
return $this->client->lpush($key, $value);
}