@gmetrixr/webdis-commands
v0.0.7
Published
[![Build Status](https://drone-xr.gmetri.io/api/badges/gmetrixr/webdis-commands/status.svg)](https://drone-xr.gmetri.io/gmetrixr/webdis-commands)
Downloads
2
Readme
webdis-commands
Client library for making webdis server requests
Exposed Commands:
- set
- get
- del
- exists
- sadd
- srem
- smember
- hset
- hget
- hmset
- hmget
- hdel
- sismember
- mget
- flushdb
- flushall
- ping
- publish
- unsubscribe
Running example
This repo uses pnpm to run, compile and build code
./sd
- start the dockerp i
- install dependencies. p is an alias for pnpmcd examples
p i
- install dependencies for examplesp watch
- start dev server. uses Snowpack
Basic Usage
import Webdis from "@gmetrixr/webdis-commands";
const options = {
db: 1, // set db index
auth: "username:passwd", // optional auth to webdis server
};
const url = "http://localhost:8003";
const webdis = new Webdis(url, options);
// execute commands
const response = await webdis.command().ping();
console.log(response); // [true, "PONG"]
Pub/Sub
import Webdis from "@gmetrixr/webdis-commands";
const options = {
db: 1, // set db index
auth: "username:passwd", // optional auth to webdis server
};
const url = "http://localhost:8003";
const webdis = new Webdis(url, options);
const channel = "process";
const cb = (data: string | object) => {
// cb should always test the typeof data here. parsing can result in either text or js objects
};
// subcsription
const id = webdis.subscribe(channel, cb);
// un-subscription
webdis.unsubscribe(channel, id); // pass the subscription id