{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Upstash Redis\n",
    "\n",
    ">[Upstash](https://upstash.com/docs/introduction) is a provider of the serverless `Redis`, `Kafka`, and `QStash` APIs.\n",
    "\n",
    "This notebook goes over how to use `Upstash Redis` to store chat message history."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain.memory.chat_message_histories.upstash_redis import (\n",
    "    UpstashRedisChatMessageHistory,\n",
    ")\n",
    "\n",
    "URL = \"<UPSTASH_REDIS_REST_URL>\"\n",
    "TOKEN = \"<UPSTASH_REDIS_REST_TOKEN>\"\n",
    "\n",
    "history = UpstashRedisChatMessageHistory(\n",
    "    url=URL, token=TOKEN, ttl=10, session_id=\"my-test-session\"\n",
    ")\n",
    "\n",
    "history.add_user_message(\"hello llm!\")\n",
    "history.add_ai_message(\"hello user!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "history.messages"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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": 4
}
