redbase icon indicating copy to clipboard operation
redbase copied to clipboard

Upstash Adapter

Open chronark opened this issue 1 year ago • 1 comments

  • refactor(adapters): switch from abstract classes to interfaces
  • feat(adapters): add upstash-rest adapater

I've chosen to go without dependencies here, because the @upstash/redis client is not as low level as the existing interfaces require and aims to provide a better typescript dx compared to existing clients like ioredis.

Instead this simply uses fetch and provides a small wrapper to implement the existing interfaces without having to convert types back and forth.

Caveat: If you're on node<18, you need a fetch polyfill.

So far I tried it with one of the example in the readme. and it worked great but we need to update the tests as well in order to test against upstash instead of a local redis db.

import { Upstash, Redbase } from 'redbase'



interface User {
  id: number
  name: string
}
interface Post {
  content: string
  userId: number
}

const redis = new Upstash({ url, token })
const users = new Redbase<User>('myProject-user', { redis })
const posts = new Redbase<Post>('myProject-post', { redis })

chronark avatar Mar 19 '23 10:03 chronark

looks good from a first pass - is there a way to do tests using a mock upstash API, or one that wraps ioredis?

alexanderatallah avatar Mar 22 '23 22:03 alexanderatallah