Comments (8)
This would be great for us too. The first option is most standard, and for backwards compatibility could be enabled by setting a constant or specifying the desired behavior during initialization.
from phpiredis.
I like both 1 and 3 but I'd be more inclined to favor 3 since it's the same approach we used for phpiredis_reader
. Currently the client and the reader resources are completely separate and don't share any kind of interaction, this is due to the fact that the reader bits were implemented at a later stage to make this library useful for other pure-PHP libraries such as Predis to optionally speed things up a bit with protocol parsing and serialization.
The advantage of 3 is that users can customize the behavior of the client simply by supplying a callable object to make it raise a PHP error (like it happens currently when using the client), return a custom error object (like it happens with Predis that uses only the reader resource) or simply throw an exception (which is the point of the current discussion). We could also make the client raise a PHP error by default to retain the current behavior when there's no custom handler specified, but maybe we should just aim to introduce breaking changes altogether (see later in my comment). I'm not sure about having a distinction between global or per-connection handlers, I'd go only with the second but maybe I'm missing a use case that would make the global ones useful.
But while this is cool to handle errors returned by Redis, it doesn't solve our problem with plain connection errors (e.g. the server goes down while doing stuff)...
Slightly related: I was meaning to finally freeze the library and tag a 1.0.0 release to start making changes (even breaking ones) targeting a new major release sometime in the future. The change described in your issue would be a good start in this direction, and I have some more ideas that I was planning to share in a issue open for discussion. Unfortunately my C skills are not something to be proud of and also a bit rusty since the last time I used it extensively was in high-school (quite a while ago :-)) so literally any kind of help and contribution would be more than appreciated.
from phpiredis.
Hi,
I'm with some free time at the moment, so I can take a stab at this, or review @theintz's implementation but I agree on deciding an interface first.
About implementations, I prefer option 3, adding a two new optional arguments to phpiredis_{multi_}command{,_bs}
that would be called on error and on status and return whatever those functions return.
The phpiredis_reader
interface might also be used instead and only use one extra new optional argument, but I think most of the users won't prefer to initialize a reader for these functions.
from phpiredis.
So the debate swings in favor of setting an error handler. However, instead of passing the handler(s) each time a phpiredis function is called, I would favor adding a function phpiredis_set_error_handler()
, which attaches a custom error handler to a connection. This error handler could also be used when a connection error happens. Maybe we could define a few constants that represent the type of error: PHPIREDIS_CONNECTION_ERROR
and PHPIREDIS_PROTOCOL_ERROR
, for example.
from phpiredis.
@theintz I agree with you and that's what I was referring to when I said that we should use per-connection handlers.
I like @seppo0010's suggestion of using the same resource returned by phpiredis_reader_create()
as an optional argument to set custom status and error handlers used to process Redis responses, but instead of passing it each time a function is called I'd pass it only once when we create the connection. The function would look something like this:
phpiredis_connect($host, $port, $reader = null);
As for connection or protocol parsing errors we can indeed add a new function with a signature like phpiredis_set_error_handler($connection, $handler)
where $handler
is a callable with a signature like function($message, $type)
(and where $type
is populated with the values of PHPIREDIS_CONNECTION_ERROR
or PHPIREDIS_PROTOCOL_ERROR
depending on the error)
from phpiredis.
What I don't know is how that works considering the connection might be persistent.
from phpiredis.
@seppo0010 For all PHP knows, there are no persistent connections. For every request, the connection must be re-initialized by calling phpiredis_pconnect()
anyways (in order to get the connection handle), so it might as well be non-persistent (connections are however cached/persisted inside the extension code). The error handler then has to be set on the connection for every request as well.
I am going to get started on adding the function and the constants we talked about, I have to admit however that C is not my native language either. Much of the code for setting an error handler is already in the extension though, so it should not be very difficult. Will create a pull request when I have it working.
from phpiredis.
In the meanwhile I'm going to create a new v1.0
branch and tag v1.0.0
soon, the new developments regarding this issue will be eventually available in a new major release.
from phpiredis.
Related Issues (20)
- PHP 7 support HOT 1
- Error building against PHP 5.6.8 HOT 11
- The value of phpiredis_command_bs SET must be string? HOT 4
- pls support php7 HOT 16
- Release on PECL HOT 19
- make compile error HOT 2
- PHP: Unable to load dynamic library HOT 8
- make test after make install: phpiredis extension is not available
- make test after make install: phpiredis extension is not available HOT 1
- Compatibility with PHP 7.x HOT 19
- Install ext-phpiredis On Mac El Capitan HOT 1
- [RFE] improve installation doc HOT 2
- PhpiRedis: supplied resource is not a valid phpredis reader HOT 1
- phpiredis for snc_redis HOT 2
- Failed make tests HOT 5
- Docker / Alpine installation (phpiredis.so: redisReplyReaderGetReply: symbol not found) HOT 4
- undefined symbol: redisReplyReaderGetReply in Unknown on line 0 HOT 4
- Extension fails to load when built with hiredis 0.14 on armv7h or x86_64: works on armv6h HOT 3
- Will recent Hiredis upgrades be implemented? HOT 6
- Plan to release 1.1.x HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phpiredis.