redisService.js 985 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. 'use strict';
  2. const Service = require('egg').Service;
  3. // redis服务
  4. class RedisService extends Service {
  5. async hget(vin, filed) {
  6. let data;
  7. if (this.app.redis) {
  8. // data = await this.app.redis.hget('faw:iov:fsm:broker:TEST0000000076257', 'SERIES_CODE');
  9. data = await this.app.redis.hget(`faw:iov:fsm:broker:${vin}`, filed);
  10. }
  11. return data;
  12. }
  13. async keys() {
  14. let data;
  15. if (this.app.redis) {
  16. data = await this.app.redis.keys('faw:iov:fsm:broker:*');
  17. }
  18. return data;
  19. }
  20. async getAddress(longitude, latitude) {
  21. const { ctx } = this;
  22. const result = await ctx.curl(
  23. `${this.app.config.GDAPI}?key=${this.app.config.GDKEY}&location=${longitude},${latitude}`);
  24. let address = '';
  25. if (result.status == 200) {
  26. const data = JSON.parse(result.data);
  27. if (data.status == '1') {
  28. address = data.regeocode.formatted_address;
  29. }
  30. }
  31. return address;
  32. }
  33. }
  34. module.exports = RedisService;