Git Product home page Git Product logo

Comments (7)

coreh avatar coreh commented on May 9, 2024 20

Since Vercel KV is based on the @upstash/redis library, you can use Serverless Redis HTTP (SRH) to run a local HTTP endpoint for development. (See: https://docs.upstash.com/redis/sdks/javascriptsdk/developing-or-testing)

This is my current docker-compose.yml setup:

version: '3.1'

services:
  redis:
    image: redis
    ports:
      - '6379:6379'

  serverless-redis-http:
    ports:
      - '8079:80'
    image: hiett/serverless-redis-http:latest
    environment:
      SRH_MODE: env
      SRH_TOKEN: example_token
      SRH_CONNECTION_STRING: 'redis://redis:6379' # Using `redis` hostname since they're in the same Docker network.

You can then connect with the following environment variables:

KV_REST_API_URL="http://localhost:8079"
KV_REST_API_TOKEN="example_token"

from edge-config.

vvo avatar vvo commented on May 9, 2024 13

Hey there, we're looking at adding pages for both postgres and kv about local development, will keep you posted

from edge-config.

sebpalluel avatar sebpalluel commented on May 9, 2024

Since Vercel KV is based on the @upstash/redis library, you can use Serverless Redis HTTP (SRH) to run a local HTTP endpoint for development. (See: https://docs.upstash.com/redis/sdks/javascriptsdk/developing-or-testing)

This is my current docker-compose.yml setup:

version: '3.1'

services:
  redis:
    image: redis
    ports:
      - '6379:6379'

  serverless-redis-http:
    ports:
      - '8079:80'
    image: hiett/serverless-redis-http:latest
    environment:
      SRH_MODE: env
      SRH_TOKEN: example_token
      SRH_CONNECTION_STRING: 'redis://redis:6379' # Using `redis` hostname since they're in the same Docker network.

You can then connect with the following environment variables:

KV_REST_API_URL="http://localhost:8079"
KV_REST_API_TOKEN="example_token"

Thanks for your solution, I will try it out !
That would be good to have it in the doc as it was clearly an issue that kept me out of using this service on the first place.

from edge-config.

tweeres04 avatar tweeres04 commented on May 9, 2024

Since Vercel KV is based on the @upstash/redis library, you can use Serverless Redis HTTP (SRH) to run a local HTTP endpoint for development. (See: https://docs.upstash.com/redis/sdks/javascriptsdk/developing-or-testing)

Upstash developing or testing page has moved to: https://upstash.com/docs/oss/sdks/ts/redis/developing

from edge-config.

jpchavat avatar jpchavat commented on May 9, 2024

Hey there, we're looking at adding pages for both postgres and kv about local development, will keep you posted

any progress, @vvo ?

from edge-config.

0x33dm avatar 0x33dm commented on May 9, 2024

Hey there, we're looking at adding pages for both postgres and kv about local development, will keep you posted

any progress, @vvo ?

Not being able to work offline is a deal breaker.

Being able to run tests offline is quite an important when developing an API.

from edge-config.

kerkkoh avatar kerkkoh commented on May 9, 2024

@0x33dm The docker container solution by @coreh above works as of 2024-04-20. Simply download Docker desktop, and in your project directory root, create a file called docker-compose.yml and copy & paste the contents:

version: '3.1'

services:
  # This is the local Redis database that will be running on your computer; Within docker it has the hostname `redis` and it exposes the port 6379 to your pc and other containers
  redis:
    image: redis
    ports:
      - '6379:6379'

  # This is the serverless router that allows the Vercel KV libraries to send queries to the redis server above (redis:6379)
  # It uses the port 80 internally, so it is mapped to an arbitrary port 8079, so that it doesn't conflict with your potential web app on port 80
  # Think of this as local Vercel KV, and you could even rename this to local-vercel-kv if that helps you to understand this structure
  serverless-redis-http:
    ports:
      - '8079:80'
    image: hiett/serverless-redis-http:latest
    environment:
      SRH_MODE: env
      SRH_TOKEN: example_token # This is your local Vercel KV instance's API token (KV_REST_API_TOKEN), and you can change it to anything or keep it as is for development
      SRH_CONNECTION_STRING: 'redis://redis:6379' # Using `redis` hostname since they're in the same Docker network.

Now when you have Docker Desktop (or other version of Docker) installed and running, simply open up a command line (bash/cmd/terminal) and navigate to the directory where you placed the docker-compose.yml file, and execute the following command:

docker-compose up

Now you should see Docker downloading the needed images, and ultimately the local Vercel KV instance starts running.

Finally, within your project of choice, expose the 2 system variables required for the @vercel/kv library to connect to your local KV instance in a .env file for example like above:

KV_REST_API_URL="http://localhost:8079"
KV_REST_API_TOKEN="example_token"

Hopefully this further explanation helps you out! This docker solution is the best one right now (and probably in the future) as you can deploy this locally on any operating system. If you have any questions, let me know.

As @tweeres04 kindly pointed out, you can also find a similar setup that will work with @vercel/kv in the Upstash documentation https://upstash.com/docs/oss/sdks/ts/redis/developing.

Vercel KV itself is simply a dumbed down wrapped version of Upstash, so generally anything that applies to Upstash will apply to Vercel KV. If you want to find out more, I'd suggest looking at what you get with Upstash directly instead of using Vercel KV as a wrapper. Disclaimer: I have nothing against Vercel KV, and use it in production

from edge-config.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.