Connecting to Vercel KV store from localhost

I am having issues connecting to a Vercel KV store I’ve recently setup. I have done the following steps…

  1. Created a Vercel kv store via Vercel’s dashboard
  2. Connected the KV store to an existing project hosting on Vercel
  3. Used the Vercel CLI to pull environment variables into an .env.development.local file. I also have the four main environment variables for KV in an .env and a .env.local file (all the same values)
  4. In my code, I am using the Vercel SDK as follows…

Whenever I reach the kv.set call, I receive the following error:
"UpstashError: DB connection refused, command was: [[“set”,“9”, “{… } ]]”

I have also tried using the “kv” export from @vercel/kv with the same effect.

Any help understanding why I am unable to connect would be appreciated! Thank you!

Hi @brandon-codeswitchco! It looks like you’ve imported kv from @vercel/kv but also assigned a const kv with createClient. That might be causing a conflict. The Vercel KV Quickstart includes some examples to help you get it set up.

I have a couple of other ideas to try if changing the import or const name didn’t solve it. If you’re not using vercel dev to run the project, give that a try. You can also try logging some of the variables from your .env.* files. Do they exist with the expected values?

Hey @amyegan, thanks for the feedback. Running vercel dev did the trick, but what’s weird is that I just stopped the localhost server and ran yarn dev again, and now it’s working there as well. Not sure what happened, but at least it’s working.

Do you know of any issues with intermittent KV access from other users by chance?

I’m glad it’s working for you! I have not seen any intermittent KV connection errors lately, but I’ll watch for them to make sure there isn’t a larger issue.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.