問題描述
有沒有辦法使用客戶端(不是 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?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!