You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

redis_utils.py 1.9 kB

5 years ago
5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # -*- coding: UTF-8 -*-
  2. # Copyright 2020 Zhejiang Lab. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # =============================================================
  16. import redis
  17. from pathlib import Path
  18. from .config_utils import ConfigInstance
  19. # Singleton mode
  20. class RedisUtils:
  21. def __init__(self):
  22. self.conn = redis.Redis(
  23. host=ConfigInstance.conf_redis_host(),
  24. port=ConfigInstance.conf_redis_port(),
  25. password=ConfigInstance.conf_redis_password(),
  26. decode_responses=True,
  27. db=ConfigInstance.conf_redis_db()
  28. )
  29. def get_file_path(self, uid, run, type, tag):
  30. _key = uid + '_' + run + '_' + type + '_' + tag
  31. return Path(self.conn.get(_key))
  32. def send_message(self, msg):
  33. self.conn.lpush("sessions", msg)
  34. def lpush(self, name, value):
  35. self.conn.lpush(name, value)
  36. def brpop(self, name, timeout=0):
  37. return self.conn.brpop(name, timeout)
  38. def exist(self, name):
  39. return self.conn.exists(name)
  40. def get(self, name):
  41. return self.conn.get(name)
  42. def set(self, name, value):
  43. self.conn.set(name, value)
  44. def flushdb(self):
  45. self.conn.flushdb()
  46. def delete(self, name):
  47. self.conn.delete(name)
  48. def keys(self, pattern='*'):
  49. return self.conn.keys(pattern)
  50. RedisInstance = RedisUtils()

一站式算法开发平台、高性能分布式深度学习框架、先进算法模型库、视觉模型炼知平台、数据可视化分析平台等一系列平台及工具,在模型高效分布式训练、数据处理和可视分析、模型炼知和轻量化等技术上形成独特优势,目前已在产学研等各领域近千家单位及个人提供AI应用赋能

Contributors (1)