当前位置:网站首页>Redis Data Migration Method III
Redis Data Migration Method III
2022-07-19 03:53:00 【Notes de Lao Wang】
Cette méthode a été élaborée parShellScript,Obtenir un par unkey,SelonKEYDifférents types un par unKEYMigration,Lent.,L'utilisation en grandes quantités n'est pas recommandée
#!/bin/bash
#Adresse
host='127.0.0.1'
#Port Source
src_port=7000
#Port de destination
dest_port=8000
#Compteur,Compter le nombre de migrationsKEY,Impression finale
cnt=0
#Traverser toutKEY
for k in `redis-cli -h $host -p $src_port keys "*"`
do
data_type=`redis-cli -h $host -p $src_port type $k`
#Juger un par unKEYAprès le type,Oui.KEYLisez - le.,Écrire à la cibleRedis
case $data_type in
'string')
v=`redis-cli -h $host -p $src_port get $k`
redis-cli -h $host -p $dest_port set $k $v
;;
'list')
values=`redis-cli -h $host -p $src_port lrange $k 0 -1`
redis-cli -h $host -p $dest_port lpush $k $values
;;
'set')
values=`redis-cli -h $host -p $src_port smembers $k`
redis-cli -h $host -p $dest_port sadd $k $values
;;
'hash')
for key in `redis-cli -h $host -p $src_port hkeys $k`
do
hvalue=`redis-cli -h $host -p $src_port hget $k $key`
redis-cli -h $host -p $dest_port hset $k $key $hvalue
done
;;
*)
echo "not known type"
;;
esac
let cnt++
done
# Imprimer la migration KEY
echo $cntMise en œuvre
bak]# sh m.sh
OK
(integer) 1
(integer) 1
(integer) 1
OK
OK
OK
(integer) 3
OK
OK
(integer) 1
OK
(integer) 5
OK
OK
(integer) 1
(integer) 1
OK
15Validation des résultats
bak]# redis-cli -h 127.0.0.1 -p 8000 keys '*'
1) "k2"
2) "sname"
3) "k10"
4) "k4"
5) "hclass1"
6) "k8"
7) "k9"
8) "hclass2"
9) "k3"
10) "k6"
11) "lname"
12) "hclass3"
13) "k1"
14) "k7"
15) "k5"Note:: Voir en lignepythonScript, Parce que je fais python Erreur de code ,Remplacer manuellement parshellScript;
Les intérêts peuvent être mentionnés:
#coding=utf-8
import redis
redis_from = redis.StrictRedis(host='127.0.0.1', port=6379, db=10)
redis_to = redis.StrictRedis(host='127.0.0.1', port=6379, db=0)
if __name__ == '__main__':
cnt = 0
for k in redis_from.keys():
data_type = redis_from.type(k)
if data_type == 'string':
v = redis_from.get(k)
redis_to.set(k, v)
elif data_type == 'list':
values = redis_from.lrange(k, 0, -1)
redis_to.lpush(k, values)
elif data_type == 'set':
values = redis_from.smembers(k)
redis_to.sadd(k, values)
elif data_type == 'hash':
keys = redis_from.hkeys(k)
for key in keys:
value = redis_from.hget(k, key)
redis_to.hset(k, key, value)
else:
print 'not known type'
cnt = cnt + 1
print 'total', cnt边栏推荐
猜你喜欢

A robust deformation convolution neural network image denoising

The role of key in V-for

Hcip Experiment 5

Sword finger offer 59 - ii Maximum value of queue

Assembly line technology

Boston house price analysis assignment summary

Chapter II: news topic classification tasks

windows10:vscode下go语言的适配

Web semantics (emphasis tag EM italic) (emphasis tag strong bold) (custom list: DL, DT, DD)

SparkCore核心设计:RDD,220716,
随机推荐
Underline shortcut
波士顿房价分析作业总结
【LeetCode】558. Intersection of quadtree
Vision Transformer(1):Self-attention Multi-head Self-attention
[2016 CCPC Hangzhou j] just a math problem (Mobius inversion)
Nature Communications
Qt OpenGL 通过鼠标和键盘移动三维物体(设置相机)
鼠标滑动两张图片前后对比js插件
Chapter II: news topic classification tasks
剑指 Offer 59 - II. 队列的最大值
STM32 serial port sending and receiving multiple data tutorial based on gas sensor practice
使用Flink1.14操作Iceberg0.13
KlakNdI 同步画面简单使用
ulsm配置案例
Jmeter常用功能-参数化介绍
go环境安装
企业钟情于混合 App 开发,小程序容器技术能让效率提升 100%
HCIP实验5
Sword finger offer 59 - ii Maximum value of queue
options has an unknown property ‘before‘