Skip to main content

kc_utils

Project description

kc_utils

install

pip install --upgrade kc_utils -i https://pypi.org/simple/
pip install --upgrade kc_utils['cache_redis'] -i https://pypi.org/simple/

use

time

  • get_time
#:param num: 和unit配合使用计算时间
#:param sf: %Y%m%d%H%M%S
#:param unit: days = None, seconds = None, microseconds = None, milliseconds = None, minutes = None, hours = None, weeks = None
#:return: %Y%m%d%H%M%S 格式化时间
from kc_utils.time import get_time
get_time() #'20220320'
get_time(1) #'20220321'
get_time(-1) #'20220319'
get_time(-1, sf="%Y%m%d%H%M%S") #'20220319055451'
get_time(-1, sf="%Y%m%d%H%M%S", unit="hours") #'20220320045504'
  • format_time
#:param log_date: 字符串日期
#:param sf: %Y%m%d%H%M%S
#:param new_sf: %Y%m%d%H%M%S
#:return: 字符串日期
from kc_utils.time import get_time, format_time
format_time(get_time()) # '2022-03-20'

cache

pip install --upgrade kc_utils['cache_redis'] -i https://pypi.org/simple/
  • redis
#redis 装饰器
#:param time: ttl
## time==0 or redis_store=None, 则不走缓存;
## time > 0, 则走缓存,缓存时间为time;
## time = -1, 则走缓存,缓存时间为永久.
## time = -2, 则不走缓存,并覆盖现有缓存
#:param redis_key_prefix: redis key prefix
#:param redis_store: redis_store

from kc_utils.cache.redis_helper import redising,KcRedis

db_redis = KcRedis(host='x', port=6379, password="xxx").get_redis()

@redising(time=10, redis_key_prefix="test", redis_store=db_redis)
def func_xxx(*args, **kwargs):
    return "xxx"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kc_utils-0.0.1.tar.gz (3.7 kB view details)

Uploaded Source

File details

Details for the file kc_utils-0.0.1.tar.gz.

File metadata

  • Download URL: kc_utils-0.0.1.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.8.2 requests/2.22.0 setuptools/44.0.0.post20200106 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/2.7.18

File hashes

Hashes for kc_utils-0.0.1.tar.gz
Algorithm Hash digest
SHA256 fe8eef8bf32403842323e1c49f7883d2cd90602ebada16715a8db73d330160dc
MD5 bb70d2dc81ca17c70de97d1e74dc3ffd
BLAKE2b-256 3db5756b719545ff8280422a54e136e88f82bcf37e5c246c14ac94c0953bc33d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page