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

adonis5-memcached-client

v1.1.0

Published

Memcached client for AdonisJS 5

Downloads

4,613

Readme

Adonis5-Memcached-Client

Memcached client for AdonisJS 5

typescript-image npm-image license-image

Based on Memcached and promisified for better developer experience.

Table of contents

Installation

npm i adonis5-memcached-client

Install provider:

node ace invoke adonis5-memcached-client
  • For other configuration, please update the config/memcached.ts.

Sample Usage

Import client from Adonis IoC and use it for getting access to the cache:

 import MemcachedClient from '@ioc:Adonis/Addons/Adonis5-MemcachedClient'

export default class CacheRepository {
	constructor() {
	}

	public async find<T>(key): Promise<T | undefined> {
		return MemcachedClient.get < T > (key)
	}
}

Client api

get

Get the value for the given key.

const value = await client.get('key');
  • key: String, the key

touch

Touches the given key.

await client.touch('key', 10);
  • key: String The key
  • lifetime: Number After how long should the key expire measured in seconds

gets

Get the value and the CAS id.

const { key, cas } = await client.gets('key', 10);
  • key: String, the key

getMulti

Retrieves a bunch of values from multiple keys.

const values = await client.getMulti(['key-1', 'key-2']);
  • keys: String[], all the keys that needs to be fetched

set

Stores a new value in Memcached.

const result = await client.set('foo', 'bar', 10);
  • key: String the name of the key
  • value: Mixed Either a buffer, JSON, number or string that you want to store.
  • lifetime: Number, how long the data needs to be replaced measured in seconds

replace

Replaces the value in memcached.

const result = await client.replace('foo', 'bar', 10);
  • key: String the name of the key
  • value: Mixed Either a buffer, JSON, number or string that you want to store.
  • lifetime: Number, how long the data needs to be replaced measured in seconds

add

Add the value, only if it's not in memcached already.

const result = await client.add('test-key', 'test-value', 60);
  • key: String the name of the key
  • value: Mixed Either a buffer, JSON, number or string that you want to store.
  • lifetime: Number, how long the data needs to be replaced measured in seconds

cas

Add the value, only if it matches the given CAS value.

const result = await client.cas('test', 'new-value', cas, 100);
  • key: String the name of the key
  • value: Mixed Either a buffer, JSON, number or string that you want to store.
  • lifetime: Number, how long the data needs to be replaced measured in seconds
  • cas: String the CAS value

append

Add the given value string to the value of an existing item.

await client.append('test', '-postfix')
  • key: String the name of the key
  • value: Mixed Either a buffer, JSON, number or string that you want to store.

prepend

Add the given value string to the value of an existing item.

const result = await client.prepend('test', 'prefix-')
  • key: String the name of the key
  • value: Mixed Either a buffer, JSON, number or string that you want to store.

incr

Increment a given key.

const result = await client.incr('test', 100)
  • key: String the name of the key
  • amount: Number The increment

decr

Decrement a given key.

const result = await client.decr('test', 100)
  • key: String the name of the key
  • amount: Number The decrement

del

Remove the key from memcached.

const result = await client.del('test')
  • key: String the name of the key

version

Retrieves the version number of your server.

const versionInfo = await client.version()

flush

Flushes the memcached server.

const results = await client.flush()

stats

Retrieves stats from your memcached server.

const statsInfo = await client.stats()

settings

Retrieves your settings for connected servers.

const settings = await client.settings()

slabs

Retrieves slabs information for connected servers.

const slabsInfo = await client.slabs()

items

Retrieves items information for connected servers.

const items = await client.items()

end

Closes all active memcached connections.

await client.end()