Memcached client for AdonisJS 5
Based on Memcached and promisified for better developer experience.
npm i adonis5-memcached-client
Install provider:
node ace invoke adonis5-memcached-client
- For other configuration, please update the
config/memcached.ts
.
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)
}
}
Get the value for the given key.
const value = await client.get('key');
key
: String, the key
Touches the given key.
await client.touch('key', 10);
key
: String The keylifetime
: Number After how long should the key expire measured inseconds
Get the value and the CAS id.
const { key, cas } = await client.gets('key', 10);
key
: String, the key
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
Stores a new value in Memcached.
const result = await client.set('foo', 'bar', 10);
key
: String the name of the keyvalue
: Mixed Either a buffer, JSON, number or string that you want to store.lifetime
: Number, how long the data needs to be replaced measured inseconds
Replaces the value in memcached.
const result = await client.replace('foo', 'bar', 10);
key
: String the name of the keyvalue
: Mixed Either a buffer, JSON, number or string that you want to store.lifetime
: Number, how long the data needs to be replaced measured inseconds
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 keyvalue
: Mixed Either a buffer, JSON, number or string that you want to store.lifetime
: Number, how long the data needs to be replaced measured inseconds
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 keyvalue
: Mixed Either a buffer, JSON, number or string that you want to store.lifetime
: Number, how long the data needs to be replaced measured inseconds
cas
: String the CAS value
Add the given value string to the value of an existing item.
await client.append('test', '-postfix')
key
: String the name of the keyvalue
: Mixed Either a buffer, JSON, number or string that you want to store.
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 keyvalue
: Mixed Either a buffer, JSON, number or string that you want to store.
Increment a given key.
const result = await client.incr('test', 100)
key
: String the name of the keyamount
: Number The increment
Decrement a given key.
const result = await client.decr('test', 100)
key
: String the name of the keyamount
: Number The decrement
Remove the key from memcached.
const result = await client.del('test')
key
: String the name of the key
Retrieves the version number of your server.
const versionInfo = await client.version()
Flushes the memcached server.
const results = await client.flush()
Retrieves stats from your memcached server.
const statsInfo = await client.stats()
Retrieves your settings
for connected servers.
const settings = await client.settings()
Retrieves slabs
information for connected servers.
const slabsInfo = await client.slabs()
Retrieves items
information for connected servers.
const items = await client.items()
Closes all active memcached connections.
await client.end()