使用(客户端)javascript 直接连接到 Redis? [英] Connecting directly to Redis with (client side) javascript?

查看:38
本文介绍了使用(客户端)javascript 直接连接到 Redis?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用客户端(不是 Node.js)javascript 直接连接到 Redis?

Is there a way to directly connect to Redis using client side (not Node.js) javascript?

我已经成功地将 Node.js + PHP + Redis + Socket.io(用于客户端)用于一些项目.但是,我真的认为这可以进一步简化为 PHP + Redis + Browser javascript 之类的东西 - 去掉 Node.js 服务器,它只是另一个服务器,如果没有必要,我宁愿不使用它.对于简单的事情,我认为使用Javascript直接连接到Redis会更好.

I'm already using Node.js + PHP + Redis + Socket.io (for the client) successfully for a few projects. However, I really think this could be further simplified to something like PHP + Redis + Browser javascript - taking out the Node.js server which is just another server I'd rather not use if it isn't necessary. For simple things, I think it would be better to just connect directly to Redis using Javascript.

据我所知,Redis 只是通过一个端口来处理它的请求,因此任何可以向该端口发出请求的语言都可以工作.理论上,您不能使用客户端 javascript 访问 redis 服务器的端口吗?

From what I understand, Redis just serves its request through a port so any language that can make requests to that port would work. In theory, couldn't you just hit the redis server's port using client side javascript?

我最感兴趣的是发布/订阅功能,这可能也可能不可能.

I'm mostly interested in the publish/subscribe functions, which may or may not be possible.

我不确定您是否可以使用 AJAX 访问非 80 端口,但从技术上讲,您应该能够使用 Nginx 反向代理或其他方式将 Redis 的端口转发到 80 端口.

I'm not sure if you can access a non-port 80 port using AJAX, but you technically should be able to forward Redis' port to port 80 using Nginx reverse proxy or something.

有什么想法吗?只是一个想法.我对我目前的解决方案很满意,但不知道我们是否可以做得更好或更有效.

Any ideas? Just a thought. I'm very happy with my current solution, but it doesn't hurt to wonder if we could do this even better or more efficiently.

推荐答案

您只能使用客户端 JavaScript 发出 HTTP 请求,在某些浏览器中,还可以使用 websocket.但是,您应该查看 Webdis.它为 Redis 添加了一个简单的 HTTP/JSON 层,应该完全符合您的要求.

You can only make HTTP requests with client-side JavaScript and, in some browsers, websockets. However, you should look into Webdis. It adds an easy HTTP/JSON layer to Redis and should do exactly what you want.

链接已修复.

这篇关于使用(客户端)javascript 直接连接到 Redis?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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