forked from larksuite/oapi-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
42 lines (30 loc) · 1.47 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- coding: UTF-8 -*-
from typing import Tuple
import redis
import logging
from larksuiteoapi import Store, Config, AppSettings, Logger, LEVEL_DEBUG, LEVEL_INFO, LEVEL_WARN, LEVEL_ERROR, \
DefaultLogger
class RedisStore(Store):
def __init__(self):
self.cli = redis.StrictRedis(host='localhost', port=6379, db=0)
def get(self, key): # type: (str) -> Tuple[bool, str]
value = self.cli.get(key)
if value:
return True, value.decode('utf-8')
return False, ""
def set(self, key, value, expire): # type: (str, str, int) -> None
"""
storage key, value into the store, value has an expire time.(unit: second)
"""
self.cli.set(key, value, ex=expire)
def test_config_with_memory_store(domain, app_settings):
# type: (str, AppSettings) -> Config
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
return Config.new_config_with_memory_store(domain, app_settings, DefaultLogger(), LEVEL_DEBUG)
def test_config_with_redis_store(domain, app_settings):
# type: (str, AppSettings) -> Config
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
return new_config_with_redis_store(domain, app_settings, DefaultLogger(), LEVEL_DEBUG)
def new_config_with_redis_store(domain, app_settings, logger, log_level):
# type: (str, AppSettings, Logger, int) -> Config
return Config.new_config(domain, app_settings, logger, log_level, RedisStore())