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.
To install Node-famcache, use npm:
npm install @famcache/famcache
First, import the module and create a client instance:
import Famcache from '@famcache/famcache';
const client = new FamcacheClient({
host: 'localhost',
port: 3577,
});
To store a value in the cache:
await client.set('key', 'value', 30000);
To retrieve a value from the cache:
const value = await client.get('key');
To delete a value from the cache:
await client.del('key');
To publish data to the topic:
client.messaging.publish('topic', 'data');
To subscribe to the topic:
client.messaging.subscribe('topic', (data) => {
// ...
});
To unsubscribe from the topic:
client.messaging.unsubscribe('topic');
Creates a new client instance.
- options (object):
- host (string): The host of the Famcache server.
- port (number): The port of the Famcache server.
Sets a value in the cache.
- key (string): The key under which the value will be stored.
- value (string): The value to store.
- ttl (number): Time to leave (optional)
Gets a value from the cache.
- key (string): The key of the value to retrieve.
Deletes a value from the cache.
Publishes data to the topic
- topic (string): Topic name
- data (string): Payload that will be send to the subscribers
Subscribes to the topic
- topic (string): Topic name
- callback (Function): Callback function that will be invoked when message will be received for this topic
Unsubscribes from the topic
- topic (string): Topic name
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
Node-famcache is licensed under the MIT License. See the LICENSE file for more details.