From 2b414703cf140107a37f591fb2517e4d06c02a9f Mon Sep 17 00:00:00 2001 From: Christoph Stenglein Date: Wed, 16 Aug 2023 18:36:53 +0200 Subject: [PATCH] (background.scan): only init values if they do not exist --- home.admin/_background.scan.sh | 40 ++++++++++---------- home.admin/_cache.sh | 69 +++++++++++++++++++--------------- 2 files changed, 58 insertions(+), 51 deletions(-) diff --git a/home.admin/_background.scan.sh b/home.admin/_background.scan.sh index 52176c47..4df91a4a 100755 --- a/home.admin/_background.scan.sh +++ b/home.admin/_background.scan.sh @@ -13,7 +13,7 @@ if [ "$1" == "only-one-loop" ]; then fi # start with parameter "install" (to setup service as systemd background running) if [ "$1" == "install" ]; then - + # write systemd service cat > /etc/systemd/system/background.scan.service </dev/null + redis-cli set ${NX} ${keystr} "${valuestr}" ${additionalParams} 1>/dev/null # set in redis the timestamp timestamp=$(date +%s) - redis-cli set ${keystr}${META_LASTTOUCH_TS} "${timestamp}" ${additionalParams} 1>/dev/null + redis-cli set ${NX} ${keystr}${META_LASTTOUCH_TS} "${timestamp}" ${additionalParams} 1>/dev/null #echo "# lasttouch(${timestamp})" # check if the value has a outdate policy outdatesecs=$(redis-cli get ${keystr}${META_OUTDATED_SECONDS}) if [ "${outdatesecs}" == "" ]; then outdatesecs="-1" - fi + fi #echo "# outdatesecs(${outdatesecs})" if [ "${outdatesecs}" != "-1" ]; then - # set exipire valid flag (if its gone - value is considered as outdated) + # set expire valid flag (if its gone - value is considered as outdated) redis-cli set ${keystr}${META_VALID_FLAG} "1" EX ${outdatesecs} 1>/dev/null fi @@ -186,7 +193,7 @@ elif [ "$1" = "get" ]; then position=0 for keystr in $@ do - + # skip first parameter ((position++)) if [ $position -eq 1 ]; then @@ -243,7 +250,7 @@ elif [ "$1" = "export" ]; then # get parameter keyfilter="${2}*" - # go thru all keys by keyfilter + # go through all keys by keyfilter keylist=$(redis-cli KEYS "${keyfilter}") readarray -t arr <<< "${keylist}" for key in "${arr[@]}";do @@ -266,7 +273,7 @@ elif [ "$1" = "export" ]; then ################################## # COUNT -# count value up +# increment value ################################## # set @@ -309,7 +316,7 @@ elif [ "$1" = "focus" ]; then for key in "${arr[@]}";do if [ "${key}" == "" ]; then continue - fi + fi keyClean=$(echo $key | cut -d ":" -f1) value=$(redis-cli get "${key}") echo "${keyClean}=${value}" @@ -324,7 +331,7 @@ elif [ "$1" = "focus" ]; then exit fi - # sanatize parameters (if not -1) + # sanitize parameters (if not -1) outdatesecs="${outdatesecs//[^0-9.]/}" # check that key & value are given @@ -333,7 +340,7 @@ elif [ "$1" = "focus" ]; then exit 1 fi - # add an expire flag if given + # add an expire flag if given additionalParams="" if [ "${durationsecs//[^0-9.]/}" != "" ]; then additionalParams="EX ${durationsecs//[^0-9.]/}" @@ -358,13 +365,13 @@ elif [ "$1" = "meta" ]; then keystr=$2 default=$3 - # check that key & value are given + # check that key & value are provided if [ "${keystr}" == "" ]; then echo "# Fail: missing parameter" exit 1 fi - - # get redis basic value + + # get redis basic value valuestr=$(redis-cli get ${keystr}) echo "value=\"${valuestr}\"" @@ -380,7 +387,7 @@ elif [ "$1" = "meta" ]; then # get META_OUTDATED_SECONDS outdatesecs=$(redis-cli get ${keystr}${META_OUTDATED_SECONDS}) if [ "${outdatesecs}" == "" ]; then - # default is -1 --> never outdate + # default is -1 --> never outdate outdatesecs="-1" fi echo "outdatesecs=\"${outdatesecs}\"" @@ -406,7 +413,7 @@ elif [ "$1" = "valid" ]; then lasttouch_overall="" for keystr in $@ do - + # skip first parameter from script - thats the action string ((position++)) if [ $position -eq 1 ]; then @@ -436,7 +443,7 @@ elif [ "$1" = "valid" ]; then # get outdate police of value (outdated = not valid anymore) outdatesecs=$(redis-cli get ${keystr}${META_OUTDATED_SECONDS}) #echo "# ${keystr}${META_OUTDATED_SECONDS}=\"${outdatesecs}\"" - + # if outdate policy is default or -1 ==> never outdated if [ "${outdatesecs}" == "" ] || [ "${outdatesecs}" == "-1" ]; then continue @@ -453,7 +460,7 @@ elif [ "$1" = "valid" ]; then # so valid flag does not exists anymore # ==> this means value is outdated - # break loop and + # break loop and echo "stillvalid=\"0\"" exit 0