zoukankan      html  css  js  c++  java
  • 一个导出redis有序集合sorted-sets的shell脚本

    1. 通过keys匹配需要导出的有序集合名称,这些集合命名格式为:*_010_09/Dec/2015
    2. 依次通过zscan导出有序集合中的数据,并分别保存

    #/bin/sh
    zset_pattern=”*_010_09/Dec/2015″
    keys=`redis-cli keys $zset_pattern`
    for k in $keys;do

    _date=`echo “$k”|awk -F”_” ‘{print $3}’|awk -F”/” ‘{print $3″_”$2″_”$1}’`
    out=`echo “$k”|awk -F”_” ‘{print $1″_”$2}’`”_$_date.txt”
    cursor=0

    batches=0
    while [ 1==1 ];do

    reply=`redis-cli zscan $k $cursor`
    cursor=`echo “$reply” | head -n 1`

    pairs=`echo “$reply”|tail -n +2`

    [ $cursor -eq 0 ] && [ $batches -gt 0 ] && break
    batches=`expr $batches + 1`


    skip_key=0
    echo “$pairs”|while read ms

    do

    #skip empty members
    [ “$ms” == “” ] && skip_key=1 && continue
    [ $skip_key -eq 1 ] && skip_key=0 && continue
    if [ “$m” == “” ];then

    m=$ms && continue

    fi
    if [ “$s” == “” ];then

    s=$ms
    echo “$m $s” >> $out
    m=”” && s=””

    fi

    done

    done

    done

     

    零一积流|IT参考 原创文章,转载请注明出处: http://www.it-refer.com/2015/12/14/a-shell-script-to-export-data-of-sorted-sets-from-redis

  • 相关阅读:
    Java的特性和优势
    MyBatis
    SpringBoot简介
    Liunx
    MySql简介与入门
    Volatile
    MySQL简介
    Redis
    Spring IoC
    什么是springboot
  • 原文地址:https://www.cnblogs.com/rd-log/p/5045239.html
Copyright © 2011-2022 走看看