npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lunardb-js-sdk

v3.0.1

Published

A lightweight Node.js library that provides an interface for interacting with the Lunar service. It allows you to easily set key-value pairs, optionally with a time-to-live (TTL) value, using a simple API.

Downloads

33

Readme

Lunar SDK JS

Lunar SDK JS is a lightweight Node.js library that provides an interface for interacting with the Lunar service. It allows you to easily set key-value pairs, optionally with a time-to-live (TTL) value, using a simple API.

Installation

You can install the package via npm:

npm install lunar-js-sdk

Usage

Here is a basic example demonstrating how to use the Lunar SDK JS:

const Lunar = require('lunar-js-sdk');

// Initialize the Lunar SDK
const lunar = new Lunar();

// Optionally set a new connection URL
lunar.connection('http://your-lunar-service-url:8000');

// Set a key-value pair with optional TTL
lunar.set('exampleKey', 'exampleValue', 60); // TTL is in seconds

Methods

new Lunar()

Creates a new instance of the Lunar SDK.

const lunar = new Lunar();

connection(connectionURL)

Sets the base URL for the Lunar service.

  • connectionURL (string): The URL of the Lunar service.
lunar.connection('http://your-lunar-service-url:8000');

set(key, value, ttl)

Stores a key-value pair in the Lunar service.

  • key (string): The key to be set.
  • value (string): The value associated with the key.
  • ttl (number, optional): Time-to-live in seconds for the key-value pair. If not provided, the key-value pair will persist indefinitely.
lunar.set('exampleKey', 'exampleValue', 60);

get(key)

Retrieves the value associated with a given key from the Lunar service.

  • key (string): The key for which the value needs to be retrieved.

Returns the value associated with the key, or null if the key does not exist or has expired.

lunar.get('exampleKey').then(value => {
  console.log(value); // Outputs the value or null if the key doesn't exist.
});

del(key)

Deletes a key-value pair from the Lunar service.

  • key (string): The key to be deleted.
lunar.del('exampleKey').then(response => {
  console.log(response); // Outputs success message or error if the key does not exist.
});

mset(...pairs)

Stores multiple key-value pairs in the Lunar service.

  • pairs: A list of keys and values, alternating between them.
lunar.mset('key1', 'value1', 'key2', 'value2').then(response => {
  console.log(response); // Outputs success message.
});

mget(...keys)

Retrieves multiple values associated with the given keys from the Lunar service.

  • keys: A list of keys to retrieve.
lunar.mget('key1', 'key2').then(values => {
  console.log(values); // Outputs the values for the keys or null if they do not exist.
});

keys()

Lists all keys stored in the Lunar service.

lunar.keys().then(keys => {
  console.log(keys); // Outputs a list of all keys.
});

clear()

Clears all key-value pairs from the Lunar service.

lunar.clear().then(response => {
  console.log(response); // Outputs success message.
});

size()

Gets the number of key-value pairs stored in the Lunar service.

lunar.size().then(count => {
  console.log(`Number of keys: ${count}`); // Outputs the number of keys.
});

cleanup()

Removes expired entries from the Lunar service.

lunar.cleanup().then(response => {
  console.log(response); // Outputs success message or number of expired entries removed.
});

save(filename)

Saves the current state of the Lunar service to a file.

  • filename (string): The name of the file where the state will be saved.
lunar.save('backup.json').then(response => {
  console.log(response); // Outputs success message.
});

load(filename)

Loads the state of the Lunar service from a file.

  • filename (string): The name of the file from which the state will be loaded.
lunar.load('backup.json').then(response => {
  console.log(response); // Outputs success message.
});

Error Handling

All methods return a Promise. If an error occurs during the execution of a command, the Promise will be rejected with an error message.

lunar.set('exampleKey', 'exampleValue', 60)
  .then(response => {
    console.log(response);
  })
  .catch(error => {
    console.error('Error:', error);
  });

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue if you find bugs or have suggestions for new features.

Disclaimer

This package assumes that you have the Lunar CLI installed and accessible from your command line. The Lunar CLI is required to execute the commands via the exec function.

Author

Adam Basha