Function Description: Connect Redis through Python to query, determine the results and follow-up operations. The redis-2.10.5.tar.gz must be installed first.
The code is as follows:
#!/usr/local/bin/pythonimport REDISR = Redis. Strictredis (host= ' 192.168.1.100 ', port=8888, db=0) t = Int (r.get (' Test ')) if T > 100:print t # # # #这边可以配置查询到匹配的值后 The action to perform, such as sending a message else:print ' not Catch ' # # # #同上
Note: The connection section can be modified to
Redis does not require a password configuration
#rip = ' 192.168.1.100 '
#rp = ' 8888 '
#r = Redis. Strictredis (Host=rip, PORT=RP, db=0)
Redis requires a password configuration
#r = Redis. Strictredis (host= ' 192.168.1.100 ', port=8888, db=0, password= ' ***************** ')
There is also a way to query data in Redis, using os.popen () to invoke the REDIS-CLI command of Redis itself.
"Gadget" Python connection Redis query