Skip to content

bug: zrange rev flag causes empty return list / flaky zrange #742

Open
@benheckmann

Description

Hi,

When using kv.zrange, the same input sometimes returns the list of values, and sometimes an empty list. When using the cli on Vercel, I always get the list.

export async function getChats(userId?: string | null) {
  const session = await auth()

  if (!userId) {
    return []
  }

  if (userId !== session?.user?.id) {
    return {
      error: 'Unauthorized'
    }
  }

  try {
    const chats: string[] = await kv.zrange(`user:chat:${userId}`, 0, -1, {
      rev: true
    })
    
    const pipeline = kv.pipeline()
    for (const chat of chats) {
      pipeline.hgetall(chat)
    }
    const results = await pipeline.exec()

    return results as Chat[]
  } catch (error) {
    return []
  }
}

I have used the debugger to make sure that the userId is the same in both cases and it passes the authentication check. However, chats sometimes evaluates to an empty list, when it should have the values I get using the cli. This is right below the line, so its not that there is an error thrown.

Not sure if this is an issue with the package or if I'm just unable to find out what the difference in the calls is when it works. In this case: is it possible to activate some sort of logging?

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions