John Davidson

php - Redis not saving data to docker container server

0 comments
Message:


I have the following docker compose configurations:


version: "3.9"
services:
redis:
image: redis:latest
volumes:
- redis_data:/var/redis/data
restart: always
environment:
ALLOW_EMPTY_PASSWORD: "yes"
REDIS_DISABLE_COMMANDS: "FLUSHDB,FLUSHALL"
ports:
- "6379:6379"
volumes:
db_data: { }
redis_data:
driver: local

In my code, I have:


public function __construct()
{
$this -> redis = new Client([
'scheme' => 'tcp',
'host' => 'localhost',
'port' => 6379
]);
}

public function connect()
{
$this -> redis -> connect();
var_dump($this -> redis -> getConnection());
$this -> redis -> set('foo', "aaa");
echo "REDIS VALUE: " . $this -> redis -> get('foo');
}

And my debugging result is:


object(Predis\Connection\StreamConnection)#18 (4) {
["resource":"Predis\Connection\AbstractConnection":private]=>
resource(149) of type (stream)
["cachedId":"Predis\Connection\AbstractConnection":private]=>
NULL
["parameters":protected]=>
object(Predis\Connection\Parameters)#16 (1) {
["parameters"]=>
array(3) {
["scheme"]=>
string(3) "tcp"
["host"]=>
string(9) "localhost"
["port"]=>
int(6379)
}
}
["initCommands":protected]=>
array(0) {
}
}
REDIS VALUE:

It seems to be connecting to the docker redis container, but the data is not saving. I'm not quite sure what the issue seems to be at this point.



My Answer:
3
services:
redis:
image: redis
ports:
- "6379:6379"
volumes:
- redis_data:/data
php:
image: php:7.4
volumes:
- ./src:/var/www/html
depends_on:
- redis
volumes:
redis_data:

I am trying to save data to the Redis server running in the docker container from my PHP application, but the data is not persisting. How can I fix this issue?

Rate this post

4 of 5 based on 2216 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us