Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,45 @@ Finally, set up your redis secrets based on instructions in `wrangler.toml`.

Depending on your usage, you may try replacing Redis with [Cloudflare KV](https://developers.cloudflare.com/workers/runtime-apis/kv/) instead which is eventually consistent but will likely provide better read latency. Check `wrangler.toml` for setup instructions.

### Caching with Local/Self-Hosted Redis

In addition to Upstash Redis and Cloudflare KV, you can configure the proxy to use a local or self-hosted Redis instance for caching. This is useful for development or if you prefer to manage your own Redis server.

**Configuration:**

To use a local Redis instance, ensure that `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN` are **not** set. Then, configure the following environment variables:

* `LOCAL_REDIS_URL`: The hostname or IP address of your Redis server (e.g., `"127.0.0.1"`).
* `LOCAL_REDIS_PORT`: (Optional) The port number for your Redis server. Defaults to `6379` if not specified by `ioredis`.
* `LOCAL_REDIS_PASSWORD`: (Optional) The password for your Redis server, if it's password-protected.

**Setting Environment Variables:**

* **For deployed workers:** Set these as secrets using Wrangler CLI or the Cloudflare dashboard:
```bash
wrangler secret put LOCAL_REDIS_URL
# Enter your Redis host when prompted
wrangler secret put LOCAL_REDIS_PORT
# Enter your Redis port when prompted (optional)
wrangler secret put LOCAL_REDIS_PASSWORD
# Enter your Redis password when prompted (optional)
```
* **For local development (`wrangler dev`):**
* The recommended way is to create a `.dev.vars` file in your project root:
```ini
LOCAL_REDIS_URL="127.0.0.1"
LOCAL_REDIS_PORT=6379
# LOCAL_REDIS_PASSWORD="yourpassword" # Uncomment if needed
```
* Alternatively, you can add them to the `[vars]` section in your `wrangler.toml` file (less common for local secrets).

**Priority Order for Cache:**

The worker will choose the caching mechanism based on the following priority:
1. Upstash Redis (if `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN` are set)
2. Local/Self-Hosted Redis (if `LOCAL_REDIS_URL` is set and Upstash is not)
3. Cloudflare KV (if `OPENAI_CACHE` is bound and neither Upstash nor Local Redis are configured)

### Usage

Start the proxy server at http://localhost:8787 with:
Expand Down
Loading