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

redis: maybe write key to state? #722

Open
josephjclark opened this issue Aug 14, 2024 · 0 comments
Open

redis: maybe write key to state? #722

josephjclark opened this issue Aug 14, 2024 · 0 comments

Comments

@josephjclark
Copy link
Collaborator

josephjclark commented Aug 14, 2024

In redis, a really common pattern is gonna be something like this

each(
  $.data,
  jGet($.data).then(state => {
    state.results.push(state.data);
    return state;
  })
);

You iterate over a set of keys, you fetch each item, you transform it and map it to state

But what if you need the key for the item you just fetched? That's been passed to get by each but then been overwritten. If the key doesn't happen to be in data, you've lost it.

The workaround is to fetch it out of references like this:

each(
  $.data,
  jGet($.data).then(state => {
    const key = state.references.at(-1).split(':')[0];
    state.results[key].push(state.data);
    return state;
  })
);

One solution would be for all redis functions to return { key, data }, much like how http returns { response, data }. That would make the key associated with data available downstream.

If there's other metadata we might want to include, perhaps we need a meta or response to be added to state instead.

@github-project-automation github-project-automation bot moved this to New Issues in v2 Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: New Issues
Development

No branches or pull requests

1 participant