Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xtcry/vk-io-redis-storage
https://github.com/xtcry/vk-io-redis-storage
Last synced: 9 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/xtcry/vk-io-redis-storage
- Owner: xTCry
- Created: 2022-03-06T14:16:51.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-03-13T11:55:16.000Z (over 2 years ago)
- Last Synced: 2024-03-23T17:22:13.295Z (8 months ago)
- Language: TypeScript
- Size: 13.7 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# vk-io-redis-storage
[![NPM version][npm-v]][npm-url]
[![NPM downloads][npm-downloads]][npm-url]RedisStorage - Simple add-on for [Session](https://github.com/negezor/vk-io/tree/master/packages/session) [vk-io](https://github.com/negezor/vk-io) library
> Powered by [ioredis](https://github.com/luin/ioredis)
## Installation
### Yarn
```bash
yarn add vk-io-redis-storage
```### NPM
```bash
npm i vk-io-redis-storage
```### Example usage
```js
const { VK } = require('vk-io');
const { SessionManager } = require('@vk-io/session');
const { RedisStorage } = require('vk-io-redis-storage');const vk = new VK({
token: process.env.TOKEN,
});function startBot({ updates }) {
const storage = new RedisStorage({
// redis: ioRedisClient,
redis: {
host: '127.0.0.1',
},
keyPrefix: 'vk-io:session:',
// ttl: 12 * 3600,
});const sessionManager = new SessionManager({
storage,
getStorageKey: (ctx) =>
ctx.userId
? `${ctx.userId}:${ctx.userId}`
: `${ctx.peerId}:${ctx.senderId}`,
});updates.on('message', sessionManager.middleware);
updates.on('message_new', (ctx, next) => {
if (context.text !== '/counter') {
return next();
}
if (ctx.isOutbox) return;const { session } = ctx;
session.counter = (session.counter || 0) + 1;
ctx.send(`You turned to the bot (${session.counter}) times`);
});updates.start().catch(console.error);
}// ...
startBot(vk);
```[npm-v]: https://img.shields.io/npm/v/vk-io-redis-storage.svg?style=flat-square
[npm-downloads]: https://img.shields.io/npm/dt/vk-io-redis-storage?label=used%20by&style=flat-square
[npm-url]: https://www.npmjs.com/package/vk-io-redis-storage[node]: https://img.shields.io/node/v/vk-io-redis-storage.svg?style=flat-square
[node-url]: https://nodejs.org[build]: https://img.shields.io/travis/vk-io-redis-storage.svg?style=flat-square
[build-url]: https://travis-ci.org/vk-io-redis-storage