Skip to content

littlebits/redis-graph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Circle CI

Redis Graph

CRUD actions against a graph model built on top of Redis.

Installation

npm install --save @littlebits/redis-graph

API

RedisGraph (default)

RedisGraph :: Settings -> GraphAPI

Settings

Settings :: {...}

A dict of settings to use and customize the graph API. If you are going to interact with the key settings then be sure to read Customizing Key Names. If you are just interested in what the key defaults are take a look at the source code responsible for resolving it.

Settings.db
db :: RedisClient

Required. An instance of ioredis.

Settings.keyNamespace
keyNamespace :: String

Optional. Defaults to graph. The key to prefix before all keys entered into Redis. Also used as the channel name prefix where graph changes are published too.

Settings.keyNode
keyNode :: FormatPattern

Optional. The key pattern for endpoints.

Settings.keyFrom
keyFrom :: FormatPattern

Optional. The key pattern for a publisher-position endpoint’s index of subscriber-position endpoints.

Settings.keyTo
keyTo :: FormatPattern

Optional. The key pattern for a subscriber-position endpoint’s index of publisher-position endpoints.

Settings.keyData
keyData :: FormatPattern

Optional. The key pattern for edge data.

GraphAPI

An API object of all the graph functions that will use the given redis connection. The following functions detail this API:

create
create :: Edge -> Promise Edge

Using the endpoints in the given edge create an edge between them using the given edge data. The given edge’s publisher/subscriber endpoints will be automatically created if they do not exist.

createStrict
createStrict :: Edge -> Promise Edge

Same as create except the given edge’s publisher/subscriber endpoints are not automatically created; Instead a ErrorNoSuchEndpoint is thrown if either does not exist. Can throw error ErrorNoSuchEndpoint.

getBetween
getBetween :: SID, PID -> Promise Edge

Returns the edge between the given endpoints. Can throw error ErrorNoSuchEdge.

getFrom
getFrom :: PID -> Promise [Edge]

Returns all edges where the given endpoint is in publisher position. Can throw error ErrorNoSuchEndpoint.

getTo
getTo :: SID -> Promise [Edge]

Returns all edges where the given endpoint is in subscriber position. Can throw error ErrorNoSuchEndpoint.

getAll
getAll :: ID -> Promise [Edge]

Returns all edges where the given endpoint is in either subscriber or publisher position. Can throw error ErrorNoSuchEndpoint.

update
update :: Edge -> Promise Edge

The endpoints in the given edge will be used to lookup the current edge and once found the current edge data will be replaced with the given edge’s data. Can throw error ErrorNoSuchEdge.

destroy
destroy :: SID, PID -> Promise Edge

Returns the destroyed edge. Can throw error ErrorNoSuchEdge.

endpointDestroy
endpointDestroy :: ID -> Promise [Edge]

Returns all the edges that were destroyed. Can throw error ErrorNoSuchEndpoint.

endpointCreate
endpointCreate :: ID -> Promise ID

Creating endpoints is idempotent so no error is thrown if it already exists.

Guide

Customizing Key Names

If you are interested in using custom key names note the following. Individual naming given for a specific key will not have the namespace prefixed. This is so that you have maximum control and we think that customizing the key names is a low-level niche use-case that warrants our no-magic approach. The value given will be processed through format. Your key names must supply %s interpolation variables where you would like the key variables to be placed in your naming scheme. All keys only require a single interpolation variable except keyData which requires two. You may want to review the source code for key names to fully understand the system.

Change Feeds

All graph functions cause their changes to be published via Redis PubSub over a channel that by default is named graph:changes (see Settings.keyNamespace). The value published is always a JSON stringified array of GraphChange objects. The model design is based on RethinkDB Change Feeds.

Types

ID | PID | SID

String

PID is an endpoint in publisher position. SID is an endpoint in subscriber position. ID is an endpoint that can be in either position.

Edge

sid  :: String
pid  :: String
data :: Object

ErrorNoSuchEdge

message :: String
code    :: 'REDIS_GRAPH_NO_SUCH_EDGE'

ErrorNoSuchEndpoint

message :: String
code    :: 'REDIS_GRAPH_NO_SUCH_ENDPOINT'

GraphChange

before :: Null | Edge
after  :: Null | Edge

About

CRUD actions against a graph model built on top of Redis

Resources

License

Stars

Watchers

Forks

Packages

No packages published