-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
2 additions
and
70 deletions.
There are no files selected for viewing
This file contains 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
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,7 @@ | ||
import redis | ||
|
||
class Monitor: | ||
def __init__(self, connection_pool): | ||
self.connection_pool = connection_pool | ||
self.connection = None | ||
|
||
def __del__(self): | ||
try: | ||
self.reset() | ||
except: | ||
pass | ||
|
||
def reset(self): | ||
if self.connection: | ||
self.connection_pool.release(self.connection) | ||
self.connection = None | ||
|
||
def monitor(self): | ||
if self.connection is None: | ||
self.connection = self.connection_pool.get_connection( | ||
'monitor', None) | ||
self.connection.send_command("monitor") | ||
return self.listen() | ||
|
||
def parse_response(self): | ||
msg = self.connection.read_response() | ||
return | ||
|
||
def listen(self): | ||
while True: | ||
yield self.parse_response() | ||
|
||
|
||
|
||
|
||
|
||
class Monitor: | ||
def __init__(self, r): | ||
self.r = r | ||
|
||
def run(self): | ||
STATE = "waiting" | ||
with r.monitor() as m: | ||
for command in m.listen(): | ||
if STATE == "waiting": | ||
pass | ||
if STATE == "waiting": | ||
pass | ||
|
||
import redis | ||
|
||
if __name__ == '__main__': | ||
pool = redis.ConnectionPool(host='localhost', port=6379, db=0) | ||
# monitor = Monitor(pool) | ||
# commands = monitor.monitor() | ||
|
||
# for c in commands: | ||
# print(c) | ||
|
||
r = redis.Redis(host='localhost', port=6379, db=0) | ||
with r.monitor() as m: | ||
for command in m.listen(): | ||
print({k: v[:50] if isinstance(v, (str, bytes)) else v for k, v in command.items()}) | ||
print({k: v[:50] if isinstance(v, (str, bytes)) else v for k, v in command.items()}) |