Azure Redis 系列之 Azure Redis 生成随机数据

    接下来准备给各位介绍下如何来实现Azure Redis数据的迁移,我们经常会收到一些需求,就是客户需要将线下或者其他云上的Redis迁移到微软的Azure Redis,或者是从微软的某个region的Azure redis迁移到其他region


    对于这些需求,我们其实可以通过分析,来判断我们应该用什么样的方法进行迁移,对于Azure Redis premium版本来说,我们是可以支持将数据导出到blob里,然后再导入到Premium版本的redis中的,这种迁移方法相对来说比较简单粗暴,但是Premium版本并不是每个用户都会用的,而且Azure Redis也没办法从Premium版本降到Standard版本,所以这种迁移方法本身就有一定的局限性,之后准备介绍一个微软提供的跨region迁移Redis的方法,但是在这之前,我们需要先准备一些测试的数据,测试数据要尽量能模拟生产环境的模式,而且数据量不能太小,所以给各位介绍一个生成redis随机数据的工具


    首先感谢这位大佬提供的工具https://github.com/SaminOz/redis-random-data-generator

    这个程序本身是用node.js写的,所以我们首先需要准备好node.js的环境


    1.先在linux服务器装好node.js

    sudo yum install node.js

    1.png


    2.安装依赖包,文档中有很明确介绍都需要哪些包,直接安装就好

    

├─┬ [email protected]
└─┬ [email protected]
└── [email protected]
├─┬ [email protected]
└─┬ [email protected]
├── [email protected]
├── [email protected]
└── [email protected]
└── [email protected]



    2.png


    使用NPM安装各种包

    3.png   


    3.下载https://github.com/SaminOz/redis-random-data-generator里的文件,拷贝到服务器上,可以看到程序本身包含这些文件

    4.png


    4.编辑config.json,添加Azure redis地址还有key

5.png


    5.运行node generator.js string 999999,随机插入999999条数据到Azure Redis

6.png


    6.连接到Azure Redis,通过info可以看到数据量已经有200多M

7.png


    8.查询数据,可以看到生成的都是一些随机数据

9.png


    当然,不只是string,这个程序还可以支持redis其他格式的数据,用起来还是很方便的

    

    以下是这个程序的一些基本用法

    Basic Usage:

    node generator.js <type> <qty> [<key_prefix>]

    This will enter <qty> of <type> entries into the redis instance

    running at the server and port address set in the config.json

    file.

    If <key_prefix> is set then this will be prepended to the key (uuid) separated by a ":" - thanks to Alfonso Montero for this contribution

    node generator.js hash 100 session

    1)...

    100) "session:ffab3b35-09c3-4fd7-9af1-4d323534065e"

    

    Types (others may be added in future versions i.e. geohash):

    'string' uses SET to add a redis string value

    'list' uses LPUSH to add a random number of values to a list

    'set' uses SADD to add a random number of values to a set

    'sorted' uses ZADD to add a random number of values and scores

    to a sorted set.

    'hash' uses HMSET to add a random number of values to a hash


    node generator.js –help可以查看帮助

    10.png


    准备好数据之后,就可以看如何迁移了!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章