Skip to content

Instantly share code, notes, and snippets.

@yuryoparin
Last active August 29, 2015 14:00
Show Gist options
  • Save yuryoparin/b5d96d1e5364f7b9d1ea to your computer and use it in GitHub Desktop.
Save yuryoparin/b5d96d1e5364f7b9d1ea to your computer and use it in GitHub Desktop.
Put Google OAuth 2.0 access token to Redis
#echo "access_token = $access_token" # valid for 3600 seconds
access_token=ya29.1.AADtN_XKybIzhN-3SUdWkwm2AETJWRKjaiimgTA4U2tR2yF2R42b16Ipz-03FfUI
# The while-loop waits 60 seconds for Redis to start after reboot
cnt=0
PING=$(/usr/local/bin/redis-cli PING 2>&1) # stderr to stdout
while [ "$PING" != "PONG" ] && (($cnt < 6)); do
sleep 10;
let cnt=$cnt+1
PING=$(/usr/local/bin/redis-cli PING 2>&1)
echo "cnt = $cnt, PING = $PING"
done
log_date=$(date +'%Y/%m/%d %T')
if [[ $PING == 'PONG' ]]; then
# Redis key: google-access-token
redis_result=$(/usr/local/bin/redis-cli SET google-access-token "$access_token")
echo "[$log_date] access_token = $access_token, exp = $exp, redis SET google-access-token [$redis_result], redis_connection_attempts = $cnt"
else
echo "[$log_date] access_token = $access_token, exp = $exp, REDIS IS NOT UP: $PING"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment