-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Famcache/feature/pubsub
Feature: Implemented Famcache Publish/Subscribe protocol
- Loading branch information
Showing
10 changed files
with
263 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
## [1.4.1](https://github.com/Famcache/node-famcache/compare/v1.4.0...v1.4.1) (2024-05-29) | ||
|
||
|
||
### Bug Fixes | ||
|
||
* **Delete:** Fixed Delete command ([b591f9e](https://github.com/Famcache/node-famcache/commit/b591f9e250ec80202264dd3f676783ff96dac9d4)) | ||
- **Delete:** Fixed Delete command ([b591f9e](https://github.com/Famcache/node-famcache/commit/b591f9e250ec80202264dd3f676783ff96dac9d4)) | ||
|
||
# [1.4.0](https://github.com/Famcache/node-famcache/compare/v1.3.0...v1.4.0) (2024-05-29) | ||
|
||
|
||
### Features | ||
|
||
* **npm:** Mark package as public ([e64a9a2](https://github.com/Famcache/node-famcache/commit/e64a9a21c62a2e737a38cba7b5a909479fbc9cce)) | ||
- **npm:** Mark package as public ([e64a9a2](https://github.com/Famcache/node-famcache/commit/e64a9a21c62a2e737a38cba7b5a909479fbc9cce)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +1,151 @@ | ||
# Node-famcache | ||
|
||
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](#installation) | ||
- [Usage](#usage) | ||
- [Connecting to the Server](#connecting-to-the-server) | ||
- [Basic Operations](#basic-operations) | ||
- [Set a Value](#set-a-value) | ||
- [Get a Value](#get-a-value) | ||
- [Delete a Value](#delete-a-value) | ||
- [API Reference](#api-reference) | ||
- [Contributing](#contributing) | ||
- [License](#license) | ||
|
||
## Installation | ||
|
||
To install Node-famcache, use npm: | ||
|
||
```sh | ||
npm install @famcache/famcache | ||
``` | ||
|
||
|
||
|
||
## Usage | ||
### Connecting to the Server | ||
|
||
First, import the module and create a client instance: | ||
|
||
```ts | ||
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: | ||
|
||
```ts | ||
await client.set('key', 'value', 30000); | ||
``` | ||
|
||
#### Get a Value | ||
To retrieve a value from the cache: | ||
|
||
```ts | ||
const value = await client.get('key'); | ||
``` | ||
|
||
#### Delete a Value | ||
To delete a value from the cache: | ||
|
||
```ts | ||
await client.del('key'); | ||
``` | ||
|
||
## API Reference | ||
|
||
### `FamcacheClient` | ||
|
||
#### `new FamcacheClient(options)` | ||
|
||
Creates a new client instance. | ||
|
||
- **options** (object): | ||
- **host** (string): The host of the Famcache server. | ||
- **port** (number): The port of the Famcache server. | ||
|
||
#### `client.set(key, value, ttl?)` | ||
|
||
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) | ||
|
||
#### `client.get(key)` | ||
|
||
Gets a value from the cache. | ||
|
||
- **key** (string): The key of the value to retrieve. | ||
|
||
#### `client.delete(key, callback)` | ||
|
||
Deletes a value from the cache. | ||
|
||
- **key** (string): The key of the value to delete. | ||
|
||
|
||
# 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](./LICENSE) file for more details. | ||
# Node-famcache | ||
|
||
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](#installation) | ||
- [Usage](#usage) | ||
- [Connecting to the Server](#connecting-to-the-server) | ||
- [Basic Operations](#basic-operations) | ||
- [Set a Value](#set-a-value) | ||
- [Get a Value](#get-a-value) | ||
- [Delete a Value](#delete-a-value) | ||
- [Publish a topic](#publish-a-topic) | ||
- [Subscribe to the topic](#subscribe-to-the-topic) | ||
- [Unsubscribe from the topic](#unsubscribe-from-the-topic) | ||
- [API Reference](#api-reference) | ||
- [Contributing](#contributing) | ||
- [License](#license) | ||
|
||
## Installation | ||
|
||
To install Node-famcache, use npm: | ||
|
||
```sh | ||
npm install @famcache/famcache | ||
``` | ||
|
||
## Usage | ||
|
||
### Connecting to the Server | ||
|
||
First, import the module and create a client instance: | ||
|
||
```ts | ||
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: | ||
|
||
```ts | ||
await client.set('key', 'value', 30000); | ||
``` | ||
|
||
#### Get a Value | ||
|
||
To retrieve a value from the cache: | ||
|
||
```ts | ||
const value = await client.get('key'); | ||
``` | ||
|
||
#### Delete a Value | ||
|
||
To delete a value from the cache: | ||
|
||
```ts | ||
await client.del('key'); | ||
``` | ||
|
||
|
||
#### Publish a topic | ||
|
||
To publish data to the topic: | ||
```ts | ||
client.publish('topic', 'data'); | ||
``` | ||
|
||
#### Subscribe to the topic | ||
|
||
To subscribe to the topic: | ||
```ts | ||
client.subscribe('topic', (data) => { | ||
// ... | ||
}); | ||
``` | ||
|
||
#### Unsubscribe from the topic | ||
|
||
To unsubscribe from the topic: | ||
```ts | ||
client.unsubscribe('topic'); | ||
``` | ||
|
||
## API Reference | ||
|
||
### `FamcacheClient` | ||
|
||
#### `new FamcacheClient(options)` | ||
|
||
Creates a new client instance. | ||
|
||
- **options** (object): | ||
- **host** (string): The host of the Famcache server. | ||
- **port** (number): The port of the Famcache server. | ||
|
||
#### `client.set(key, value, ttl?)` | ||
|
||
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) | ||
|
||
#### `client.get(key)` | ||
|
||
Gets a value from the cache. | ||
|
||
- **key** (string): The key of the value to retrieve. | ||
|
||
#### `client.delete(key, callback)` | ||
|
||
Deletes a value from the cache. | ||
|
||
#### `client.publish(topic, data)` | ||
|
||
Publishes data to the topic | ||
|
||
- **topic** (string): Topic name | ||
- **data** (string): Payload that will be send to the subscribers | ||
|
||
#### `client.subscribe(topic, callback)` | ||
|
||
Subscribes to the topic | ||
|
||
- **topic** (string): Topic name | ||
- **callback** (Function): Callback function that will be invoked when message will be received for this topic | ||
|
||
|
||
#### `client.unsubscribe(topic)` | ||
|
||
Unsubscribes from the topic | ||
|
||
- **topic** (string): Topic name | ||
|
||
# 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](./LICENSE) file for more details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.