Skip to content

How can I make subscriptions with Redis? #1042

Answered by Teajey
Teajey asked this question in Q&A
Discussion options

You must be logged in to vote

Awesome! Thanks to @tyranron's help I seem to have got it working with an asynchronous solution using redis::aio:

    async fn new_trivia_question(
        context: &Context,
    ) -> FieldResult<Pin<Box<dyn Stream<Item = FieldResult<UnansweredTriviaQuestion>> + Send>>>
    {
        let redis_url = context.config.redis_url.clone();

        let mut pubsub = data::async_connect_redis(&redis_url).await?.into_pubsub();
        pubsub.subscribe("new_trivia_question").await?;

        let stream = pubsub
            .into_on_message()
            .map(|m| {
                m.get_payload::<UnansweredTriviaQuestion>()
                    .map_err(|e| FieldError::from(e))
            })

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
5 replies
@Teajey
Comment options

@Teajey
Comment options

@tyranron
Comment options

@Teajey
Comment options

@tyranron
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by Teajey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants