{"id":21672518,"url":"https://github.com/redis-developer/redis-caching-slow-database-queries","last_synced_at":"2025-08-05T23:05:46.544Z","repository":{"id":46773188,"uuid":"342014898","full_name":"redis-developer/redis-caching-slow-database-queries","owner":"redis-developer","description":"Simple demonstration of caching database queries with Redis.","archived":false,"fork":false,"pushed_at":"2022-10-17T18:46:22.000Z","size":1253,"stargazers_count":8,"open_issues_count":2,"forks_count":3,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-12T03:53:08.085Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://developer.redis.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/redis-developer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-24T19:40:29.000Z","updated_at":"2024-03-07T14:19:52.000Z","dependencies_parsed_at":"2022-08-05T17:00:13.584Z","dependency_job_id":null,"html_url":"https://github.com/redis-developer/redis-caching-slow-database-queries","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/redis-developer/redis-caching-slow-database-queries","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis-developer%2Fredis-caching-slow-database-queries","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis-developer%2Fredis-caching-slow-database-queries/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis-developer%2Fredis-caching-slow-database-queries/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis-developer%2Fredis-caching-slow-database-queries/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/redis-developer","download_url":"https://codeload.github.com/redis-developer/redis-caching-slow-database-queries/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis-developer%2Fredis-caching-slow-database-queries/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268987471,"owners_count":24340667,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-05T02:00:12.334Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-25T13:29:46.576Z","updated_at":"2025-08-05T23:05:46.433Z","avatar_url":"https://github.com/redis-developer.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Caching\n\nSimple caching examples with Redis and Node.js!\n\n## Prerequisites\n\n- Node.js\n- SQLite\n- SQLite3\n- Redis\n- Docker\n\n## Installing this application\n\nClone the repository to your computer:\n\n```bash\n$ git clone https://github.com/redis-developer/redis-caching-slow-database-queries.git\n```\n\nNavigate to the NodeJS folder:\n\n```bash\n$ cd nodejs\n```\n\nInstall dependencies:\n\n```bash\n$ npm install \n```\n\n## Database Preparation\n\nEnsure you have Redis installed and running.\n\nYou can run it with Docker:\n\n```bash\n$ docker-compose up -d\n```\n\nYou can also run redis-cli in the container\n```bash\n$  docker exec -it redis-caching-slow-database-queries redis-cli\n```\n\u003e NOTE: If you're using Redis Enterprise Cloud, you'll need the hostname, port number, and password for your database.  Use these to set the `REDIS_OM_URL` environment variable like this:\n\n```bash\n$ export REDIS_OM_URL=redis://default:\u003cpassword\u003e@\u003chost\u003e:\u003cport\u003e\n```\n\n(**This step is not required when working with Docker as the Docker container** runs Redis on `localhost` port `6379` with no password, which is the default connection that Redis OM uses.)\n\nFor example if your Redis Enterprise Cloud database is at port `9139` on host `enterprise.redis.com` and your password is `5uper53cret` then you'd set `REDIS_OM_URL` as follows:\n\n\u003e You can also use redis-stack on your browser\n\n\u003e Ensure you have SQLite3 installed.\n\n### Unzip and import data to the SQLite `weather` table:\n\nUnzip the weather.csv.zip file that is in the `db` folder:\n\n```bash\n$ gzip -d db/weather.csv.zip\n```\n\nRun the Sqlite3 command line interface to import the `weather.csv` file and set empty `TAVG` values to `NULL`:\n\n```bash\n$ sqlite3\nsqlite\u003e .open db/weather.db\nsqlite\u003e .mode csv\nsqlite\u003e .import db/weather.csv weather_measurements\nsqlite\u003e UPDATE weather_measurements SET tavg = NULLIF(tavg, '');\nsqlite\u003e .quit\n```\n\nYou are now prepared to run the example file.\n\nThis CSV file was acquired from the National Centers for Environmental Information (NOAA) whose original dataset can be found [https://www.ncdc.noaa.gov/cdo-web/datasets#GHCND](here).\n\n## Running the examples\n\n### `average.js`\n\nThis file contains two functions to demonstrate caching entries from a database.  `getAverage()` retrieves the average daily average temperature recorded from numerous weather stations within Iceland recorded since 2010. Timing is collected during the function execution and added to the returned JSON object.\n\nEnsure Redis is running, then run the `averages.js` file once.  Since there is no cache entry, the function will retrieve the data from the database.\n\n```bash\n$ node average.js\n{\n  'AVG(TAVG)': 41.85745350929814,\n  source: 'database',\n  responseTime: '1735ms'\n}\n```\n\nThe code will have placed a copy of the entry in the Redis cache, so the next function execution should return data from the cache.\n\n```bash\n$ node average.js\n{\n  'AVG(TAVG)': 41.85745350929814,\n  source: 'cache',\n  responseTime: '2ms'\n}\n```\n## Shutting Down Redis (Docker)\n\nIf you're using Docker, and want to shut down the Redis container when you are finished with the application just use:\n```bash\n$ docker-compose down\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredis-developer%2Fredis-caching-slow-database-queries","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fredis-developer%2Fredis-caching-slow-database-queries","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredis-developer%2Fredis-caching-slow-database-queries/lists"}