由于历史原因,需要将一批key做判断后进行调整,规则如下:
1、如果源端的成绩大于目标端的,那么将源和目标的对应hash的字段相加,更新到目标端。
2、如果源端的成绩小于目标端的,那么将这些key记录下来,提供业务进行手动检查处理。
3、如果源端成绩和目标端相等,那么记录这些key,不做任何其他处理。
PS:相关的IP和字段已经脱敏。
source_ip="192.168.1.1" source_port=$1 source_db=1 dest_ip="192.168.1.2" dest_port=6379 dest_db=1 for i in `cat /home/xiaodongl/check/${source_port}/change_${source_port}.txt` do source_value=($(redis-cli -h $source_ip -p $source_port -n $source_db hmget $i math english|xargs -n2)) dest_value=($(redis-cli -h $dest_ip -p $dest_port -n $dest_db hmget $i math english)) source_math=${source_value[0]} source_english=${source_value[1]} dest_math=${dest_value[0]} dest_english=${dest_value[1]} if [[ -z $dest_math ]];then echo "$dest_ip:$dest_port not have the key $i" >> dest_no_keys.txt else #源比目标大处理 check_ret1=$(echo "$source_math>$dest_math"|bc) if [[ $check_ret1 -eq 1 ]];then new_math=$(echo "$source_math+$dest_math"|bc) new_english=$(echo "$source_english+$dest_english"|bc) echo -e "key $i\t源端:source_math:$source_math\t目标端:dest_math:$dest_math" | tee -a change_${source_port}.log echo -e "key $i\t源端:source_english:$source_english\t目标端:dest_english:$dest_english" | tee -a change_${source_port}.log echo -e "key $i\t待修改后:math:$new_math" | tee -a change_${source_port}.log echo -e "key $i\t待修改后:english:$new_english" | tee -a change_${source_port}.log redis-cli -h $dest_ip -p $dest_port -n $dest_db hmset $i math $new_math english $new_english check_new_value=($(redis-cli -h $dest_ip -p $dest_port -n $dest_db hmget $i math english | xargs -n2)) current_math=${check_new_value[0]} current_english=${check_new_value[1]} echo -e "key $i\t修改后确认:math:$current_math" | tee -a change_${source_port}.log echo -e "key $i\t修改后确认:english:$current_english" | tee -a change_${source_port}.log echo | tee -a change_${source_port}.log fi #源比目标小处理 check_ret2=$(echo "$source_math<$dest_math"|bc) if [[ $check_ret2 -eq 1 ]];then echo "key $i\t源端比目标端小未处理,需确认." | tee -a check_${source_port}.log echo "--------key:$i--------------" | tee -a check_${source_port}.log echo "源端:math:$source_math" | tee -a check_${source_port}.log echo "目标端:math:$dest_math" | tee -a check_${source_port}.log echo "源端:english:$source_english" | tee -a check_${source_port}.log echo "目标端:english:$dest_english" | tee -a check_${source_port}.log echo | tee -a check_${source_port}.log continue fi #源和目标相等 check_ret3=$(echo "$source_math==$dest_math"|bc) if [[ $check_ret3 -eq 1 ]];then echo "key $i\t源端和目标端相等,未处理." | tee -a equal_${source_port}.log echo "--------key:$i--------------" | tee -a equal_${source_port}.log echo "源端:math:$source_math" | tee -a equal_${source_port}.log echo "目标端:math:$dest_math" | tee -a equal_${source_port}.log echo "源端:english:$source_english" | tee -a equal_${source_port}.log echo "目标端:english:$dest_english" | tee -a equal_${source_port}.log echo | tee -a equal_${source_port}.log continue fi fi done