https://github.com/b-goodman/redis-websocket-host
Redis HTTP interface and websocket messaging Node.js server
https://github.com/b-goodman/redis-websocket-host
nodejs redis socket-io
Last synced: 2 months ago
JSON representation
Redis HTTP interface and websocket messaging Node.js server
- Host: GitHub
- URL: https://github.com/b-goodman/redis-websocket-host
- Owner: b-goodman
- Created: 2019-05-09T04:51:51.000Z (about 7 years ago)
- Default Branch: public
- Last Pushed: 2019-05-09T04:54:07.000Z (about 7 years ago)
- Last Synced: 2025-01-24T18:35:07.260Z (over 1 year ago)
- Topics: nodejs, redis, socket-io
- Language: JavaScript
- Size: 22.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Redis Websocket Host
A rudimentery websocket server which combines [socket.io](https://socket.io/docs/) with [redis](https://redis.io/commands) to form a redis HTTP interface, and realtime messenger.
Requires an existing installation (see either [redis](https://redis.io/download) or [homebrew](https://formulae.brew.sh/formula/redis#default) )
## Redis HTTP Interface
Append any redis-cli query to the base URL, seperated by back-slashes.
E.g,
### Show all keys
```curl
GET /keys/*
{"args":["keys","*"],"response":[["search-cache","latest_activity","status","anotherkey"]]}
```
### Set a key `test` to value `hello`
```curl
GET /set/test/hello
{"args":["set","test","hello"],"response":["OK"]}
```
### Query the value of `test`
```curl
GET /get/test
{"args":["get","test"],"response":["hello"]}
```
### Delete the key `test`
```curl
GET /del/test
{"args":["del","test"],"response":[1]}
```
## Websocket Integration
Any redis key modified via the HTTP API may also be listened to via a websocket inteface.
### Node.js Client
```javascript
//The URL is the API base plus the key you want to listen to: redis-key-
const url = '/redis-key-AN_EXAMPLE_KEY';
var socket = require('socket.io-client')(url);
socket.emit("new_client", window.location.href);
socket.on("new_client", (msg) => {
console.log(msg);
});
//an update to the key emits a "local_redis_update" event.
socket.on("local_redis_update", (msg)=>{
//Do something when a message comse through
console.log(msg);
})
```
### Browser Client
```javascript
let socket = null;
$(function () {
socket = io('/redis-key-demonstrations_build_status');
socket.emit("new_client", window.location.origin);
socket.on("new_client", (msg) => {
console.log(msg)
});
});
socket.on("local_redis_update", (resp) => {
//Do something when a message comes through.
//For example, this updates a progress bar.
if(resp.key == jobTriggerID){
const print_response = (resp.p_max == resp.progress) ? `Complete. Files saved to ${resp.msg}` : `${resp.msg} category ${resp.progress} of ${resp.p_max}`;
console.log(print_response);
setProgress( parseInt(resp.progress), parseInt(resp.p_max) );
}
});
```