Home

Awesome

Adonis5-Memcached-Client

Memcached client for AdonisJS 5

typescript-image npm-image license-image

Based on Memcached and promisified for better developer experience.

<!-- START doctoc generated TOC please keep comment here to allow auto update --> <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

Table of contents

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

Installation

npm i adonis5-memcached-client

Install provider:

node ace invoke adonis5-memcached-client

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');

touch

Touches the given key.

await client.touch('key', 10);

gets

Get the value and the CAS id.

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

getMulti

Retrieves a bunch of values from multiple keys.

const values = await client.getMulti(['key-1', 'key-2']);

set

Stores a new value in Memcached.

const result = await client.set('foo', 'bar', 10);

replace

Replaces the value in memcached.

const result = await client.replace('foo', 'bar', 10);

add

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

const result = await client.add('test-key', 'test-value', 60);

cas

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

const result = await client.cas('test', 'new-value', cas, 100);

append

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

await client.append('test', '-postfix')

prepend

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

const result = await client.prepend('test', 'prefix-')

incr

Increment a given key.

const result = await client.incr('test', 100)

decr

Decrement a given key.

const result = await client.decr('test', 100)

del

Remove the key from memcached.

const result = await client.del('test')

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()