@itsmagick/nexus-client
v1.0.2
Published
Client for connecting to Nexus Knowledge Graph
Maintainers
Readme
Nexus Client for Node.js
A Node.js client for the Nexus Knowledge Graph System. This client allows you to connect to a Nexus server and perform operations on the knowledge graph.
Installation
npm install nexus-clientUsage
Basic Connection
import { createClient } from 'nexus-client';
// Create a client
const client = createClient({
url: 'nexus://localhost:4242',
password: 'your-password'
});
// Connect to the server
await client.connect();
// Perform operations
await client.set('key', 'value');
const value = await client.get('key');
console.log(value); // 'value'
// Disconnect
await client.disconnect();Connection Options
import { createClient } from 'nexus-client';
const client = createClient({
// Use URL format
url: 'nexus://username:password@localhost:4242/0',
// Or use socket configuration
socket: {
host: 'localhost',
port: 4242
},
// Authentication
username: 'default',
password: 'your-password',
// Database selection
database: 0,
// Connection timeout
connectTimeout: 10000, // 10 seconds
// Retry strategy
retryStrategy: (times) => Math.min(times * 50, 2000)
});Working with Entities
// Create an entity
await client.hSet('entity:person:1', {
name: 'John Doe',
age: '30',
email: '[email protected]'
});
// Get an entity
const person = await client.hGetAll('entity:person:1');
console.log(person); // { name: 'John Doe', age: '30', email: '[email protected]' }Working with Relationships
// Create a relationship
await client.hSet('relationship:follows:1', {
source: 'entity:person:1',
target: 'entity:person:2',
type: 'follows',
since: '2023-01-01'
});
// Get relationships
const relationship = await client.hGetAll('relationship:follows:1');
console.log(relationship);Querying the Knowledge Graph
// Find all entities of a specific type
const keys = await client.keys('entity:person:*');
const entities = await Promise.all(
keys.map(key => client.hGetAll(key))
);
// Find relationships between entities
const relationshipKeys = await client.keys('relationship:follows:*');
const relationships = await Promise.all(
relationshipKeys.map(key => client.hGetAll(key))
);API Reference
The Nexus client provides all the same methods as the Redis client, including:
get,set,del- Basic key-value operationshGet,hSet,hGetAll- Hash operationslPush,lRange- List operationssAdd,sMembers- Set operationszAdd,zRange- Sorted set operationskeys,scan- Key operations- And many more...
Protocol Support
The Nexus client supports the nexus:// protocol scheme, which is automatically translated to the appropriate protocol for communicating with the Nexus server.
License
MIT
