version :  '3.1' 
services : redis : image :  redisports : -  6379: 6379 
命令行:docker-compose up 查看: docker ps 进入redis-cli,输入以下docker exec -it 7dc0a redis-cli -h localhost -p 6379 设置 name=marronset name marron 获取nameget name 若docker未开启redis,会提示如下 连接redis const  redis =  require ( 'redis' ) ; 
const  client =  redis. createClient ( 6379 ,  '127.0.0.1' ) ; 
client. on ( 'error' ,  async  ( err)  =>  { console. log ( `[Error]:  ${ err} ` ) ; 
} ) 
client. set ( 'name' ,  'marron' ,  redis. print) ; 
client. get ( 'name' ,  async  ( err,  value)  =>  { if  ( err)  throw  err; console. log ( 'Name: '  +  value) ; 
} ) ; 
client. hmset ( 'marron' ,  { 'item' :  'koaDemo' , 'chapter' :  'redisDemo' 
} ) ; 
client. hgetall ( 'marron' ,  async  ( err,  obj)  =>  { console. log ( obj) ; 
} ) ; 
client. hkeys ( 'marron' ,  async  ( err,  replies)  =>  { replies. forEach ( ( reply,  i)  =>  { console. log ( i +  ":"  +  reply) ; } ) ; 
} ) 
client. lpush ( 'marron1' ,  'koa' ,  redis. print) 
client. lpush ( 'marron1' ,  'redisDemo' ,  redis. print) ; 
client. lrange ( 'marron1' ,  0 ,  - 1 ,  async  ( err,  items)  =>  { if  ( err)  throw  err; items. forEach ( async  ( item,  i)  =>  { console. log ( item) ; } ) 
} )