From e7ac17fc47a8b82d88bdd20436bb63c236b12084 Mon Sep 17 00:00:00 2001 From: Yanis HESSINI <yanis.hessini@isaan.fr> Date: Sat, 19 Nov 2022 21:24:20 +0100 Subject: [PATCH] Redis ajout, suppression et modifiation des taches --- docker-compose.yml | 22 +++++++++++++++------- dockerfile_postgres | 1 + dockerfile_redis | 4 ++++ redis_rdb/dump.rdb | Bin 0 -> 335 bytes redis_rdb/test | 0 www/data/memo.json | 2 +- www/data/redis_data/taches.redis | 5 +++++ www/index.php | 15 +++++++++++---- 8 files changed, 37 insertions(+), 12 deletions(-) create mode 100644 dockerfile_redis create mode 100644 redis_rdb/dump.rdb create mode 100644 redis_rdb/test create mode 100644 www/data/redis_data/taches.redis diff --git a/docker-compose.yml b/docker-compose.yml index 937ceab..5c25480 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '3.9' services: - nginx: + nginx-memo: image: nginx:stable-alpine container_name: nginx-memo volumes: @@ -9,7 +9,7 @@ services: - "./log:/var/log/nginx" - "./nginx.conf:/etc/nginx/nginx.conf:ro" ports: - - published: 80 + - published: 85 target: 80 networks: - databases @@ -17,6 +17,10 @@ services: php: build: dockerfile: dockerfile_php + depends_on: + - redis-memo + - postgresql-memo + - nginx-memo container_name: php-memo volumes: - "./www:/script" @@ -39,22 +43,26 @@ services: - "postgres_data:/var/lib/postgresql/data" networks: - databases - # command: echo "fuck" & - # command: psql -U user -d postgres -f postgresqldata/data/datapostgres.sql redis-memo: - image: redis:latest + build: + dockerfile: dockerfile_redis + restart: unless-stopped container_name: redis-memo ports: - published: 6379 target: 6379 volumes: - - ./www/data/redis_data:/redisdata/data:rw + - ./www/data/redis_data/taches.redis:/redisdata/data/taches.redis + - ./redis_rdb:/redisdata/rdb + - redis_data:/data networks: - databases + # command: redis-server --dbfilename dump.rdb --dir /data + - adminer: + adminer-memo: image: adminer restart: unless-stopped container_name: adminer-memo diff --git a/dockerfile_postgres b/dockerfile_postgres index 68cd105..28d0182 100644 --- a/dockerfile_postgres +++ b/dockerfile_postgres @@ -1,2 +1,3 @@ FROM postgres:latest + USER postgres \ No newline at end of file diff --git a/dockerfile_redis b/dockerfile_redis new file mode 100644 index 0000000..5b324d8 --- /dev/null +++ b/dockerfile_redis @@ -0,0 +1,4 @@ +FROM redis:latest + +COPY ./redis_rdb/dump.rdb /data/dump.rdb +COPY ./redis_rdb/test /data/test \ No newline at end of file diff --git a/redis_rdb/dump.rdb b/redis_rdb/dump.rdb new file mode 100644 index 0000000000000000000000000000000000000000..30b5c2920940059214b67fac60d3ad2ad1b3f6d3 GIT binary patch literal 335 zcmaLRze>YE9Ki8QOQ9CJh#=jL?kV>tm&8mh=-_If;Bxs@PLsQsO9h|9#nsWbDD9iL zxH?BLHdLL&^*em{UR|7DE(xKeIjSJj&cBCh5Y5O;G^0aEb?r9uW}s?a!1k3qsAjl! zkog4^+xTsanxV8SKa~zP=o5YP(eXIsQ78f)3Z6!h*PAaE2%$cDWP~xFQlCbciiGoo zk`v@Tue8w>&Lu9Z-HQWL%UWB5!C+~wbE)05{V`dpq!iri#qpmcOT^ipeEKF~Pud%( yaR%5}cb89oB~C>kc<|pH5#60EyDg>Ru(;OFNu!`6GplZ)nzrrIOv=%Fd-?_I?`3xY literal 0 HcmV?d00001 diff --git a/redis_rdb/test b/redis_rdb/test new file mode 100644 index 0000000..e69de29 diff --git a/www/data/memo.json b/www/data/memo.json index 7667064..1609ee2 100644 --- a/www/data/memo.json +++ b/www/data/memo.json @@ -1 +1 @@ -{"5defb94651ea3":{"texte":"finir le tp de prog web","accomplie":true,"dateAjout":"2019-12-10T15:27:02.000Z"},"5defb9a88e9a3":{"texte":"finir le tp d'animation ","accomplie":false,"dateAjout":"2019-12-10T15:28:40.000Z"},"5defbc36499e1":{"texte":"finir le tp de design","accomplie":true,"dateAjout":"2019-12-10T15:39:34.000Z"},"5defbc4b20c23":{"texte":"finir le tp de bdd","accomplie":false,"dateAjout":"2019-12-10T15:39:55.000Z"},"5defbc7418ff8":{"texte":"finir le tp de vid\u00e9o ","accomplie":true,"dateAjout":"2019-12-10T15:40:36.000Z"},"63763c41d6d4f":{"texte":"pr\u00e9parer la pr\u00e9sentation d'anglais","accomplie":true,"dateAjout":"2022-11-17 13:50:57"},"63764775e6206":{"texte":"finir projet nosql","accomplie":false,"dateAjout":"2022-11-17 14:38:45"},"637648750c469":{"texte":"finir projet web services","accomplie":false,"dateAjout":"2022-11-17 14:43:01"},"637648842e03f":{"texte":"appr\u00e9cier la puissance de docker","accomplie":false,"dateAjout":"2022-11-17 14:43:16"},"637652f339886":{"texte":"finir le projet nosql","accomplie":false,"dateAjout":"2022-11-17 15:27:47"},"6376543653b77":{"texte":"finir la pr\u00e9sentation en anglais","accomplie":false,"dateAjout":"2022-11-17 15:33:10"},"6376587328a8d":{"texte":"test","accomplie":false,"dateAjout":"2022-11-17 15:51:15"},"6376543154534":{"accomplie":true}} \ No newline at end of file +{"5defb94651ea3":{"texte":"finir le tp de prog web","accomplie":true,"dateAjout":"2019-12-10T15:27:02.000Z"},"5defb9a88e9a3":{"texte":"finir le tp d'animation ","accomplie":false,"dateAjout":"2019-12-10T15:28:40.000Z"},"5defbc36499e1":{"texte":"finir le tp de design","accomplie":true,"dateAjout":"2019-12-10T15:39:34.000Z"},"5defbc4b20c23":{"texte":"finir le tp de bdd","accomplie":false,"dateAjout":"2019-12-10T15:39:55.000Z"},"5defbc7418ff8":{"texte":"finir le tp de vid\u00e9o ","accomplie":true,"dateAjout":"2019-12-10T15:40:36.000Z"},"63763c41d6d4f":{"texte":"pr\u00e9parer la pr\u00e9sentation d'anglais","accomplie":true,"dateAjout":"2022-11-17 13:50:57"},"63764775e6206":{"texte":"finir projet nosql","accomplie":false,"dateAjout":"2022-11-17 14:38:45"},"637648750c469":{"texte":"finir projet web services","accomplie":false,"dateAjout":"2022-11-17 14:43:01"},"637648842e03f":{"texte":"appr\u00e9cier la puissance de docker","accomplie":false,"dateAjout":"2022-11-17 14:43:16"},"637652f339886":{"texte":"finir le projet nosql","accomplie":false,"dateAjout":"2022-11-17 15:27:47"},"6376543653b77":{"texte":"finir la pr\u00e9sentation en anglais","accomplie":true,"dateAjout":"2022-11-17 15:33:10"},"6376587328a8d":{"texte":"test","accomplie":false,"dateAjout":"2022-11-17 15:51:15"},"6376543154534":{"accomplie":false},"6376542bcaa53":{"accomplie":false},"6379276f2048f":{"texte":"test","accomplie":false,"dateAjout":"2022-11-19 18:58:55"},"63792c429807b":{"texte":"test","accomplie":false,"dateAjout":"2022-11-19 19:19:30"},"6379310f77d68":{"texte":"test","accomplie":false,"dateAjout":"2022-11-19 19:39:59"}} \ No newline at end of file diff --git a/www/data/redis_data/taches.redis b/www/data/redis_data/taches.redis new file mode 100644 index 0000000..caa373a --- /dev/null +++ b/www/data/redis_data/taches.redis @@ -0,0 +1,5 @@ +select 0 + +LPUSH 6376542bcaa53 "finir le projet de nosql" "0" "2022-11-17 15:32:59" +LPUSH 6376543653b77 "finir la présentation en anglais" "0" "2022-11-17 15:33:10" +LPUSH 6376543154534 "apprécier la puissance de docker" "0" "2022-11-17 15:33:05" diff --git a/www/index.php b/www/index.php index 3c2b2e0..401aa30 100644 --- a/www/index.php +++ b/www/index.php @@ -35,6 +35,9 @@ $db_connection = new PDO($config, $username, $password); $redis = new Redis(); $redis->connect('redis-memo', 6379); +$redisDbIdTaches = 0; +$redisDbIdChat = 1; + $tachesFichier = "data/memo.json"; $tachesJSON = file_get_contents($tachesFichier); @@ -91,7 +94,8 @@ if (isset($_POST["texteTache"])) { // Insert dans redis - + $redis->select($redisDbIdTaches); + $redis->rpush($idTache, $texte, 0, $dateHeureTache); } @@ -155,8 +159,10 @@ if (isset($_GET["action"]) && $_GET["action"]=="basculer" && isset($_GET["id"])) ]); // Basculer dans redis - + $redis->select($redisDbIdTaches); + $redis->lset($_GET["id"], 1, $tache["accomplie"] ? 0 : 1); + $tachesJSON = json_encode($tachesArray); file_put_contents($tachesFichier, $tachesJSON); @@ -176,7 +182,8 @@ if (isset($_GET["action"]) && $_GET["action"]=="supprimer" && isset($_GET["id"]) // Supprimer dans redis - + $redis->select($redisDbIdTaches); + $redis->del($_GET["id"]); $tachesJSON = json_encode($tachesArray); @@ -184,7 +191,7 @@ if (isset($_GET["action"]) && $_GET["action"]=="supprimer" && isset($_GET["id"]) file_put_contents($tachesFichier, $tachesJSON); } -$sql = "SELECT * FROM taches"; +$sql = "SELECT * FROM taches ORDER BY accomplie ASC, date_ajout DESC"; $stmt = $db_connection->prepare($sql); $stmt->execute(); $tachesArrayDb = $stmt->fetchAll(PDO::FETCH_ASSOC); -- GitLab