【Azure Redis 缓存】Azure Cache for Redis 如何迁移

Azure Cache for Redis 如何迁移

【Azure Redis 缓存】Azure Cache for Redis有默认备份可以用于恢复么?一文中,介绍了使用RDB文件的方式来迁移Redis中的数据或者事备份恢复。与此同时,在Azure Cache for Redis的官方文档描述中,也列举出了有一下三种方式:

  1. 将数据导出到 RDB 文件并将该文件导入 Azure Cache for Redis: 此方法需要在Redis高级版中完成。https://docs.azure.cn/zh-cn/azure-cache-for-redis/cache-migration-guide#export-data-to-an-rdb-file-and-import-it-into-azure-cache-for-redis
  2. 在迁移期间同时写入两个 Redis 缓存: 可以使用应用程序将数据写入现有缓存和要设置的新缓存,而不是直接在缓存之间移动数据。 应用程序一开始仍将从现有缓存中读取数据。 当新缓存拥有必要的数据后,就可以将应用程序切换到该缓存,然后停用旧缓存。https://docs.azure.cn/zh-cn/azure-cache-for-redis/cache-migration-guide#write-to-two-redis-caches-simultaneously-during-migration-period
  3. 以编程方式迁移可以通过编程方式从现有缓存中读取数据并将其写入 Azure Cache for Redis,从而创建自定义迁移过程。https://docs.azure.cn/zh-cn/azure-cache-for-redis/cache-migration-guide#migrate-programmatically

开源工具下载地址:https://github.com/deepakverma/redis-copy 最核心的代码为:

复制代码
    await sourcedb.KeyDumpAsync(key).ContinueWith(dump =>
       {
         if (dump.IsFaulted || dump.IsCanceled)
          {
             throw new AggregateException(dump.Exception);
          }
          else
          {
          //Redis > 3.0, if key already exists it won't overwrite
             destdb.KeyRestoreAsync(key, dump.Result, ttl.Result).ContinueWith(restore =>
             {
               Interlocked.Increment(ref totalKeysCopied);
                percent = ((double)totalKeysCopied / totalKeysSource) * 100;
                TasksInProgress[source] = percent;
             });
          }
       });
复制代码

其最核心的思想使用的是Redis DUMPRESTORE命令。 

DUMP  key:

Serialize the value stored at key in a Redis-specific format and return it to the user. The returned value can be synthesized back into a Redis key using the RESTORE command.

Redis DUMP 命令用于序列化给定 key ,并返回被序列化的值。

RESTORE key

 Create a key associated with a value that is obtained by deserializing the provided serialized value (obtained via DUMP).

 

参考资料

迁移到 Azure Cache for Redis:https://docs.azure.cn/zh-cn/azure-cache-for-redis/cache-migration-guide#migrate-programmatically

Redis 数据备份与恢复: https://www.runoob.com/redis/redis-backup.html

 

posted @   路边两盏灯  阅读(215)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示