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


PHP Redis::publish方法代码示例

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


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

示例1: onCall

 public function onCall(CallbackEvent $event)
 {
     $callEvent = $event->getCallEvent();
     /** @var Call $call */
     $call = $callEvent->getCall();
     $account = $call->getAccount();
     if ($call->getDirection() != CallInterface::DIRECTION_INCOMING) {
         return;
     }
     $converter = new ObjectScalarConverter();
     if ($callEvent instanceof CallEventInterface) {
         if (!$call->getClient() instanceof ClientInterface) {
             return;
         }
         $client = $call->getClient();
         $managerIds = [];
         if ($call->getCalledUsers()->count()) {
             $managerIds = $converter->reverseConvertCollection($call->getCalledUsers());
         }
         $company = null;
         if ($client->getCompany() instanceof CompanyInterface) {
             $company = $client->getCompany()->getName();
         }
         $message = ['managerIds' => $managerIds, 'event' => 'incoming-call', 'data' => ['clientId' => $client->getId(), 'name' => $client->getFirstName() . ' ' . $client->getLastName(), 'company' => $company, 'position' => $client->getPosition()]];
         $this->redis->publish('events.' . $account->getDomain(), json_encode($message));
     }
 }
开发者ID:Exanrus,项目名称:crm-bundle,代码行数:27,代码来源:CallSubscriber.php

示例2: logXenonData

/**
 * Collate Xenon traces and publish to Redis.
 *
 * To use ArcLamp, pass this function as the callback parameter to
 * register_shutdown_function:
 *
 * <code>
 * require_once('ArcLamp.php');
 * register_shutdown_function('ArcLamp\logXenonData', ['localhost', 6379]);
 * </code>
 *
 * @param Redis|array|string $redis A Redis instance, a Redis server name,
 *   or an array of arguments for Redis::connect.
 */
function logXenonData($redis = 'localhost')
{
    if (!extension_loaded('xenon')) {
        return;
    }
    $data = \HH\xenon_get_data();
    if (!is_array($data) || !count($data)) {
        return;
    }
    if ($redis instanceof \Redis) {
        $conn = $redis;
    } else {
        $conn = new \Redis();
        call_user_func_array(array($conn, 'connect'), (array) $redis);
    }
    if (!$conn) {
        return;
    }
    foreach (combineSamples($data) as $stack => $count) {
        $conn->publish('xenon', "{$stack} {$count}");
    }
}
开发者ID:wikimedia,项目名称:arc-lamp,代码行数:36,代码来源:ArcLamp.php

示例3: importAction

 /**
  * Start Import Product Queue action.
  *
  * @return void
  */
 public function importAction($param1 = null, $param2 = null)
 {
     $redis = new \Redis();
     $redis->connect('127.0.0.1', 6379);
     $queue = $this->getDI()->get('queue');
     $queue->watch('haraapp.import');
     $config = $this->getDI()->get('config');
     $filefive = $this->getDI()->get('filefive');
     while ($job = $queue->reserve()) {
         $message = $job->getBody();
         $data = $message[0];
         // Get offline product data from mysql db
         $myProductQueue = ProductQueue::findFirst(['pid = :haravanProductId: AND status = :status: AND sid = :storeId:', 'bind' => ['haravanProductId' => $data['haravanProductId'], 'status' => ProductQueue::STATUS_QUEUE, 'storeId' => $data['storeId']]]);
         if ($myProductQueue) {
             $pass = false;
             $myStore = Store::findFirstById($data['storeId']);
             // get content, image and import to five.vn db
             $product = json_decode($myProductQueue->pdata);
             $cleanData = strip_tags($product->body_html);
             // insert table ADS
             $myAds = new Ads();
             $myAds->assign(['uid' => $myStore->uid, 'udid' => "", 'rid' => $product->id, 'cid' => $myProductQueue->fcid, 'title' => $product->title, 'slug' => Utils::slug($product->title), 'description' => $cleanData, 'price' => $product->variants[0]->price, 'instock' => 1, 'cityid' => 0, 'districtid' => 0, 'status' => 1, 'isdeleted' => 0, 'seokeyword' => $product->tags, 'lastpostdate' => time()]);
             if ($myAds->create()) {
                 $pass = true;
                 if (isset($product->images)) {
                     // Insert table IMAGES
                     foreach ($product->images as $img) {
                         $response = \Requests::get($img->src);
                         if ($response->status_code == 200) {
                             // Download image to local
                             $filePart = explode('.', $img->filename);
                             $namePart = $filePart[0];
                             $extPart = $filePart[1];
                             $path = rtrim($config->global->product->directory, '/\\') . '/' . date('Y') . '/' . date('m') . DIRECTORY_SEPARATOR;
                             $fullPath = $config->global->staticFive . $path;
                             $uploadOK = $filefive->put($path . $namePart . '.' . $extPart, (string) $response->body);
                             // Resise image
                             $myResize = new PhImage($fullPath . $namePart . '.' . $extPart);
                             $orig_width = $myResize->getWidth();
                             $orig_height = $myResize->getHeight();
                             $height = $orig_height * 1200 / $orig_width;
                             $mediumHeight = $orig_height * 600 / $orig_width;
                             $smallHeight = $orig_height * 200 / $orig_width;
                             $myResize->resize(1200, $height)->crop(1200, $height)->save($fullPath . $namePart . '.' . $extPart);
                             $myResize->resize(600, $mediumHeight)->crop(600, $mediumHeight)->save($fullPath . $namePart . '-medium' . '.' . $extPart);
                             $myResize->resize(200, $smallHeight)->crop(200, $smallHeight)->save($fullPath . $namePart . '-small' . '.' . $extPart);
                             if ($uploadOK) {
                                 // Save to db
                                 $myImage = new Images();
                                 $myImage->assign(['aid' => $myAds->id, 'name' => $myAds->title, 'path' => $path . $namePart . '.' . $extPart, 'status' => Images::STATUS_ENABLE, 'orderNo' => $img->position]);
                                 if ($myImage->save()) {
                                     // Update first image to ads table
                                     if ($img->position == 1) {
                                         $myAds->image = $path . $namePart . '.' . $extPart;
                                         $myAds->update();
                                     }
                                 } else {
                                     echo "cannot save image!";
                                 }
                             } else {
                                 echo "cannot download image!";
                             }
                         } else {
                             echo "cannot get image url!";
                         }
                     }
                 }
                 $imageName = strlen($myAds->image) > 0 ? $myAds->image : "";
                 // Save to product_map table
                 $myProduct = new ProductMap();
                 $myProduct->assign(['sid' => $myStore->id, 'uid' => $myStore->uid, 'hid' => $data['haravanProductId'], 'aid' => $myAds->id, 'cid' => $myAds->cid, 'title' => $myAds->title, 'price' => $myAds->price, 'image' => $imageName, 'slug' => $myAds->slug, 'status' => $myAds->status]);
                 $myProduct->create();
                 // Delete queued data. (Production)
                 // $myProductQueue->delete();
             } else {
                 $pass = false;
             }
             if ($pass) {
                 $myProductLog = new ProductLog();
                 $myProductLog->assign(['sid' => $myStore->id, 'message' => 'Ads name ' . $myAds->title . ' has been created!', 'type' => ProductLog::TYPE_IMPORT, 'status' => ProductLog::STATUS_COMPLETED, 'class' => 'succcess']);
                 $myProductLog->create();
                 // update okie
                 $myCategoryMap = CategoryMap::findFirst(['hid = :haravanId: AND fid = :fid: AND sid = :storeId:', 'bind' => ['haravanId' => $data['haravanId'], 'fid' => $myProductQueue->fcid, 'storeId' => $data['storeId']]]);
                 $myCategoryMap->totalItemSync++;
                 $myCategoryMap->totalItemQueue--;
                 $myCategoryMap->update();
                 // generate total process, when import a product success
                 $totalItem = CategoryMap::sum(['column' => 'totalItem', 'conditions' => 'hid = ' . $data['haravanId'] . ' AND sid = ' . $data['storeId']]);
                 $totalItemSync = CategoryMap::sum(['column' => 'totalItemSync', 'conditions' => 'hid = ' . $data['haravanId'] . ' AND sid = ' . $data['storeId']]);
                 $process = $totalItemSync * 100 / $totalItem;
                 // Push process
                 $meta = ['shopName' => $myStore->name, 'record' => $process];
                 $redis->publish('notification', json_encode($meta));
                 // send message.
                 // When process all products in category map, update store mapped to OK
//.........这里部分代码省略.........
开发者ID:nguyenducduy,项目名称:haraapp,代码行数:101,代码来源:Worker.php

示例4: Redis

 * A simple PHP script to allow speech recongition of color selections.
 * Publishes selections on a Tropo channel through a persistent socket connection.
 * 
 */
// Redis settings
define("REDIS_HOST", "bass.redistogo.com");
define("REDIS_PORT", 9219);
define("REDIS_PASS", "1604d5037f6fd79b71f158019a1eff04");
$redis = new Redis(REDIS_HOST, REDIS_PORT);
$redis->connect();
$redis->auth(REDIS_PASS);
say("Welcome to the Redis and socket I O test.");
do {
    $result = ask("Say the color you want to see. When done, say stop.", array("choices" => "white, blue, green, yellow, stop"));
    _log("*** User selected: " . $result->value . " ***");
    $response = $redis->publish("tropo.color", $result->value);
} while ($result->value != 'stop');
$redis->disconnect();
say("Goodbye.");
hangup();
class Redis
{
    // Private class members.
    private $server;
    private $port;
    private $sock;
    private $auth;
    function __construct($host = 'localhost', $port = 6379)
    {
        $this->host = $host;
        $this->port = $port;
开发者ID:hack4reno,项目名称:hack4reno2011,代码行数:31,代码来源:tropo-redis.php

示例5: Redis

<?php

$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$channel = $argv[1];
// channel
$msg = $argv[2];
// msg
$redis->publish('channel' . $channel, $msg);
开发者ID:CraryPrimitiveMan,项目名称:code-examples,代码行数:9,代码来源:publish.php

示例6: publish

 /**
  * @param string $channel
  * @param string $msg
  */
 public function publish($channel, $msg)
 {
     $this->_redis->publish($channel, $msg);
 }
开发者ID:aladin1394,项目名称:CM,代码行数:8,代码来源:Client.php

示例7: implode

                } else {
                    $func = $frame['function'];
                }
                if ($func !== end($stack)) {
                    $stack[] = $func;
                }
            }
            if (count($stack)) {
                // The last element is usually (but not always) the full file
                // path of the script name. We want things nice and consistent,
                // so we pop off the path if it is there, and push the basename
                // instead.
                if (strpos(end($stack), $entryPoint) !== false) {
                    array_pop($stack);
                }
                $stack[] = $entryPoint;
                $strStack = implode(';', array_reverse($stack));
                if (!isset($stacks[$strStack])) {
                    $stacks[$strStack] = 0;
                }
                $stacks[$strStack] += 1;
            }
        }
        $redis = new Redis();
        if ($redis->connect('fluorine.eqiad.wmnet', 6379, 0.1)) {
            foreach ($stacks as $stack => $count) {
                $redis->publish('xenon', "{$stack} {$count}");
            }
        }
    });
}
开发者ID:nomoa,项目名称:operations-mediawiki-config,代码行数:31,代码来源:StartProfiler.php

示例8: pushAction

 /**
  * push action.
  *
  * @Route("/push", methods={"GET", "POST"}, name="site-import-push")
  */
 public function pushAction()
 {
     $redis = new \Redis();
     $redis->connect('127.0.0.1', 6379);
     $meta = ['shopName' => $this->session->get('shop'), 'record' => 0];
     for ($i = 1; $i <= 100; $i++) {
         sleep(1);
         $meta['record'] = $i;
         $i += 10;
         $redis->publish('notification', json_encode($meta));
         // send message.
     }
     die;
 }
开发者ID:nguyenducduy,项目名称:haraapp,代码行数:19,代码来源:SiteController.php

示例9: Redis

<?php

$update = false;
$redis = new Redis();
try {
    $redis->connect('127.0.0.1', 6379);
    if (isset($_GET['c']) && !empty($_GET['c'])) {
        $redis->set('cobbler:count', $_GET['c']);
        $update = true;
    }
    if (isset($_GET['s']) && !empty($_GET['s'])) {
        $redis->set('cobbler:speed', $_GET['s']);
        $update = true;
    }
    if ($update) {
        $redis->publish('cobbler', 'update');
        echo 'OK';
    } else {
        echo 'NO_UP';
    }
    $redis->close();
} catch (Exception $e) {
    echo 'ERROR ' . $e->getMessage();
}
开发者ID:episode17,项目名称:cobbler-web,代码行数:24,代码来源:update.php

示例10: feed

 public function feed()
 {
     /*
      *
      *
      *
      */
     $food = "";
     $errorMessage = "";
     if (!empty(file_get_contents("php://input"))) {
         $raw = file_get_contents("php://input");
         //some test data for filling
         if ($food = json_decode($raw, true)) {
         } else {
             header("HTTP/1.0 400 Error");
             echo "invalid JSON format";
         }
         if ($food != "") {
             // Validation block, to check if payLoad have endpoint, correct url provided and allowed method
             if (isset($food['endpoint'])) {
                 if (isset($food['data'])) {
                     if (!in_array(strtolower($food['endpoint']['method']), $this->params['allowedMethods'])) {
                         $errorMessage = "Wrong Method (" . $food['endpoint']['method'] . ")";
                     }
                     if (!preg_match("/\\b(?:(?:https?):\\/\\/|www\\.)[-a-z0-9+&@#\\/%?=~_|!:,.;]*[-a-z0-9+&@#\\/%=~_|]/i", $food['endpoint']['url'])) {
                         $errorMessage = "URL is invalid";
                     }
                 } else {
                     $errorMessage = "Missing Load";
                 }
             } else {
                 $errorMessage = "Missing Endpoint";
             }
             if ($errorMessage == "") {
                 //print_r($food);
                 $redis = new Redis();
                 if ($redis->connect('127.0.0.1', 6379)) {
                     $countCalls = 0;
                     if (strtolower($food['endpoint']['method']) == 'post') {
                         //if post, then all data will be submitted at onst filling
                         $recordUUI = sha1(microtime() . $raw . mt_rand());
                         $time = time();
                         $args = array('load' => $raw, 'time' => $time, 'count' => 0);
                         //saving data into redis, using multi to save roundtrips
                         $redis->multi()->hMset($recordUUI, $args)->zAdd('sQue', $time, $recordUUI)->incrBy('postCalls', 1)->incrBy('requestCount', 1)->incrBy('loadVolume', mb_strlen($raw, '8bit'))->exec();
                     }
                     if (strtolower($food['endpoint']['method']) == "get") {
                         //for GET compatibility sake break load into multiple calls
                         //$recordData[]='que';
                         $recordDataForSortedSet[] = 'sQue';
                         foreach ($food['data'] as $index => $data) {
                             $time = time();
                             $recordUUI = sha1(microtime() . $raw . mt_rand());
                             $recordData[] = $recordUUI;
                             $recordDataForSortedSet[] = $time;
                             $recordDataForSortedSet[] = $recordUUI;
                             $breaking['endpoint'] = $food['endpoint'];
                             $breaking['data'] = $data;
                             $args = array('load' => json_encode($breaking, JSON_UNESCAPED_SLASHES), 'time' => $time, 'count' => 0);
                             $redis->hMset($recordUUI, $args);
                             $countCalls++;
                         }
                         //saving data into redis, didn't find method to use multi for that
                         //call_user_func_array(array($redis, 'lpush'), $recordData);
                         call_user_func_array(array($redis, 'zAdd'), $recordDataForSortedSet);
                         //sorted list for process
                         $redis->multi()->incrBy('requestCount', 1)->incrBy('loadVolume', mb_strlen($raw, '8bit'))->incrBy('getCalls', $countCalls)->exec();
                         //print_r($err = $redis->getLastError());
                         //print_r($ind);
                     }
                     echo 'ok';
                     $redis->publish('queue', '1');
                 } else {
                     header("HTTP/1.0 400 Error");
                     echo 'Redis is offline';
                 }
             } else {
                 header("HTTP/1.0 400 Error");
                 echo $errorMessage;
             }
         }
     } else {
         header("HTTP/1.0 400 Error");
         echo "No Payload";
     }
 }
开发者ID:vSaKv,项目名称:ko_php,代码行数:86,代码来源:ingest.php

示例11: publish

 /**
  * publish channel message
  *
  * @param $channel
  * @param $message
  * @return int
  */
 public function publish($message, $channel = 'email')
 {
     return $this->_redis->publish($channel, $message);
 }
开发者ID:TimHuangcheng,项目名称:CI,代码行数:11,代码来源:Cache_redis.php


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