I used the Laravel 4 framework development and wanted to switch the cache server from Memcache to Redis, and the driver in config/cache.php was set to Redis. But call Cache::get () error, error information such as:
[2014-10-21 18:47:44] production.ERROR: exception 'Predis\Connection\ConnectionException' with message 'Error while reading line from the server [tcp://127.0.0.1:6379]' in /home/nginx/mono/vendor/predis/predis/lib/Predis/Connection/AbstractConnection.php:141
However, accessing Redis-server from Redis-cli is OK, and it is no problem to test Redis separately in PHPUnit. But the direct use of the route is problematic.
Route::get('/test', function(){
Cache::put('name', 'Taylor', 60); //error!
$name = Cache::get('name');
echo $name;
});
Who can explain the problem?
Add: Refresh multiple/test, there will be a few normal.
Reply content:
I used the Laravel 4 framework development and wanted to switch the cache server from Memcache to Redis, and the driver in config/cache.php was set to Redis. But call Cache::get () error, error information such as:
[2014-10-21 18:47:44] production.ERROR: exception 'Predis\Connection\ConnectionException' with message 'Error while reading line from the server [tcp://127.0.0.1:6379]' in /home/nginx/mono/vendor/predis/predis/lib/Predis/Connection/AbstractConnection.php:141
However, accessing Redis-server from Redis-cli is OK, and it is no problem to test Redis separately in PHPUnit. But the direct use of the route is problematic.
Route::get('/test', function(){
Cache::put('name', 'Taylor', 60); //error!
$name = Cache::get('name');
echo $name;
});
Who can explain the problem?
Add: Refresh multiple/test, there will be a few normal.
Predis's Streamconnection Class
/ **
* Initializes a TCP stream resource.
*
* @param ConnectionParametersInterface $ parameters Parameters used to initialize the connection.
* @return resource
* /
protected function tcpStreamInitializer (ConnectionParametersInterface $ parameters)
{
$ uri = "tcp: // {$ parameters-> host}: {$ parameters-> port}";
$ flags = STREAM_CLIENT_CONNECT;
if (isset ($ parameters-> async_connect) && $ parameters-> async_connect) {
$ flags | = STREAM_CLIENT_ASYNC_CONNECT;
}
if (isset ($ parameters-> persistent) && $ parameters-> persistent) {
$ flags | = STREAM_CLIENT_PERSISTENT;
$ uri. = strpos ($ path = $ parameters-> path, '/') === 0? $ path: "/ $ path";
}
$ resource = @stream_socket_client ($ uri, $ errno, $ errstr, $ parameters-> timeout, $ flags);
if (! $ resource) {
$ this-> onConnectionError (trim ($ errstr), $ errno);
}
// The problem is that you need to set the timeout for the read stream, otherwise the connection will report an error when reading the stream data,
// You can directly set read_write_timeout to 0 to solve the problem.
if (isset ($ parameters-> read_write_timeout)) {
$ rwtimeout = $ parameters-> read_write_timeout;
$ rwtimeout = $ rwtimeout> 0? $ rwtimeout: -1;
$ timeoutSeconds = floor ($ rwtimeout);
$ timeoutUSeconds = ($ rwtimeout-$ timeoutSeconds) * 1000000;
stream_set_timeout ($ resource, $ timeoutSeconds, $ timeoutUSeconds);
}
if (isset ($ parameters-> tcp_nodelay) && function_exists ('socket_import_stream')) {
$ socket = socket_import_stream ($ resource);
socket_set_option ($ socket, SOL_TCP, TCP_NODELAY, (int) $ parameters-> tcp_nodelay);
}
return $ resource;
}
Production. ERROR
Is there a folder in configproduction? Is there a cache.php file inside? That would overwrite the outside configuration.