JavaScript Style Guide

Redis client for UnityBase

Limitations

For simplicity current implementation uses a single redis instance

Usage

Can be used from command line - see apps/autotest/scripts/redis_sample.js, or from server worker as in example

  
      const redis = require('@unitybase/redis')
 const redisConn = redis.getDefaultRedisConnection()
 // Set key `key1` to hold the string value `val1` with 3 second expire
 redisConn.commands('set', 'key1', 'val1', 'EX', 3)
 // get time-to-live (TTL0 of key1
 const TTL = redisConn.commands('TTL', 'key1')
 console.log('key1 will live', TTL, 'sec')
 // get value
 let val = redisConn.commands('get', 'key1')
 console.log('Value for key1 is', val)

 console.log('Waiting for 3 second...')
 sleep(3100)
 // now  value is expired
 val = redisConn.commands('get', 'key1')
 console.log('Expired value for key1 is', val) // val is null
  

Classes

Methods

# getDefaultRedisConnection () → RedisClient inner

Return per-thread instance of redis client connected to server using configuration from ubConfig.application.redis. To be used inside server-side thread

  
      const redis = require('@unitybase/redis')
 const redisConn = redis.getDefaultRedisConnection()
 console.log(redisConn.commands('PING')) // PONG