Skip to content

Instantly share code, notes, and snippets.

@stephanustedy
Last active April 22, 2020 12:17
Show Gist options
  • Save stephanustedy/eb1d0c0daf5cc83373513b1f6980be52 to your computer and use it in GitHub Desktop.
Save stephanustedy/eb1d0c0daf5cc83373513b1f6980be52 to your computer and use it in GitHub Desktop.
command for copy redis
# COPY REAL TIME / NEW DATA
while true; do exec redis-cli -h [old-endpoint] monitor | sed -u 's/.*]//' | grep -vi "get\|ping" | redis-cli -h [new-endpoint] >> /dev/null; done;
# COPY DATA ON REDIS with TTL
redis-cli -h [old-endpoint] --scan | while read key; do tempTTL=$(redis-cli -h [old-endpoint] TTL "$key"); ttl=$tempTTL;if [ $tempTTL -lt 0 ]; then ttl=0; fi; redis-cli -h [old-endpoint] --raw DUMP "$key" | head -c -1 |redis-cli -x -h [new-endpoint] RESTORE "$key" $ttl; echo "copied $key $ttl"; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment