接下來準備給各位介紹下如何來實現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
2.安裝依賴包,文檔中有很明確介紹都需要哪些包,直接安裝就好
├─┬ [email protected]
│ └─┬ [email protected]
│ └── [email protected]
├─┬ [email protected]
│ └─┬ [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ └── [email protected]
└── [email protected]
使用NPM安裝各種包
3.下載https://github.com/SaminOz/redis-random-data-generator裏的文件,拷貝到服務器上,可以看到程序本身包含這些文件
4.編輯config.json,添加Azure redis地址還有key
5.運行node generator.js string 999999,隨機插入999999條數據到Azure Redis
6.連接到Azure Redis,通過info可以看到數據量已經有200多M
8.查詢數據,可以看到生成的都是一些隨機數據
當然,不只是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可以查看幫助
準備好數據之後,就可以看如何遷移了!