Last active
August 27, 2015 15:26
-
-
Save Lax/23f45c070fceec590384 to your computer and use it in GitHub Desktop.
transfer item from one redis queue to another
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import redis | |
POOL = redis.ConnectionPool(host='127.0.0.1', port=6379, db=0) | |
if __name__=="__main__": | |
while True: | |
my_server = redis.Redis(connection_pool=POOL) | |
kafka_message = my_server.lpop("src:queue") | |
if kafka_message: | |
my_server.rpush("dst:queue",kafka_message) | |
else: | |
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -x | |
while true | |
do | |
REDIS="redis-cli ${@:--h 127.0.0.1 -p 6379}" | |
redis_script=$($REDIS SCRIPT LOAD "local src = KEYS[1]; local dst = KEYS[2]; local count = 0; local msg = redis.call('lpop', src); while msg do count = count + 1; redis.call('rpush', dst, msg); msg = redis.call('lpop', src); end; return count") | |
echo $redis_script | |
while true | |
do | |
RST=$($REDIS EVALSHA $redis_script 2 src:queue dest:queue) | |
echo $(date +'[%Y%m%d %H:%M:%S]') $RST | |
if echo "$RST" | grep -q "NOSCRIPT"; then | |
break | |
fi | |
sleep 1 | |
done | |
sleep 20 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment