gpt4 book ai didi

phpredis Redis::subscribe() 期望参数 2 是一个有效的回调

转载 作者:可可西里 更新时间:2023-11-01 11:21:53 27 4
gpt4 key购买 nike

我在使用订阅方法时遇到问题。欢迎任何帮助以使其正常工作。以下 php 单元测试给我以下错误。

这是 phpredis 提供的示例。

https://github.com/nicolasff/phpredis#subscribe

Redis::subscribe() expects parameter 2 to be a valid callback, function 'f' not found or invalid function name

/myproj/test/RedisEventBusTest.php:37

RedisEventBusTest.php

<?php

namespace bkcqrs\eventing;

use bkcqrs\DefaultDomainEvent;
use bkcqrs\serializing\JsonSerializer;

class RedisEventBusTest extends \PHPUnit_Framework_TestCase
{
private $redisEventBus;
private $redisSubscribeClient;

public function setUp()
{
$serializer = new JsonSerializer();
$this->redisEventBus = new RedisEventBus($serializer);
$this->redisSubscribeClient = new \Redis();
}

public function it_publishes_the_event_on_redis()
{
$notificationCountChangedEvent = new NotificationCountChangedEvent(array('userId' => 6, 'count' => 21));
function f($redis, $channel, $msg)
{
var_dump($msg);
$notification = json_decode($msg);
var_dump($notification);

$this->assertEquals($notification["userId"], $notificationCountChangedEvent->userId);
$this->assertEquals($notification["count"], $notificationCountChangedEvent->count);
}

$this->redisSubscribeClient->subscribe(array("NotificationCountChanged"), 'f');
$this->redisEventBus->publish($notificationCountChangedEvent);
}
}

class NotificationCountChangedEvent extends DefaultDomainEvent
{
public $userId;
public $count;
}

最佳答案

以下两种方法之一确实有效。

A) $client->subscribe($channels, function($r, $c, $m){});

B) $f = create_function($parms, $functionBody); $client->subscribe($channels, $f);

关于phpredis Redis::subscribe() 期望参数 2 是一个有效的回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25064616/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com