如何在反应本机中使用服务器实现发布/订阅功能 [英] How to implement publish / subscribe feature with a server in react native

查看:52
本文介绍了如何在反应本机中使用服务器实现发布/订阅功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 redis pub/sub 在 react native 中构建一个聊天应用程序.已搜索
javascript 的 redis 客户端,但我没有得到.谁能告诉我如何在 React Native 中使用 redis pub/sub.

I'm trying to build a chat applicaton in react native using redis pub/sub. Searched
redis client for javascript but i didn't get. Can anyone let me know how to use redis pub/sub in react native.

推荐答案

你必须在后端实现 redis,而不是在前端.正如他们在网站上所说,Redis 是一个数据库这里

You have to implement redis on the backend side, not on the frontend. Redis is a database as they say on their websites here

Redis 是一个开源(BSD 许可)、内存数据结构存储,用作数据库、缓存和消息代理

Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker

对于前端,如果你想使用发布/订阅功能,你可以使用 websockets 为例.

For the frontend side if you want to use publish / subscribe feature you can use websockets for example.

这里有一些与 React Native 一起使用的好库:

Here is some good libraries to use with React Native:

在后端,您可以使用:

这是一个使用 React Native WebSockets 的例子:

Here is an example using the React Native WebSockets:

var ws = new WebSocket('wss://example.com/stuff');

ws.onopen = () => {
  // connection opened
  ws.send('Hello world'); // send a message
};

ws.onmessage = (e) => {
  // a message was received
  console.log(e.data);
};

你还有其他选择,比如长期池

You also have other alternatives, like long-pooling

这篇关于如何在反应本机中使用服务器实现发布/订阅功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆