当前位置: 首页 > news >正文

网站建设实训进程计划专业建设网站公司哪家好

网站建设实训进程计划,专业建设网站公司哪家好,多种东莞微信网站建设,兰州网站建设方法背景 需求#xff1a;需要将的 Redis 数据迁移由云厂商 A 迁移至云厂商 B问题#xff1a;云版本的 Redis 版本不支持 SYNC、MIGRATE、BGSAVE 等命令#xff0c;使得许多工具用不了#xff08;如 redis-port#xff09; 思路 #xff08;1#xff09;从 Redis A 获取所…背景 需求需要将的 Redis 数据迁移由云厂商 A 迁移至云厂商 B问题云版本的 Redis 版本不支持 SYNC、MIGRATE、BGSAVE 等命令使得许多工具用不了如 redis-port 思路 1从 Redis A 获取所有 key依次导出数据2将导出的数据加载到 Redis B 实现 示例将 127.0.0.1:6379 数据迁移至 127.0.0.1:6380 导出脚本 export.py from optparse import OptionParser import os import redis import logging import sysmylogger None fdata Nonedef new_logger(logger_nameAppName,levellogging.INFO,to_fileTrue,log_file_nameapp.log,format[%(asctime)s] %(filename)s:%(lineno)d %(message)s):if to_file:handler logging.FileHandler(log_file_name)else:handler logging.StreamHandler(sys.stdout)handler.setFormatter(logging.Formatter(format))logger logging.getLogger(logger_name)logger.addHandler(handler)logger.setLevel(level)return loggerdef gen_redis_proto(*args):Write out the string in redis protocol so it can be replayed back laterproto *{0}\\r\\n.format(len(args))for arg in args:proto ${0}\\r\\n.format(len(arg))proto {0}\\r\\n.format(arg)return proto# 只取出指定前缀的 key def match_key(key: str):return key.startswith(normal)def extract(options, fd, logg: logging.Logger):src_r redis.StrictRedis(hostoptions.redis_source_url, portoptions.redis_source_port, dboptions.redis_source_db)all_keys src_r.keys(*)for key in all_keys:key_type arr []try:key key.decode(utf8)if not match_key(key):continuekey_type src_r.type(key).decode(utf8)if key_type hash:arr.append(HMSET)arr.append(key)for k, v in src_r.hgetall(key).items():arr.append(k.decode(utf8))arr.append(v.decode(utf8))elif key_type string:arr.append(SET)arr.append(key)arr.append(src_r.get(key).decode(utf8))elif key_type set:arr.append(SADD)arr.append(key)arr.extend([v.decode(utf8) for v in src_r.smembers(key)])elif key_type list:arr.append(LPUSH)arr.append(key)arr.extend([v.decode(utf8) for v in src_r.lrange(key, 0, -1)])elif key_type zset:arr.append(ZADD)arr.append(key)for member, score in src_r.zrange(key, 0, -1, withscoresTrue):arr.append(str(score))arr.append(member.decode(utf8))else:# TODO 其它的数据类型logg.error(Unsupported key type detected: {}, key: {}.format(key_type, key))continuefd.write(gen_redis_proto(*arr) \n)# 设置 ttlttl src_r.ttl(key)if ttl ! -1:fd.write(gen_redis_proto(*[EXPIRE, key, str(ttl)]) \n)except Exception as e:logg.error(Unsupported key type detected: {}, key: {}, error: {}.format(key_type, key, e.__str__()))if __name__ __main__:parser OptionParser()parser.add_option(-s, --redis-source-url,actionstore,destredis_source_url,helpThe url of the source redis which is to be cloned [required])parser.add_option(-p, --redis-source-port,actionstore,destredis_source_port,default6379,typeint,helpThe port of the source redis which is to be cloned [required, \default: 6379])parser.add_option(-n, --redis-source-db,actionstore,destredis_source_db,default0,typeint,helpThe db num of the source redis[required, default: 0])parser.add_option(-o, --redis-data-output-file-name,actionstore,destredis_data_output_file_name,defaultredis.data,typestr,helpThe output file name of the source redis data[required, default: redis.data])parser.add_option(-l, --log-file-name,actionstore,destlog_file_name,defaultapp.log,typestr,helpThe log file name[required, default: app.log])(options, args) parser.parse_args()if not (options.redis_source_url and options.redis_source_port):parser.error(redis-source-url, redis-source-port are required arguments. Please see help)data_path options.redis_data_output_file_nameif os.path.exists(data_path):os.remove(data_path)mylogger new_logger(to_fileTrue, levellogging.ERROR, log_file_nameoptions.log_file_name)with open(data_path, a) as fd:extract(options, fd, mylogger)导出数据 $ python export.py -s 127.0.0.1 -p 6379$ head redis.data *5\r\n$5\r\nLPUSH\r\n$11\r\nnormalQueue\r\n$3\r\nccc\r\n$2\r\nbb\r\n$3\r\naaa\r\n *8\r\n$4\r\nSADD\r\n$9\r\nnormalSet\r\n$2\r\ndd\r\n$2\r\nbb\r\n$2\r\ncc\r\n$2\r\nee\r\n$2\r\naa\r\n$2\r\nff\r\n *3\r\n$6\r\nEXPIRE\r\n$9\r\nnormalSet\r\n$4\r\n1728\r\n *6\r\n$5\r\nHMSET\r\n$10\r\nnormalHash\r\n$2\r\nk1\r\n$2\r\nv1\r\n$2\r\nk2\r\n$2\r\nv2\r\n *3\r\n$3\r\nSET\r\n$9\r\nnormalStr\r\n$3\r\nvvv\r\n导入脚本 load.sh #!/bin/shwhile read -r line donohup printf %b $line| redis-cli -p 6380 --pipe load-std.log 2 load-err.log done $1导入数据 sh load.sh redis.data参考 https://stackoverflow.com/questions/44288974/sync-with-master-failed-err-unknown-command-synchttps://gist.github.com/jimmyislive/0efd7a6a1c7f7afd73e8#file-clone_redis-py
http://wiki.neutronadmin.com/news/264638/

相关文章:

  • 简单的asp网站源码WordPress 教育模板
  • 山东网站开发学校怎么制作商城小程序
  • 做外贸生意最好的网站网络运营策划
  • 做门户网站cmswordpress yusi
  • 留学网站建设网络公司的推广
  • 做网站很火的APP万网 网站建设
  • 专业做室内设计的网站有哪些内容wordpress不显示网站标题
  • 济南网站搭建公司青岛seo推广
  • 网站文章收录查询山西建筑工程集团有限公司
  • 定州网站建设兼职服装行业做推广网站
  • 着力规范网站集约化建设wordpress 留言插件
  • 做网站的流程知乎北戴河区建设局网站
  • pac网站代理seozhun
  • 北理离线《网站开发与应用》平面网页设计教学
  • 网站开发常用js函数官方网站下载拼多多
  • 备案中的网站名称微信开发公司怎么样
  • 网站域名注册哪家好东莞排名推广
  • 网站免费制作教程珠海高端网站建设
  • 阳春做网站公司学习做网站多久
  • 如何让网站火起来wordpress 获取当前文章id
  • 做网站美工工资多少wordpress首页文章显示固定分类
  • 网站筑云做关键词网站建设哪里找
  • 广西南宁建设银行最新招聘网站wordpress的插件下载地址
  • 网站建设需求量深圳住房与建设局网站
  • 自适应型网站建设费用邢台做wap网站的公司
  • 滨海新区建设网站平面设计公司赚钱吗
  • 响应式网站头部企业网站改版建议
  • 福田做网站公司怎么选择肇庆免费模板建站
  • 网址大全123官方网站品牌推广专员
  • 优秀的学校网站欣赏h5网站做微信小程序