Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I connect directly to a Redis server from JavaScript running in a browser?

I know there are node.js libraries for Redis; what I'd like to do is run a Redis server (either on localhost or on a server host somewhere) and call it directly via HTTP (i.e. AJAX or HTTP GET as needed) from JavaScript running inside a browser (i.e. a Greasemonkey or Chrome Extension script, or maybe a bookmarklet or SCRIPT tag). Does Redis have a native REST or HTTP API?

like image 271
AlexChaffee Avatar asked Apr 22 '11 19:04

AlexChaffee


People also ask

How do I connect to Redis locally?

To start Redis client, open the terminal and type the command redis-cli. This will connect to your local server and now you can run any command. In the above example, we connect to Redis server running on the local machine and execute a command PING, that checks whether the server is running or not.

Does Redis have a REST API?

REST Redis Service provides an easy-to-use and powerful way to create REST API calls to the Redis server.


2 Answers

You can't connect directly to Redis from JavaScript running in a browser because Redis does not speak HTTP. What you can do is put webdis in front of Redis, it makes it possible work with a Redis instance over a HTTP interface.

like image 143
Theo Avatar answered Oct 12 '22 22:10

Theo


You can literally connect to the redis server over http, and there's a security exploit based on this.

Redis is effectively a HTTP server -- http://benmmurphy.github.io/blog/2015/06/04/redis-eval-lua-sandbox-escape/

Maybe this could be used to make a javascript client for redis? In the examples shown, commands are sent directly to the redis server, which executes them. However, practically speaking, you can use openresty+nginx in front of redis to essentially directly talk to redis over http, and get the performance benefit of nginx's multithreaded server which will share a limited set of connections to redis itself.

like image 23
eyeApps LLC Avatar answered Oct 12 '22 20:10

eyeApps LLC