Closed lemarweb closed 1 year ago
Any idea about the possible fix?
Any idea about the possible fix?
Not sure, but maybe store current database index in static variable in yii\redis\Connection
.
Update this variable value when execute command 'SELECT'.
Check if database changed before get or set data, and execute 'SELECT index' again if needed.
Do you still have this problem if you remove socketClientFlags
config? I'm using Redis with socket and I haven't noticed any problems, but I'm not using any custom flags.
This is issue with STREAM_CLIENT_PERSISTENT
flag and it is documented: https://www.yiiframework.com/extension/yiisoft/yii2-redis/doc/api/2.0/yii-redis-connection#$socketClientFlags-detail
STREAM_CLIENT_PERSISTENT
Well, actually useful warning. Although, I think it is a bit strange behavior...
Another way to "fix" the problem in my case is using single redis connection for queue and cache, but with shareDatabase = true
for \yii\redis\RedisCache
Thanks everyone for your replies.
What steps will reproduce the problem?
For example it can be used to separate cache and queue databases.
Write some values in redis via
redisCacheConnection
andredisQueueConnection
:Try to get value by
key1
fromredisCacheConnection
:What's expected?
I had get a string
'value1'
(from db 0 via first connection)What do you get instead?
I got
null
(from db 1 via second connection).Because after opening second connection (
redisCacheConnection
) any request from any redis connection component is sending to last connected database.Additional info
For example: If you use
redis-cache
andredis-queue
together, push job to queue and after that flush the cache - all data about jobs will be lost (FLUSHDB
will be called on database 1 in redis), but cache will not be flushed.