nrk / predis-async Goto Github PK
View Code? Open in Web Editor NEWAsynchronous PHP client library for Redis built on top of ReactPHP
License: MIT License
Asynchronous PHP client library for Redis built on top of ReactPHP
License: MIT License
Below exampel script. Run it and than publish messages to "queue:0:cmd":
publish queue:0:cmd test
publish queue:0:cmd quit
publish queue:0:cmd test
publish queue:0:cmd quit
You will see response from monitor:
$php ./test
Connected to Redis, now listening for incoming messages cmd...
Received message test
from channel queue:0:cmd
[type: message].
Received message quit
from channel queue:0:cmd
[type: message].
Connected to Redis, now listening for incoming messages cmd...
Received message quit
from channel queue:0:cmd
[type: message].
As you can see second "test" message is lost. In same time "redis-cli" points that all messages were delivered:
127.0.0.1:6379> publish queue:0:cmd test
(integer) 1
127.0.0.1:6379> publish queue:0:cmd quit
(integer) 1
127.0.0.1:6379> publish queue:0:cmd test
(integer) 1
127.0.0.1:6379> publish queue:0:cmd quit
(integer) 1
"libvent" lib is used for event loop.
require __DIR__ . '/vendor/autoload.php';
$loop = \React\EventLoop\Factory::create();
$client = new Predis\Async\Client('tcp://127.0.0.1:6379', $loop);
$client->connect(function ($client) {
echo "Connected to Redis, now listening for incoming messages cmd...\n";
$client->pubSubLoop('queue:0:cmd', function ($event, $pubsub) {
$message = "Received message `%s` from channel `%s` [type: %s].\n";
$feedback = sprintf($message,
$event->payload,
$event->channel,
$event->kind
);
echo $feedback;
if ($event->payload === 'quit') {
$pubsub->quit();
}
});
});
$loop->run();
$client->connect(function ($client) {
echo "Connected to Redis, now listening for incoming messages cmd...\n";
$client->pubSubLoop('queue:0:cmd', function ($event, $pubsub) {
$message = "Received message `%s` from channel `%s` [type: %s].\n";
$feedback = sprintf($message,
$event->payload,
$event->channel,
$event->kind
);
echo $feedback;
if ($event->payload === 'quit') {
$pubsub->quit();
}
});
});
$loop->run();
Hi Team,
I am using this plugin into my project.
I am getting the following error in my project logs...Can someone plz help on this
My s/w specification:
Php 7.0
"predis/predis": "1.1.1",
"predis/predis-async": "dev-master"
PHP Fatal error: Uncaught Error: Call to undefined method React\EventLoop\Timer\Timer::setData() in /var/www/html/vendor/predis/predis-async/src/Connection/AbstractConnection.php:179
Stack trace:
#0 /var/www/html/vendor/predis/predis-async/src/Connection/AbstractConnection.php(158): Predis\Async\Connection\AbstractConnection->armTimeoutMonitor(5, Object(Closure))
#1 /var/www/html/vendor/predis/predis-async/src/Connection/AbstractConnection.php(209): Predis\Async\Connection\AbstractConnection->createResource(Object(Closure))
#2 /var/www/html/vendor/predis/predis-async/src/Client.php(178): Predis\Async\Connection\AbstractConnection->connect(Object(Closure))
#3 /var/www/html/commands/Queue/QueueConnector.php(86): Predis\Async\Client->connect(Object(Closure))
#4 /var/www/html/commands/Queue/QueueConnector.php(43): CLI\Queue\QueueConnector->createRedisClient(Object(CLI\Configuration\Configuration), Object(CLI\Handler\s3UploadHandler))
#5 /var/www/html/commands/Jobs/S3Upload.php(13): CLI\Queue\QueueConnector->__construct(Object(CLI in /var/www/html/vendor/predis/predis-async/src/Connection/AbstractConnection.php on line 179
Thanks in advance
Predis\Configuration\Options#L104 invokes any callable to get its value. As a result on_error needs to be wrapped otherwise the following error occurs:
Missing argument 3 for ...{closure}(), called in .../vendor/predis/predis/src/Configuration/Options.php on line 104
Hello, i got this error
PHP Fatal error: Uncaught Error: Call to undefined function Predis\Async\Connection\phpiredis_reader_create() in /home/mark/test-task/room/src/backend/websocket/vendor/predis/predis-async/lib/Predis/Async/Connection/StreamConnection.php:75
this is composer.json
"require": {
"cboden/ratchet": "^0.4.1",
"react/socket": "^1.1.0",
"predis/predis": "^0.8",
"predis/predis-async": "^0.2.3",
"clue/redis-react": "^2.2"
}
I'm wondering is there a way of 're-invoke pubSubLoop()', without re-runing the script
EDIT: got it
if !redis-async->isConnected()
redis-async->connect(function() { redis-async->pubSubLoop(['psubscribe'=>'*'], function() {....}) })
Could you tag current master as next stable version? I'm working on a project using react 0.4 and predis-async and I wouldn't like to maintain dependencies on dev versions.
btw Thank you for Predis, it's a great library!
React event-loop is at 0.3.* now.
CPU spikes to 100% regardless of the event loop backend I use and feed to Predis\Async\Connection\StreamConnection.
Can't seem to pinpoint the issue, but it seems to have creeped up when I moved to my new server (php 5.4, new linux kernel - lots of variables in the equation).
CPU only spikes after a command is issued to redis.
I'm going to keep trying to track down exactly what is causing this in my free time, I just wanted to let you know.
To recreate:
Is it possible to use the AUTH command with Predis-async ?
I've got the blocking list pop example working from the repo, however, I'm unable to get the blpop working in a continuous loop.
$connection = "tcp://localhost:6379";
$consumer = new \Predis\Async\Client( $connection )
$consumer->connect(
function ( $consumer ) {
echo "Connected to Redis, blpop'ing on queue:*\n";
$consumer->blpop(
'queue:normal',
0,
function ( $response ) use ( $consumer ) {
list( $priority, $job ) = $response;
if ( $priority ):
$message = "`%s` from channel `%s`.\n";
$feedback = sprintf( $message, $job, $priority );
echo $feedback;
endif;
return TRUE;
});
});
$consumer->getEventLoop()->run();
When I run this code with items in the queue, it will process the first one but then halt and hang in the terminal. Is there a way to have this blpop continuously block and then pop an item when it finds one?
<?php
require __DIR__ . '/vendor/autoload.php';
ini_set('display_errors', 'on');
error_reporting(E_ALL);
function pubsub($message, $client)
{
}
$loop = \React\EventLoop\Factory::create();
$client = new Predis\Async\Client('tcp://127.0.0.1:6379', $loop);
$consumer = $this->redis->pubSubLoop('test', 'pubsub');
$consumer->unsubscribe('test');
This code triggers catchable fatal error on PHP 5.6:
PHP Catchable fatal error: Argument 2 passed to Predis\Async\Client::pubSubLoop() must be callable, null given, called in redis_test.php on line 10 and defined in /media/sf_share/nevesta.info/vendor/predis/predis-async/src/Client.php on line 307
Is this abandoned?
I'm trying to install it via composer but i requires ext-phpiredis. Is there a way to force it without phpiredis?
Is it possible to use predis-async as a listener to a list in Redis?
When ever there is an item in a list, pop it and run a callback and if there is not an item wait for an item.
I want to use a list as buffer.
Hi,
Phastlight(https://github.com/phastlight/phastlight) is a new node.js inspired tool that's built on top of libuv.
It has timer functionality(https://github.com/phastlight/phastlight#server-side-timer) that I believe will be faster than the timer that is simulated in php, it would be nice if there is a predis-aysnc port to phastlight.
Best Regards,
Jim
Hello,
i got a deamon in php who do many thousand sub/unsub redis channel.
After few hours i use 1Go ram.
I found [commands:protected] => SplQueue Object become more and more larger, maybe all sub/unsub is save inside without clean it ?
"$commands" from class Predis\Async\Connection\PhpiredisStreamConnection
I wasn't sure where to ask this so I picked here.
I'm testing out using Redis to collect my user analytics events for realtime viewing. While it is being developed I want the transaction to have minimal impact on page load (ideally none) and to give up very quickly if the Redis server isn't responding.
At first I was (incorrectly) doing $client->connect
proceeded immediately by
try{
$client->getEventLoop()->run();
} catch
It is now my understanding that the idea of the eventLoop is to set those commands up and then run the event loop later, like via AJAX after the page loads (right?).
If you need more background information let me know.
Here's my issue. I can't figure out what, if anything, setting async_connect
to true does. I'm just generally confused. Is user-facing performance/responsiveness not the goal of asynchronous PHP like it is with asynchronous javascript? What approach should I use to unobtrusively write to Redis?
$client = new Predis\Async\Client('tcp://127.0.0.1:6379');
$client->connect(function ($client) {
$client->disconnect();
});
$client->getEventLoop()->run();
When I go to this URL resource /resque/failed/list
I can see some failed jobs. However my Redis has more than 1 worker and I am not sure what is the server that has managed that scheduled job, so I cannot investigate (easily) why the scheduled job has failed because I cannot see the worker that managed the job. Can you add a new column on that list please?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.