問題描述
我已經在 Amazon ElastiCache 上為緩存設置了 redis-cluster,使用 Laravel 5.5 和 Predis 包,我收到以下錯誤.
PredisClientException: 在 vendor/predis/predis/src/Connection/Aggregate/RedisCluster.php:337 中的池中沒有可用的連接
<塊引用>
跟蹤:PredisClientException: 在 vendor/predis/predis/src/Connection/Aggregate/RedisCluster.php:337 中的池中沒有可用連接
堆棧跟蹤:
0 vendor/predis/predis/src/Connection/Aggregate/RedisCluster.php(411):PredisConnectionAggregateRedisCluster->guessNode(153)
1 vendor/predis/predis/src/Connection/Aggregate/RedisCluster.php(388):PredisConnectionAggregateRedisCluster->getConnectionBySlot(153)
2 vendor/predis/predis/src/Connection/Aggregate/RedisCluster.php(550):PredisConnectionAggregateRedisCluster->getConnection(Object(PredisCommandStringSetExpire))
3 vendor/predis/predis/src/Connection/Aggregate/RedisCluster.php(593):PredisConnectionAggregateRedisCluster->retryCommandOnFailure(Object(PredisCommandStringSetExpire),'執行命令')
4 vendor/predis/predis/src/Client.php(331): PredisConnectionAggregateRedisCluster->executeCommand(Object(PredisCommandStringSetExpire))
5 vendor/predis/predis/src/Client.php(314): PredisClient->executeCommand(Object(PredisCommandStringSetExpire))
6 vendor/laravel/framework/src/Illuminate/Redis/Connections/Connection.php(96):PredisClient->__call('setex', Array)
7 vendor/laravel/framework/src/Illuminate/Redis/Connections/Connection.php(108):IlluminateRedisConnectionsConnection->command('setex', Array)
8 vendor/laravel/framework/src/Illuminate/Cache/RedisStore.php(93): IlluminateRedisConnectionsConnection->__call('setex', Array)
9 vendor/laravel/framework/src/Illuminate/Cache/Repository.php(195): IlluminateCacheRedisStore->put('5rr44TBjIPEgJSx...','a:1:{s:6:"_flas...', 480)
10 vendor/laravel/framework/src/Illuminate/Session/CacheBasedSessionHandler.php(66):IlluminateCacheRepository->put('5rr44TBjIPEgJSx...','a:1:{s:6:"_flas...', 480)
11 vendor/laravel/framework/src/Illuminate/Session/Store.php(128): IlluminateSessionCacheBasedSessionHandler->write('5rr44TBjIPEgJSx...','a:1:{s:6:"_flas...')
12 vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(87):IlluminateSessionStore->save()
13 vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(218):IlluminateSessionMiddlewareStartSession->terminate(Object(IlluminateHttpRequest),對象(IlluminateHttpResponse))
14 vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(189):IlluminateFoundationHttpKernel->terminateMiddleware(Object(IlluminateHttpRequest),對象(IlluminateHttpResponse))
15 public/index.php(58): IlluminateFoundationHttpKernel->terminate(Object(IlluminateHttpRequest),對象(IlluminateHttpResponse))
16 {main}
我使用的技術棧:
- PHP7.0
- Laravel5.5
- 操作系統(Debian GNU/Linux 9.6 (stretch)),9.6 版
我在 config/database.php 中嘗試了以下配置:
redis=>['客戶' =>'predis','選項' =>['集群' =>'redis',],'集群' =>['默認' =>[['主機' =>環境('REDIS_CLUSTER_HOST','本地主機'),'密碼' =>env('REDIS_CLUSTER_PASSWORD', null),'端口' =>環境('REDIS_CLUSTER_PORT',6379),'數據庫' =>0,],],'緩存' =>[['主機' =>環境('REDIS_CLUSTER_HOST','本地主機'),'密碼' =>env('REDIS_CLUSTER_PASSWORD', null),'端口' =>環境('REDIS_CLUSTER_PORT',6379),'數據庫' =>0,],],]]
我也試過 timeout => 0|5|60 但每次我都遇到同樣的錯誤.
任何幫助將不勝感激!
這在我們的環境中起作用:
'redis' =>['集群' =>真的,'客戶' =>'predis','選項' =>['集群' =>'redis','參數' =>['方案' =>env('REDIS_SCHEME', 'tcp'),'主機' =>環境('REDIS_HOST','本地主機'),'密碼' =>env('REDIS_PASSWORD', null),'端口' =>環境('REDIS_PORT',6379),'數據庫' =>0,'超時' =>15、],],'集群' =>['默認' =>['方案' =>env('REDIS_SCHEME', 'tcp'),'主機' =>環境('REDIS_HOST','本地主機'),'密碼' =>env('REDIS_PASSWORD', null),'端口' =>環境('REDIS_PORT',6379),'數據庫' =>0,'超時' =>15、],],],
基于此處找到的信息:https://github.com/nrk/predis/issues/480 - 但還需要復制選項中的所有默認"配置值 -> 參數組
REDIS_HOST,指向 AWS elasticache 的 redis 集群中的配置端點.
I've setup redis-cluster on Amazon ElastiCache for cache, using Laravel 5.5 and Predis package, I get the following error.
PredisClientException: No connections available in the pool in vendor/predis/predis/src/Connection/Aggregate/RedisCluster.php:337
Trace: PredisClientException: No connections available in the pool in vendor/predis/predis/src/Connection/Aggregate/RedisCluster.php:337
Stack trace:
0 vendor/predis/predis/src/Connection/Aggregate/RedisCluster.php(411): PredisConnectionAggregateRedisCluster->guessNode(153)
1 vendor/predis/predis/src/Connection/Aggregate/RedisCluster.php(388): PredisConnectionAggregateRedisCluster->getConnectionBySlot(153)
2 vendor/predis/predis/src/Connection/Aggregate/RedisCluster.php(550): PredisConnectionAggregateRedisCluster->getConnection(Object(PredisCommandStringSetExpire))
3 vendor/predis/predis/src/Connection/Aggregate/RedisCluster.php(593): PredisConnectionAggregateRedisCluster->retryCommandOnFailure(Object(PredisCommandStringSetExpire), 'executeCommand')
4 vendor/predis/predis/src/Client.php(331): PredisConnectionAggregateRedisCluster->executeCommand(Object(PredisCommandStringSetExpire))
5 vendor/predis/predis/src/Client.php(314): PredisClient->executeCommand(Object(PredisCommandStringSetExpire))
6 vendor/laravel/framework/src/Illuminate/Redis/Connections/Connection.php(96): PredisClient->__call('setex', Array)
7 vendor/laravel/framework/src/Illuminate/Redis/Connections/Connection.php(108): IlluminateRedisConnectionsConnection->command('setex', Array)
8 vendor/laravel/framework/src/Illuminate/Cache/RedisStore.php(93): IlluminateRedisConnectionsConnection->__call('setex', Array)
9 vendor/laravel/framework/src/Illuminate/Cache/Repository.php(195): IlluminateCacheRedisStore->put('5rr44TBjIPEgJSx...', 'a:1:{s:6:"_flas...', 480)
10 vendor/laravel/framework/src/Illuminate/Session/CacheBasedSessionHandler.php(66): IlluminateCacheRepository->put('5rr44TBjIPEgJSx...', 'a:1:{s:6:"_flas...', 480)
11 vendor/laravel/framework/src/Illuminate/Session/Store.php(128): IlluminateSessionCacheBasedSessionHandler->write('5rr44TBjIPEgJSx...', 'a:1:{s:6:"_flas...')
12 vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(87): IlluminateSessionStore->save()
13 vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(218): IlluminateSessionMiddlewareStartSession->terminate(Object(IlluminateHttpRequest), Object(IlluminateHttpResponse))
14 vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(189): IlluminateFoundationHttpKernel->terminateMiddleware(Object(IlluminateHttpRequest), Object(IlluminateHttpResponse))
15 public/index.php(58): IlluminateFoundationHttpKernel->terminate(Object(IlluminateHttpRequest), Object(IlluminateHttpResponse))
16 {main}
Technical stack I used:
- PHP7.0
- Laravel5.5
- OS (Debian GNU/Linux 9.6 (stretch)), Release 9.6
I tried the following configs in config/database.php:
redis=> [
'client' => 'predis',
'options' => [
'cluster' => 'redis',
],
'clusters' => [
'default' => [
[
'host' => env('REDIS_CLUSTER_HOST', 'localhost'),
'password' => env('REDIS_CLUSTER_PASSWORD', null),
'port' => env('REDIS_CLUSTER_PORT', 6379),
'database' => 0,
],
],
'cache' => [
[
'host' => env('REDIS_CLUSTER_HOST', 'localhost'),
'password' => env('REDIS_CLUSTER_PASSWORD', null),
'port' => env('REDIS_CLUSTER_PORT', 6379),
'database' => 0,
],
],
]
]
I also tried with timeout => 0|5|60 but every time I get the same error.
Any help would be highly appreciated!
This is working in in our env:
'redis' => [
'cluster' => true,
'client' => 'predis',
'options' => [
'cluster' => 'redis',
'parameters' => [
'scheme' => env('REDIS_SCHEME', 'tcp'),
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
'timeout' => 15,
],
],
'clusters' => [
'default' => [
'scheme' => env('REDIS_SCHEME', 'tcp'),
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
'timeout' => 15,
],
],
],
Based on info found here: https://github.com/nrk/predis/issues/480 - but needed to also replicate all 'default' config values in the options -> parameters group
REDIS_HOST, is pointing to the configuration endpoint in AWS elasticache's redis cluster.
這篇關于帶有 laravel 5.5 的 Predis“Aggregate/RedisCluster.php:337 中的池中沒有可用連接"的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!