"Gadget" Python connection Redis query

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.