node-famcache

Node-famcache

NPM Downloads NPM Version GitHub Actions Workflow Status TypeScript Badge

Node-famcache is a Node.js client for Famcache, a caching server written in Go. This client allows you to interact with the Famcache server from your Node.js applications, providing an easy-to-use interface for caching operations.

Table of Contents

Installation

To install Node-famcache, use npm:

npm install @famcache/famcache

Usage

Connecting to the Server

First, import the module and create a client instance:

import Famcache from '@famcache/famcache';

const client = new FamcacheClient({
  host: 'localhost',
  port: 3577,
});

Basic Operations

Set a Value

To store a value in the cache:

await client.set('key', 'value', 30000);

Get a Value

To retrieve a value from the cache:

const value = await client.get('key');

Delete a Value

To delete a value from the cache:

await client.del('key');

Publish a topic

To publish data to the topic:

client.messaging.publish('topic', 'data');

Subscribe to the topic

To subscribe to the topic:

client.messaging.subscribe('topic', (data) => {
  // ...
});

Unsubscribe from the topic

To unsubscribe from the topic:

client.messaging.unsubscribe('topic');

API Reference

FamcacheClient

new FamcacheClient(options)

Creates a new client instance.

client.set(key, value, ttl?)

Sets a value in the cache.

client.get(key)

Gets a value from the cache.

client.delete(key, callback)

Deletes a value from the cache.

client.messaging.publish(topic, data)

Publishes data to the topic

client.messaging.subscribe(topic, callback)

Subscribes to the topic

client.messaging.unsubscribe(topic)

Unsubscribes from the topic

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

License

Node-famcache is licensed under the MIT License. See the LICENSE file for more details.