标签:输入数据 进一步 统计 roc 结构 into run remove 取出
问题背景: php读取线上redis数据,常常不稳定,数据响应时有时无。
解决方法:多次读取。每次读取全部上一次没读出的数据,直到全部获取。
本文实现用shell进行多次redis数据读取, 每次取出当中的有效值(对于我们的样例中,就是给key,能在redis上取得其value的为有效值。其它无效),并将无效值重跑一遍,以此迭代,直到全部redis数据被取出。PS:redis数据能够由php或C读出,给定接口的话很easy,详细能够參考phpredis。。因为可能涉密,本文中不给出这块的实现。
方法概述:
项目结构:
详细实现:
all.sh :
#Author:Rachel Zhang
#Email: zrqjennifer@sina.com
for file in source/*
do
{
echo "processing source $file"
if test -f $file
then
php getredis.php $file > result/$file
fi
echo "$file done..."
}&
done
analyze_result.sh:
#Author:Rachel Zhang
#Email: zrqjennifer@sina.com
Filefolder=result/source/*
#Filefolder=source/*
echo "##################################"
echo " In Folder $Filefolder"
echo "##################################"
nl=0
hv=0
for file in $Filefolder
do
if test -f $file
then
fline=`wc -l $file | awk ‘{print $1}‘`
nl=$(($nl+$fline))
fvalue=`cat $file |awk ‘BEGIN{x=0;}{if($2) x=x+1;}END{print x;}‘`
hv=$(($hv+$fvalue))
fi
done
echo "totally $nl lines"
echo "$hv lines have tag value"
##################################
#combine results into one file
if [ "$#" -gt 0 ]
then
if test -e "result/all.result"
then
mv result/all.result result/all.result.bak
fi
for file in $Filefolder
do
if test -f $file
then
cat $file >> result/all.result
fi
done
echo "all the output are write in result/all.result"
# put null-value keys into source/step2/contsigns
if test -e source/step2
then
mkdir source/step2
fi
cat result/all.result| awk ‘{if($2==null) print}‘ > source/step2/contsigns
Nnull_value=`wc -l source/step2/contsigns | awk ‘{print $1}‘`
echo "remaining ${Nnull_value} keys to be processed"
# put has-value key-value into result/steps/step${step_id}.res
step_id=1
while test -e result/steps/step${step_id}.res
do
step_id=$(($step_id+1))
done
cat result/all.result | awk ‘{if($2) print}‘ > result/steps/step${step_id}.res
echo "current valid results are writen in result/steps/step${step_id}.res"
# remove the current source files, generate new source files and re-run all.sh
echo "remove current source and result files? (y/n)"
read answer
if [ $answer == "y" ]; then
if [ $Nnull_value -gt 10 ]; then
rm source/*
rm result/source/*
cd source && split -l 5000 step2/contsigns && cd ../
echo "now re-run sh ./all.sh? (y/n)"
read answer
if [ $answer == "y" ]; then
sh all.sh
fi
fi
fi
fi
PS: 以上analyze_result.sh 还能够去掉analyze_result.sh中的interactive部分(无需用户输入)。通过crontab进行定时,进一步自己主动化运行。
标签:输入数据 进一步 统计 roc 结构 into run remove 取出
原文地址:http://www.cnblogs.com/yangykaifa/p/7128451.html