项目作者: milkandsour

项目描述 :
a fastify redis boilerplate
高级语言: JavaScript
项目地址: git://github.com/milkandsour/fastify-redis-boilerplate.git
创建时间: 2019-01-15T11:46:04Z
项目社区:https://github.com/milkandsour/fastify-redis-boilerplate

开源协议:

下载


nyan asd

Another fastify + redis boilerplate.
The scope of this project is to offer a real fastify + redis use case
(Redis it is used as main database).


npm nstall

  1. npm i fastify-redis-boilerplate
  2. ./node_modules/.bin/build
  3. npm install

myan asd

Requirements

  • nodejs lts
  • docker
  • fastify
  • redis

Preliminary step

  • fork the repo

Usage with Docker

Start
  1. docker-compose -f docker-compose.debug.yml build
  2. docker-compose -f docker-compose.debug.yml up
  • Builds, (re)creates, starts, and attaches to containers for a service.
Stop
  1. docker-compose -f docker-compose.debug.yml down
  • Stops containers and removes containers, networks, volumes, and images created by up.
Tests
  1. docker-compose -f docker-compose.tests.yml build
  2. docker-compose -f docker-compose.tests.yml up --abort-on-container-exit --exit-code-from tests
Prod
  1. docker build -t nyan-asd:latest .
Benchmark
  1. docker-compose -f docker-compose.benchmarks.yml build
  2. docker-compose -f docker-compose.benchmarks.yml up --abort-on-container-exit --exit-code-from benchmarks
  • by default benchmarks point to ‘0.0.0.0:3001’
Note on benchmarking

The configuration (tests/benchmarks/config.json)

  1. {
  2. "tests" : [
  3. {
  4. "server" : "http://0.0.0.0:3001",
  5. "threads": 100,
  6. "duration": "10s",
  7. "connections": 100,
  8. "paths": [
  9. "/v1/reviews?accomodation=96e83a90-48da-4e81-9d06-7f1b76e5364e",
  10. ...
  11. ],
  12. "requirements": {
  13. "latencyAvg": 130,
  14. ...
  15. "latency99": 150
  16. }
  17. }
  18. ]
  19. }

requirements:

  • latencyAvg
  • latencyStdev
  • latencyMax
  • latency50
  • latency75
  • latency90
  • latency99
  • requestsPerSec
  • non2xx3xx
Delete all containers
  1. docker rm $(docker ps -a -q)
Delete all images
  1. docker rmi $(docker images -q)
Delete all the volumes
  1. docker volumes prune

Local Usage

Install
  1. npm install
Debug

Run in debug mode with watch and debug capabilities

  1. npm run debug
Start

Run in server mode without any extra tool or capability

  1. npm start
Benchmark
  1. npm run benchmark
Test

Run all the tests suite and the linter

  1. npm test

alternatively you may want yo tag your test

  1. it('Return status 404 @asd-307', (done) => {
  2. ...

and then use the --grep option

  1. npm test -- --grep="asd-307"

also

  1. npm test -- --grep="asd-307|unit"

Endpoints

Reviews

  1. curl http://0.0.0.0:3001/v1/reviews\?accomodation=96e83a90-48da-4e81-9d06-7f1b76e5364e&limit=1

Result

  1. {
  2. "collection":[
  3. {
  4. "key":"e54b1d94-5590-4410-9d4e-76b3ea1f2ce5",
  5. "accomodation":"96e83a90-48da-4e81-9d06-7f1b76e5364e",
  6. "along":"COUPLE",
  7. "travel":1470009600000,
  8. "submission":1472550180580,
  9. "general":10,
  10. "user":"Claus Duus Pedersen",
  11. "locale":"en",
  12. "texts":{
  13. "en":"Friendly staff - nice restaurants and Sporting Bar"
  14. },
  15. "titles":{
  16. "en":"Great camping site"
  17. },
  18. "aspects":{
  19. "location":10,
  20. "service":0,
  21. "priceQuality":9,
  22. "food":0,
  23. "room":0,
  24. "childFriendly":9,
  25. "interior":0,
  26. "size":0,
  27. "activities":0,
  28. "restaurants":0,
  29. "sanitaryState":0,
  30. "accessibility":0,
  31. "nightlife":0,
  32. "culture":0,
  33. "surrounding":0,
  34. "atmosphere":0,
  35. "noviceSkiArea":0,
  36. "advancedSkiArea":0,
  37. "apresSki":0,
  38. "beach":0,
  39. "entertainment":0,
  40. "environmental":0,
  41. "pool":10,
  42. "terrace":0
  43. },
  44. "scores":{
  45. "weight":0.7,
  46. "general":7,
  47. "aspects":{
  48. "location":7,
  49. "service":0,
  50. "priceQuality":6.3,
  51. "food":0,
  52. "room":0,
  53. "childFriendly":6.3,
  54. "interior":0,
  55. "size":0,
  56. "activities":0,
  57. "restaurants":0,
  58. "sanitaryState":0,
  59. "accessibility":0,
  60. "nightlife":0,
  61. "culture":0,
  62. "surrounding":0,
  63. "atmosphere":0,
  64. "noviceSkiArea":0,
  65. "advancedSkiArea":0,
  66. "apresSki":0,
  67. "beach":0,
  68. "entertainment":0,
  69. "environmental":0,
  70. "pool":7,
  71. "terrace":0
  72. }
  73. }
  74. }
  75. ],
  76. "scores":{
  77. "general":10,
  78. "aspects":{
  79. "location":{
  80. "general":10,
  81. "COUPLE":10
  82. },
  83. "service":{
  84. "general":0,
  85. "COUPLE":0
  86. },
  87. "priceQuality":{
  88. "general":9,
  89. "COUPLE":9
  90. },
  91. "food":{
  92. "general":0,
  93. "COUPLE":0
  94. },
  95. "room":{
  96. "general":0,
  97. "COUPLE":0
  98. },
  99. "childFriendly":{
  100. "general":9,
  101. "COUPLE":9
  102. },
  103. "interior":{
  104. "general":0,
  105. "COUPLE":0
  106. },
  107. "size":{
  108. "general":0,
  109. "COUPLE":0
  110. },
  111. "activities":{
  112. "general":0,
  113. "COUPLE":0
  114. },
  115. "restaurants":{
  116. "general":0,
  117. "COUPLE":0
  118. },
  119. "sanitaryState":{
  120. "general":0,
  121. "COUPLE":0
  122. },
  123. "accessibility":{
  124. "general":0,
  125. "COUPLE":0
  126. },
  127. "nightlife":{
  128. "general":0,
  129. "COUPLE":0
  130. },
  131. "culture":{
  132. "general":0,
  133. "COUPLE":0
  134. },
  135. "surrounding":{
  136. "general":0,
  137. "COUPLE":0
  138. },
  139. "atmosphere":{
  140. "general":0,
  141. "COUPLE":0
  142. },
  143. "noviceSkiArea":{
  144. "general":0,
  145. "COUPLE":0
  146. },
  147. "advancedSkiArea":{
  148. "general":0,
  149. "COUPLE":0
  150. },
  151. "apresSki":{
  152. "general":0,
  153. "COUPLE":0
  154. },
  155. "beach":{
  156. "general":0,
  157. "COUPLE":0
  158. },
  159. "entertainment":{
  160. "general":0,
  161. "COUPLE":0
  162. },
  163. "environmental":{
  164. "general":0,
  165. "COUPLE":0
  166. },
  167. "pool":{
  168. "general":10,
  169. "COUPLE":10
  170. },
  171. "terrace":{
  172. "general":0,
  173. "COUPLE":0
  174. }
  175. },
  176. "COUPLE":10
  177. }
  178. }

Documentation

Check swagger.yml