{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8b22a2d1",
   "metadata": {},
   "source": [
    "# Introduction\n",
    "\n",
    "Bonjour et bienvenue dans le notebook du projet sur les bases de données tablebase.\n",
    "\n",
    "Dans ce notebook. Nous allons montrer comme fonctionne le stockage d'une base de données tablebases en prenant comme exemple la table base \"syzygy\" avec comme taille  3 à 5 pièces pour des raisons de taille.\n",
    "Nous allons expliquer comment les finales ( ou position d'échecs) sont stockés dans le format key-value puis nous verrons ensuite les performances de la base à l'aide de Redis.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "78fdf40a",
   "metadata": {},
   "outputs": [],
   "source": [
    "#import du projet\n",
    "\n",
    "import redis\n",
    "import time\n",
    "import chess\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d584aba1",
   "metadata": {},
   "source": [
    "## Peuplement de Redis\n",
    "\n",
    "Dans un premier temps, on ajoute les positions de la tablebase à Redis afin de pouvoir les utilisers derrières pour faire les tests."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "338f123d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Value set. Retrieved from Redis: example_value\n",
      "Time == 1 seconds\n",
      "Retrieved from Redis: b'example_value'\n",
      "Retrieved from Redis: None\n",
      "Time == 2 seconds\n",
      "Retrieved from Redis: b'example_value'\n",
      "Retrieved from Redis: None\n",
      "Time == 3 seconds\n",
      "Retrieved from Redis: b'example_value'\n",
      "Retrieved from Redis: None\n",
      "Time == 4 seconds\n",
      "Retrieved from Redis: b'example_value'\n",
      "Retrieved from Redis: None\n",
      "Time == 5 seconds\n",
      "Retrieved from Redis: b'example_value'\n",
      "Retrieved from Redis: None\n",
      "Time == 6 seconds\n",
      "Retrieved from Redis: b'example_value'\n",
      "Retrieved from Redis: None\n",
      "Time == 7 seconds\n",
      "Retrieved from Redis: b'example_value'\n",
      "Retrieved from Redis: None\n",
      "Time == 8 seconds\n",
      "Retrieved from Redis: b'example_value'\n",
      "Retrieved from Redis: None\n",
      "Time == 9 seconds\n",
      "Retrieved from Redis: b'example_value'\n",
      "Retrieved from Redis: None\n",
      "Time == 10 seconds\n",
      "Retrieved from Redis: b'example_value'\n",
      "Retrieved from Redis: None\n"
     ]
    }
   ],
   "source": [
    "#Connect to Redis server\n",
    "\n",
    "def do_this():\n",
    "\n",
    "    redis_server = redis.Redis(host='localhost', port=6379, db=0)\n",
    "\n",
    "    #Set and get a simple key-value pair    \n",
    "\n",
    "    redis_server.set('example_key', 'example_value')\n",
    "    value = redis_server.get('example_key')\n",
    "\n",
    "    print(\"Value set. Retrieved from Redis:\", value.decode('utf-8'))\n",
    "\n",
    "    count = 1\n",
    "    while count <= 10:\n",
    "        print(f\"Time == {count} seconds\")\n",
    "        value = redis_server.get('example_key')\n",
    "        print(f\"Retrieved from Redis: {value}\")\n",
    "        print(f\"Retrieved from Redis: {redis_server.get(name = 'exemple2')}\")\n",
    "\n",
    "        count +=1\n",
    "        time.sleep(1)\n",
    "    \n",
    "if __name__ == \"__main__\":\n",
    "        do_this()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
