@skazka/server-redis

    0.0.10 • Public • Published

    Server Redis

    Skazka Server Redis client.

    NPM

    How to install

    npm i @skazka/server @skazka/server-redis config ioredis
    

    With yarn:

    yarn add @skazka/server @skazka/server-redis config ioredis
    

    Optionally you can add http server, error handler, logger, router, request and response:

    npm i @skazka/server-http @skazka/server-router @skazka/server-error @skazka/server-logger @skazka/server-request @skazka/server-response
    

    With yarn:

    yarn add @skazka/server-http @skazka/server-router @skazka/server-error @skazka/server-logger @skazka/server-request @skazka/server-response
    

    How to use

    Config

    config/default.json

    {
      "redis": {
        "host": "127.0.0.1",
        "port": 6379
      }
    }

    Server module

    const App = require('@skazka/server');
    const Router = require('@skazka/server-router');
        
    const redis = require('@skazka/server-redis');
        
    const error = require('@skazka/server-error');
    const logger = require('@skazka/server-logger');
    
    const request = require('@skazka/server-request');
    const response = require('@skazka/server-response');
        
    const server = require('@skazka/server-http');
        
    const app = new App();
    const router = new Router();
        
    app.all([
      error(),
      logger(),
      request(),
      redis(),
      response(),
    ]);
        
    app.then(async (ctx) => {
      await ctx.redis.set('data', 'test');
      const data = await ctx.redis.get('data');
    });
        
    router.get('/data').then(async (ctx) => {
      await ctx.redis.set('data', 'test');
      const data = await ctx.redis.get('data');
            
      return ctx.response(data); 
    });
        
    app.then(router.resolve());
        
    server.createHttpServer(app);

    Any other module

    You can use redis client in any app module:

    const redis = require('@skazka/server-redis/redis');
        
    async () => {
      await redis.set('test', 'test');
      const data = await redis.get('test');
    }

    Install

    npm i @skazka/server-redis

    DownloadsWeekly Downloads

    1

    Version

    0.0.10

    License

    MIT

    Unpacked Size

    3.3 kB

    Total Files

    4

    Last publish

    Collaborators

    • evheniy.bystrov
    • skazkajs