Home Reference Source Test Repository

Function

Static Public Summary
public

checkStatus(response,: Object): Object

Check for 2xx response.status after fetch; used by request()

public

set common options for all webdis/redis requests

public

del(keys: ...string): Promise<number, Error>

deletes keys on the redis server (via DEL)

public

echo(message: string): Promise<string, Error>

echo message

public

Convenience function equivalent to new Hash(k)

public

Convenience function equivalent to new Key(k) to save typing "new" over and over

public

lists all keys or keys matching a pattern (via KEYS)

public

list(k: *): Object

convenience function equivalent to new List(k) to keep from typing "new" all the time

public

mget(redis: ...string): Promise<string[], Error>

read multiple redis keys via MGET

public

set multiple redis keys from javascript object via MSET

public

set multiple redis keys if and only if none of the keys exist; sets all of the keys or none (via MSETNX)

public

return an existing key at random (via RANDOMKEY)

public

request(command: Array, endPoint: string): Promise<Object, MyError>

send a command array to webdis, return a Promise of a javascript object response.

public

rset(k: *): Object

Convenience function equivalent to new Rset(k), to avoid typing "new" over and over

public

select(index: *): Promise<Array, Error>

select which redis database to use for this connection (via SELECT).

public

Pass non-objects unaltered, JSON.stringify objects/arrays.

public

JSON.parse stringified response into objects, pass unparseable content as is.

Static Public

public checkStatus(response,: Object): Object source

import {checkStatus} from 'webdismay/src/index.js'

Check for 2xx response.status after fetch; used by request()

Params:

NameTypeAttributeDescription
response, Object

presumably from fetch.then()

Return:

Object

response if 2xx

Throw:

Error

with response.statusText if not 2xx

public configure(o: Object): Object source

import {configure} from 'webdismay/src/index.js'

set common options for all webdis/redis requests

Params:

NameTypeAttributeDescription
o Object

configuration options

o.method string
  • optional
  • default: "POST"

request HTTP method may be set to GET or POST. Some test frameworks (e.g.karma) seem to have difficulty proxying POST and need GET. POST is recommended for production to avoid cache issues.

o.endPoint string
  • optional
  • default: "/"

fetch URL where webdis is listening for requests

o.credentials string
  • optional
  • default: "same-origin"

fetch option determining whether to send http-auth or other credentials with each request

o.headers Object
  • optional

fetch option setting headers (e.g. accept, content-type) for each fetch. Default sets headers for 'application/json'

o.preProcess function(cmdAndParams: Array): string
  • optional

function to determine a URL-like string representing an array containing a redis command string and parameters.

o.postProcess function(response: Object): Object
  • optional

function to transform response objects received by fetch, after transforming to JSON and dereferencing webdis object return

Return:

Object

resulting configuration settings

public del(keys: ...string): Promise<number, Error> source

import {del} from 'webdismay/src/index.js'

deletes keys on the redis server (via DEL)

Params:

NameTypeAttributeDescription
keys ...string

Keys to remove.

Return:

Promise<number, Error>

response is number of keys actually deleted

public echo(message: string): Promise<string, Error> source

import {echo} from 'webdismay/src/index.js'

echo message

Params:

NameTypeAttributeDescription
message string

Return:

Promise<string, Error>

a promise resolving to the echoed message as the server returns it

public hash(k: string): Object source

import {hash} from 'webdismay/src/index.js'

Convenience function equivalent to new Hash(k)

Params:

NameTypeAttributeDescription
k string

Key name

Return:

Object

equivalent to new Hash(k)

public key(k: string): Object source

import {key} from 'webdismay/src/index.js'

Convenience function equivalent to new Key(k) to save typing "new" over and over

Params:

NameTypeAttributeDescription
k string

Key name

Return:

Object

key handler = new Key(k)

public keysMatching(pattern: String): Promise<string[], Error> source

import {keysMatching} from 'webdismay/src/index.js'

lists all keys or keys matching a pattern (via KEYS)

Params:

NameTypeAttributeDescription
pattern String
  • optional
  • default: '*'

pattern to match

Return:

Promise<string[], Error>

response is array of keys

public list(k: *): Object source

import {list} from 'webdismay/src/index.js'

convenience function equivalent to new List(k) to keep from typing "new" all the time

Params:

NameTypeAttributeDescription
k *

Key

Return:

Object

new List(k)

public mget(redis: ...string): Promise<string[], Error> source

import {mget} from 'webdismay/src/index.js'

read multiple redis keys via MGET

Params:

NameTypeAttributeDescription
redis ...string

keys to read

Return:

Promise<string[], Error>

a promise resolving to an array of values

public mset(obj: Object): Promise<Array, Error> source

import {mset} from 'webdismay/src/index.js'

set multiple redis keys from javascript object via MSET

Params:

NameTypeAttributeDescription
obj Object

An object whose keys and (stringified) values are to be set on the redis server

Return:

Promise<Array, Error>

response is an array of [true|false, message]

public msetnx(obj: Object): Promise<number, Error> source

import {msetnx} from 'webdismay/src/index.js'

set multiple redis keys if and only if none of the keys exist; sets all of the keys or none (via MSETNX)

Params:

NameTypeAttributeDescription
obj Object

An object whose keys and (stringified) values are all to be set or none set.

Return:

Promise<number, Error>

response is 1 on success, 0 on failure

public randomKey(): Promise<string, Error> source

import {randomKey} from 'webdismay/src/index.js'

return an existing key at random (via RANDOMKEY)

Return:

Promise<string, Error>

response is a key chosen at random by the server

public request(command: Array, endPoint: string): Promise<Object, MyError> source

import {request} from 'webdismay/src/index.js'

send a command array to webdis, return a Promise of a javascript object response. Put each redis command parameter in its own slot in the command array, ideally it will be automatically stringified and encoded as needed. The response object depends on which redis command was called.

Params:

NameTypeAttributeDescription
command Array

Array of command parameters.

endPoint string
  • optional
  • default: options.endPoint

endpoint URL for POST to webdis

Return:

Promise<Object, MyError>

Promise that resolves to webdis requested data or status

public rset(k: *): Object source

import {rset} from 'webdismay/src/index.js'

Convenience function equivalent to new Rset(k), to avoid typing "new" over and over

Params:

NameTypeAttributeDescription
k *

Key

Return:

Object

new Rset(k)

public select(index: *): Promise<Array, Error> source

import {select} from 'webdismay/src/index.js'

select which redis database to use for this connection (via SELECT). Untested!

Params:

NameTypeAttributeDescription
index *

number of database

Return:

Promise<Array, Error>

status response

public stringifyObjects(x: Object | Array | number | string): number | string source

import {stringifyObjects} from 'webdismay/src/index.js'

Pass non-objects unaltered, JSON.stringify objects/arrays. Shallow. Used by request preProcessing

Params:

NameTypeAttributeDescription
x Object | Array | number | string

Input

Return:

number | string

x JSON.stringified input if input is object/array, otherwise pass input

public tryParseObjects(x: Object | Array | number | string): Object | Array | number | string source

import {tryParseObjects} from 'webdismay/src/index.js'

JSON.parse stringified response into objects, pass unparseable content as is. Used as default request postProcessing.

Params:

NameTypeAttributeDescription
x Object | Array | number | string

Input

Return:

Object | Array | number | string

parsed output