Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add upstash-redis driver #289

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Conversation

Hebilicious
Copy link
Member

@Hebilicious Hebilicious commented Aug 17, 2023

πŸ”— Linked issue

Resolves #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)
  • ✨ 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 #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

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

@codecov
Copy link

codecov bot commented Aug 17, 2023

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%.

❗ 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

@chronark
Copy link

chronark commented Oct 1, 2023

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 :)

@Hebilicious
Copy link
Member Author

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

@atinux
Copy link
Member

atinux commented Oct 9, 2023

Do you mind resolving the conflicts @Hebilicious ?

@Hebilicious
Copy link
Member Author

Hebilicious commented Oct 9, 2023

Do you mind resolving the conflicts @Hebilicious ?

Sure. For full context, when vercel-kv was added in #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.

.env.example Outdated Show resolved Hide resolved
docs/content/6.drivers/redis.md Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can simplify driver name to upstash with an alias to upstash-redis as this is only upstash/kv storage option now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the changes here and in the docs. I still think for future proof we should be explicit with then name, as upstash could add a new product that unstorage could support.

src/drivers/redis-upstash.ts Outdated Show resolved Hide resolved
src/types.ts Outdated Show resolved Hide resolved
@pi0
Copy link
Member

pi0 commented Oct 9, 2023

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
Copy link
Member

pi0 commented Oct 9, 2023

Thanks for the updates @Hebilicious ❀️

@chronark
Copy link

@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

@pi0 pi0 changed the title feat: add upstash redis driver feat: add upstash-redis driver May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[driver request] upstash redis
4 participants