Memcached client for AdonisJS 5
npm install adonis5-memcached-client> Memcached client for AdonisJS 5
[![typescript-image]][typescript-url] [![npm-image]][npm-url] [![license-image]][license-url]
Based on Memcached and promisified for better developer experience.
- Installation
- Sample Usage
- Client api
- get
- touch
- gets
- getMulti
- set
- replace
- add
- cas
- append
- prepend
- incr
- decr
- del
- version
- flush
- stats
- settings
- slabs
- items
- end
``bash`
npm i adonis5-memcached-client
Install provider:
`bash`
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:
`js
import MemcachedClient from '@ioc:Adonis/Addons/Adonis5-MemcachedClient'
export default class CacheRepository {
constructor() {
}
public async find
return MemcachedClient.get < T > (key)
}
}
`
Get the value for the given key.
`js`
const value = await client.get('key');
* key: String, the key
Touches the given key.
`js`
await client.touch('key', 10);
* key: String The keylifetime
* : Number After how long should the key expire measured in seconds
Get the value and the CAS id.
`js`
const { key, cas } = await client.gets('key', 10);
* key: String, the key
Retrieves a bunch of values from multiple keys.
`js`
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.
`js`
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 in seconds
Replaces the value in memcached.
`js`
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 in seconds
Add the value, only if it's not in memcached already.
`js`
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 in seconds
Add the value, only if it matches the given CAS value.
`js`
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 in secondscas
* : String the CAS value
Add the given value string to the value of an existing item.
`js`
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.
`js`
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.
`js`
const result = await client.incr('test', 100)
* key: String the name of the keyamount
* : Number The increment
Decrement a given key.
`js`
const result = await client.decr('test', 100)
* key: String the name of the keyamount
* : Number The decrement
Remove the key from memcached.
`js`
const result = await client.del('test')
* key: String the name of the key
Retrieves the version number of your server.
`js`
const versionInfo = await client.version()
Flushes the memcached server.
`js`
const results = await client.flush()
Retrieves stats from your memcached server.
`js`
const statsInfo = await client.stats()
Retrieves your settings for connected servers.
`js`
const settings = await client.settings()
Retrieves slabs information for connected servers.
`js`
const slabsInfo = await client.slabs()
Retrieves items information for connected servers.
`js`
const items = await client.items()
Closes all active memcached connections.
`js``
await client.end()
[typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
[typescript-url]: "typescript"
[npm-image]: https://img.shields.io/npm/v/adonis5-memcached-client.svg?style=for-the-badge&logo=npm
[npm-url]: https://npmjs.org/package/adonis5-memcached-client "npm"
[license-image]: https://img.shields.io/npm/l/adonis5-memcached-client?color=blueviolet&style=for-the-badge
[license-url]: LICENSE.md "license"