Created
May 9, 2018 18:10
-
-
Save khalib/b755aab2bade38a9551c48ba840f2f7f to your computer and use it in GitHub Desktop.
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
| 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() | |
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
| 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() | |
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
| 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() | |
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
| 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