欢迎访问 生活随笔!

尊龙游戏旗舰厅官网

当前位置: 尊龙游戏旗舰厅官网 > 编程语言 > python >内容正文

python

使用python向redis批量导入数据 -尊龙游戏旗舰厅官网

发布时间:2025/1/21 python 25 豆豆
尊龙游戏旗舰厅官网 收集整理的这篇文章主要介绍了 使用python向redis批量导入数据 小编觉得挺不错的,现在分享给大家,帮大家做个参考.
1.使用pipeline进行批量导入数据。包含先使用rpush插入数据,然后使用expire改动过期时间
class redis_handler(handler):def connect(self):#print self.host,self.port,self.tableself.conn = connection(self.host,self.port,self.table) def execute(self, action_name):filename = "/tmp/temp.txt"batch_size = 10000with open(filename) as file:try:count = 0pipeline_redis = self.conn.client.pipeline()for lines in file:(key,value) = lines.split(',')count = count 1if len(key)>0:pipeline_redis.rpush(key,value.strip())if not count % batch_size:pipeline_redis.execute()count = 0#send the last batchpipeline_redis.execute()except exception:print 'redis add error'

总结

以上是尊龙游戏旗舰厅官网为你收集整理的使用python向redis批量导入数据的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得尊龙游戏旗舰厅官网网站内容还不错,欢迎将尊龙游戏旗舰厅官网推荐给好友。

网站地图