unstorage icon indicating copy to clipboard operation
unstorage copied to clipboard

feat: add `upstash-redis` driver

Open Hebilicious opened this issue 2 years ago β€’ 8 comments

πŸ”— Linked issue

Resolves https://github.com/unjs/unstorage/issues/288

❓ Type of change

  • [ ] πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • [ ] 🐞 Bug fix (a non-breaking change that fixes an issue)
  • [ ] πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • [x] ✨ New feature (a non-breaking change that adds functionality)
  • [ ] 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • [ ] ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This PR adds a upstash-redis driver for redis support on edge platforms.

For full context, when vercel-kv was added in https://github.com/unjs/unstorage/pull/213, @redis/upstash was added as a dependency because it is a vercel-kv dependency, so that makes it easier for pnpm users.

This PR adds a redis-upstash driver for the use case where you want to use upstash without vercel (which I encountered recently)

image

The tests are running locally, and need env variables to work in the CI. We should create an unjs upstash db, or mock the client.

πŸ“ Checklist

  • [x] I have linked an issue or discussion.
  • [x] I have updated the documentation accordingly.

Hebilicious avatar Aug 17 '23 12:08 Hebilicious

Codecov Report

Merging #289 (ba6ea2d) into main (60159a5) will decrease coverage by 0.60%. Report is 3 commits behind head on main. The diff coverage is 52.50%.

:exclamation: Current head ba6ea2d differs from pull request most recent head c370cbd. Consider uploading reports for the commit c370cbd to get more accurate results

@@            Coverage Diff             @@
##             main     #289      +/-   ##
==========================================
- Coverage   77.96%   77.37%   -0.60%     
==========================================
  Files          29       30       +1     
  Lines        3418     3496      +78     
  Branches      521      522       +1     
==========================================
+ Hits         2665     2705      +40     
- Misses        752      790      +38     
  Partials        1        1              
Files Coverage Ξ”
src/types.ts 100.00% <100.00%> (ΓΈ)
src/drivers/redis-upstash.ts 51.89% <51.89%> (ΓΈ)

... and 1 file with indirect coverage changes

codecov[bot] avatar Aug 17 '23 13:08 codecov[bot]

Hey there! (disclaimer: I work for upstash)

quick question: why did you install @vercel/kv and then use @upstash/redis It seems to work cause their package is just a wrapper around @upstash/redis but it seemed weird :D

secondly: we can provde a db for unit tests for free, just let me know :)

chronark avatar Oct 01 '23 09:10 chronark

Hey there! (disclaimer: I work for upstash)

quick question: why did you install @vercel/kv and then use @upstash/redis It seems to work cause their package is just a wrapper around @upstash/redis but it seemed weird :D

secondly: we can provde a db for unit tests for free, just let me know :)

Hello there! @vercel/kv is already a driver supported by unstorage, this PR doesn't install it. I didn't know their package was just a wrapper.

On providing us with a DB, I think that would be great ! @pi0 is the maintainer of unstorage, so he'll need to green light this

Hebilicious avatar Oct 02 '23 07:10 Hebilicious

Do you mind resolving the conflicts @Hebilicious ?

atinux avatar Oct 09 '23 09:10 atinux

Do you mind resolving the conflicts @Hebilicious ?

Sure. For full context, when vercel-kv was added in https://github.com/unjs/unstorage/pull/213, @redis/upstash was added as a dependency because it is a vercel-kv dependency, so that makes it easier for pnpm users to use unstorage without shamefully-hoist.

This PR adds a redis-upstash driver for the use case where you want to use upstash without vercel (which I encountered recently)

I'll add this to the PR description.

Hebilicious avatar Oct 09 '23 10:10 Hebilicious

Hi dear @chronark thanks for reaching out and for your offer about the CI plan.

I would ideally love to have a proper "unit" test for both drivers. I think we can mock the HTTP client with upstash API. If you have a tool or package that can help in this regard it would be awesome! Also, feel free to reach me via discord (pi0) if you would like to work closer on upstash integrations I can invite you to the unjs discord channel.


Off topic: Regarding vercel-kv, the main reason for having a wrapper is that it allows having "zero configuration" integration with their platform / provided environment variables - also any changes needed in the future. If there are other hosting options that provided upstash integration, we probably have to either use their packages or make a wrapper driver.

pi0 avatar Oct 09 '23 11:10 pi0

Thanks for the updates @Hebilicious ❀️

pi0 avatar Oct 09 '23 11:10 pi0

@pi0 we don't have any true unit test library or similar, I'm running all of our tests against a real upstash db or in a docker container :/

I'm leaving upstash soon, joining your discord now probably won't help much unfortunately.

if you want credits for testing against real dbs, just let us know here: [email protected] and ideally reference this comment :D

chronark avatar Oct 11 '23 09:10 chronark