Skip to content

Instantly share code, notes, and snippets.

@Lax
Last active August 27, 2015 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lax/23f45c070fceec590384 to your computer and use it in GitHub Desktop.
Save Lax/23f45c070fceec590384 to your computer and use it in GitHub Desktop.
transfer item from one redis queue to another
#!/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
#!/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