This has been asked before at
Can I connect directly to a Redis server from JavaScript running in a browser?
(notice my comment)
and
Connecting directly to Redis with (client side) javascript?
but I wonder about something which would have perfect realtime connection. Reading the (a node-redis client) https://github.com/luin/ioredis source I noticed the net
part of node`s library is likely containing the kind of functionality we'd need to reproduce in the browser to do this .
Guessing maybe something with hacked together from pieces of webrtc functions could do it ?
Prospective benefits relate to building large distributed app systems infrastructure -- like social media (from comment on first question linked above):
I'm asking this question again, but stipulating we want a 'real' as in realtime redis-client -- not HTTP anything -- operating in the browser. Could build a great realtime 'infrastructure' with just CDN serving assets constituting the client webapp communicating with Redis directly. I want to cut out the unnecessary WebSocket server aspect of the system. All the control logic can be internalised to redis cluster in Lua.
To implement a direct redis-client in the web-browser you need to change Redis itself, so it will expose WebSocket interface. That way you will get the simplest protocol browser is allowed to use.
Other approaches will involve intermediate layers. I think it should be possible to proxy commands via ws-tcp-relay which is pretty fast.
来源:https://stackoverflow.com/questions/33241247/what-would-it-take-to-implement-a-good-redis-client-in-the-web-browser