desc time author veaba
 *  const redis = require ( 'redis' ) ; import { redisConfig } from "../config" ; desc export const setHash = async ( key , data ) => { if ( ! key ) { console . info ( 'setHash 丢失key' ) ; return ; } const client = redis . createClient ( redisConfig ) ; client . on ( 'error' , ( err ) => { console . log ( err , 'setHash' ) ; } ) ; return new Promise ( resolve => { client . HMSET ( key . toString ( ) , { ... data } , ( err , res ) => { if ( err ) console . info ( err ) ; client . end ( true ) ; resolve ( res ) ; } ) ; } ) ; } ; desc export const setSet = async ( key , field ) => { key = key . toString ( ) ; const client = redis . createClient ( redisConfig ) ; client . on ( 'error' , ( err ) => { console . log ( err , 'setSet' ) ; } ) ; return new Promise ( ( resolve ) => { if ( field ) { client . sadd ( key , field , async ( err , obj ) => { if ( err ) console . log ( err ) ; client . end ( true ) ; resolve ( obj ) ; } ) ; } else { throw new Error ( '请输入设置的字段' ) ; } } ) ; } ; desc export const delSet = async ( key , field ) => { key = key . toString ( ) ; const client = redis . createClient ( redisConfig ) ; client . on ( 'error' , ( err ) => { console . log ( err , 'delSet' ) ; } ) ; return new Promise ( ( resolve ) => { if ( field ) { client . srem ( key , field , async ( err , obj ) => { if ( err ) console . log ( err ) ; client . end ( true ) ; resolve ( obj ) ; } ) ; } else { throw new Error ( '请输入设置的字段' ) ; } } ) ; } ; desc export const totalOnline = async ( key ) => { key = key . toString ( ) ; const client = redis . createClient ( redisConfig ) ; client . on ( 'error' , ( err ) => { console . log ( err , 'totalOnline' ) ; } ) ; return new Promise ( ( resolve ) => { client . SCARD ( key , async ( err , obj ) => { if ( err ) console . log ( err ) ; client . end ( true ) ; resolve ( obj ) ; } ) ; } ) ; } ; desc param key param field export const getHash = async ( key , field ? ) => { key = key . toString ( ) ; const client = redis . createClient ( redisConfig ) ; client . on ( 'error' , ( err ) => { console . log ( err , 'getHash' ) ; } ) ; return new Promise ( ( resolve ) => { if ( field ) { client . HGET ( key , field , async ( err , obj ) => { if ( err ) console . log ( err ) ; client . end ( true ) ; resolve ( obj ) ; } ) ; } else { client . hgetall ( key , ( err , obj ) => { if ( err ) console . info ( err ) ; client . end ( true ) ; resolve ( obj ) ; } ) ; } } ) ; } ; desc export const delKey = async ( key ) => { const client = redis . createClient ( redisConfig ) ; client . on ( 'error' , ( err ) => { console . log ( err , 'getHash' ) ; } ) ; return new Promise ( resolve => { client . del ( key , ( err , res ) => { if ( err ) console . info ( err ) ; client . end ( true ) ; resolve ( res ) ; } ) ; } ) ; } ; desc param key param second export const setTime = async ( key , second ) => { const client = redis . createClient ( redisConfig ) ; client . on ( 'error' , ( err ) => { console . log ( err , 'getHash' ) ; } ) ; return new Promise ( ( resolve , reject ) => { client . expire ( key . toString ( ) , second , ( err , res ) => { if ( err ) reject ( ) ; else resolve ( res ) ; client . end ( true ) ; } ) ; } ) ; } ;