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

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

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

Contributors (1)