Skip to content

Instantly share code, notes, and snippets.

@khalib
Created May 9, 2018 18:10
Show Gist options
  • Select an option

  • Save khalib/b755aab2bade38a9551c48ba840f2f7f to your computer and use it in GitHub Desktop.

Select an option

Save khalib/b755aab2bade38a9551c48ba840f2f7f to your computer and use it in GitHub Desktop.
import sys
from redis import StrictRedis
def pub():
player_code = sys.argv[1]
r = StrictRedis(host='localhost', port=6379, db=0)
p = r.pubsub()
print('publishing - player_code:', player_code)
r.publish('player-update', player_code)
if __name__ == '__main__':
pub()
import time
from redis import StrictRedis
def sub():
r = StrictRedis(host='localhost', port=6379, db=0)
p = r.pubsub()
p.subscribe('player-update')
print('Subscriber 1 listening...')
while True:
message = p.get_message()
if message:
print('Subscriber 1 updating cache - player_code:',
message.get('data'))
time.sleep(0.001)
if __name__ == '__main__':
sub()
import time
from redis import StrictRedis
def sub():
r = StrictRedis(host='localhost', port=6379, db=0)
p = r.pubsub()
p.subscribe('player-update')
print('Subscriber 2 listening...')
while True:
message = p.get_message()
if message:
print('Subscriber 2 updating advance report - player_code:',
message.get('data'))
time.sleep(0.001)
if __name__ == '__main__':
sub()
import time
from redis import StrictRedis
def sub():
r = StrictRedis(host='localhost', port=6379, db=0)
p = r.pubsub()
p.subscribe('player-update')
print('Subscriber 3 listening...')
while True:
message = p.get_message()
if message:
print('Subscriber 3 updating video count - player_code:',
message)
time.sleep(0.001)
if __name__ == '__main__':
sub()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment