我有一个流明api在我的服务器上,它工作得很好。实际上,这个api每秒钟都会从另一台服务器调用一次,更新库存率并存储到redis中。在这个api中,我比较从redis接收的数据(请求体)和存储的数据,更新当前值和以前值的差异率作为响应,并且我将在redis中发送当前日期时间来显示股票价格的最后一次更新时间。我的流明api中有以下代码,
use Illuminate\Support\Facades\Redis;
public function updatebaserate(Request $request)
{
$request_data = array();
parse_str($request, $request_data);
if (app('redis')->get("BaseRates")) {
if(json_decode(app('redis')->get("BaseRates"),true) === json_decode($request->getContent(), true)){
$this->createrates();
return app('redis')->get("BaseRatesUpdated");
}else{
$receivedrates = json_decode($request->getContent(), true);
$rate_valid = true;
if($rate_valid){
app('redis')->set("BaseRatesUpdated", Carbon::createFromFormat('d-m-Y H:i:s', date('d-m-Y H:i:s')));
app('redis')->set("BaseRates", $request->getContent());
}
}
} else {
app('redis')->set("BaseRates", $request->getContent());
app('redis')->set("BaseRatesUpdated", Carbon::createFromFormat('d-m-Y H:i:s', date('d-m-Y H:i:s')));
}
$this->createrates();
return app('redis')->get("BaseRatesUpdated");
}
每秒钟连续工作一次的redis操作的get和set 2api请求将从另一个服务器调用。是否会引起任何问题。在我的lumen.env设置中
BROADCAST_DRIVER=redis
CACHE_DRIVER=redis
QUEUE_DRIVER=redis
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
在服务器redis info中显示以下详细信息,
# Server
redis_version:3.2.10
tcp_port:6379
# Clients
connected_clients:13
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0
# Memory
used_memory:1802320
used_memory_human:1.72M
used_memory_rss:2387968
used_memory_rss_human:2.28M
used_memory_peak:2200392
used_memory_peak_human:2.10M
total_system_memory:4026261504
total_system_memory_human:3.75G
used_memory_lua:39936
used_memory_lua_human:39.00K
maxmemory:0
# Stats
total_connections_received:302107
total_commands_processed:30017647
instantaneous_ops_per_sec:302
total_net_input_bytes:6532076041
total_net_output_bytes:67794026721
instantaneous_input_kbps:59.68
instantaneous_output_kbps:642.24
rejected_connections:0
redis中是否存在每秒连续读写密钥的问题。我还设置了redis超时值
127.0.0.1:6379> config get timeout
1) "timeout"
2) "100"
在redis的lumen api中是否有打开和关闭连接的方法。我经常收到错误日志中的错误,如
[2020-03-17 17:17:29] production.ERROR: Predis\Connection\ConnectionException: Connection timed out [tcp://127.0.0.1:6379] in /home/public_html/winapi/vendor/predis/predis/src/Connection/AbstractConnection.php:155
Stack trace:
# 0 /home/public_html/winapi/vendor/predis/predis/src/Connection/StreamConnection.php(128): Predis\Connection\AbstractConnection->onConnectionError('Connection time...', 110)
# 1 /home/public_html/winapi/vendor/predis/predis/src/Connection/StreamConnection.php(178): Predis\Connection\StreamConnection->createStreamSocket(Object(Predis\Connection\Parameters), 'tcp://127.0.0.1...', 4)
# 2 /home/public_html/winapi/vendor/predis/predis/src/Connection/StreamConnection.php(100): Predis\Connection\StreamConnection->tcpStreamInitializer(Object(Predis\Connection\Parameters))
请帮助任何人解决这个问题。
1条答案
按热度按时间qv7cva1a1#
请尝试更改redis
timeout
价值/etc/redis/redis.conf
一些非零值。这可以解决你的问题。