pandas 读取redis

# !/usr/bin/env Python3
# -*- coding: utf-8 -*-
# @Author   : zsc
# @FILE     : redis获取.py
# @Time     : 2020/6/11 12:50
# @Software : PyCharm

import redis
import json
import pandas as pd
from sqlalchemy import create_engine

engine = create_engine("mysql+pymysql://user:password@ip:port/db")


def redis_df():
    pool = redis.ConnectionPool(host='host', port='poty', db=0, password='password')
    cur = redis.Redis(connection_pool=pool)
    all_keys = [pd.DataFrame([{'name': key.decode("utf-8"), "cookies": len(json.loads(cur.get(key)))}]) for key in
                cur.keys() if key is not None]
    return pd.concat(all_keys, axis=0, ignore_index=True)


df = redis_df()
# df['update_time'] = datetime.datetime.now()
print(df)

 

你可能感兴趣的:(np,and,pd)