通过cron作业将数据存入redis [英] storing data into redis through cron job

查看:26
本文介绍了通过cron作业将数据存入redis的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想每 15 分钟通过一次 cron 作业将数据从 Pandas 存储到 redis 中,以下是我的代码:-

I want to store data into redis from pandas through a cron job every 15 minute and below is my code:-

我每 15 分钟使用以下代码将数据输入到 Pandas 中,并通过 cron 作业将其发送到 redis 字典 mydict2.

I am taking data into pandas every 15 minutes with below code and sending it to the redis dictionary mydict2 through a cron job.

import sys
import pickle
import redis

r = redis.StrictRedis(host='localhost', port=6379, db=0)

test_dict1 = results_df.set_index('user')['ua'].T.to_dict()

p_mydict = pickle.dumps(test_dict1)
r.set('mydict2', p_mydict)

我在密钥 mydict2 中一次又一次地得到相同的输出.基本上我想存储整个月的用户 ID,在月底我想要它的唯一计数.

I am getting the same output again and again in the key mydict2. Basically i want to store user ids for the whole month and at the end of the month i want the unique count of that.

此外,我正在使用 set 方法,假设我拥有大量数据,最好的方法是什么.

Also i am using set method, what could be the best method assuming i am having a very large amount of data.

有人能帮我吗.

推荐答案

替换下方

p_mydict = pickle.dumps(test_dict1)
r.set('mydict2', p_mydict)

    for k, v in test_dict1.items():
        r.hmset(k, {"ua" : v})
    print("Done adding stuff")

字典中的每个键都将是 Redis 中的一个键.

and each key in your dictionary will be a key in Redis.

这篇关于通过cron作业将数据存入redis的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆