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

publish/subscribe #7

Closed
CurtTilmes opened this issue Apr 24, 2017 · 2 comments
Closed

publish/subscribe #7

CurtTilmes opened this issue Apr 24, 2017 · 2 comments

Comments

@CurtTilmes
Copy link

What is the right way to implement publish/subscribe on top of eredis?

I tried sending a 'subscribe' command, and it works fine, but I can't call eredis_r_reply() in a blocking manner to wait for a response that hasn't come yet.

@CurtTilmes
Copy link
Author

I added this little sub and it seems to work for pub/sub, but I'm not sure I'm doing everything right..

/**
 * @brief eredis reader reply, blocking for pub/sub
 *
 * @param r     eredis reader
 *
 * @return reply (redisReply)
 */
  eredis_reply_t *
eredis_r_reply_blocking( eredis_reader_t *r )
{
    redisContext *c;
    eredis_reply_t *reply;
    int err;

    reply = NULL;

    if (!(c = _eredis_r_ctx(r, 0)))
        return NULL;

    err = redisGetReply( c, (void**)&reply );

    if (err == EREDIS_OK) {
      /* Good */
      /* Previous to clean? */
      _eredis_r_free_reply( r );
      /* New reply */
      r->reply = reply;
    } else {
      /* Bad */
      if (reply)
        freeReplyObject( reply );

      err = c->err;
    }

    return reply;
}

@CurtTilmes CurtTilmes changed the title Eredis publish/subscribe publish/subscribe Apr 24, 2017
@guillaumef
Copy link
Member

Moved to pull request #8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants