The path of Python 49-redis

Source: Internet
Author: User

Operating mode

R = Redis. Redis (host= "192.168.80.20", port=6379) R.set ("name", "Jiachen") Print (R.get ("name"))


Connection pool

Pool = Redis. ConnectionPool (host= "192.168.80.20", port=6379) R = Redis. Redis (Connection_pool=pool) r.set ("name", "Jiachen") Print (R.get ("name"))


    1. String manipulation

    2. Hash operation

    3. List operation

    4. Set operation

    5. Other operations

Http://www.redis.cn/commands.html


Pipeline

Import Redisimport Timepool = Redis. ConnectionPool (host= ' 192.168.80.20 ', port=6379) R = Redis. Redis (connection_pool=pool) # pipe = R.pipeline (transaction=false) pipe = R.pipeline (transaction=true) pipe.set (' name ' , ' Wupeiqi ') time.sleep (() Pipe.set (' Role ', ' SB ') Pipe.execute ()


Subscribe/Publish

Import Redisclass redishelper:def __init__ (self): Self.__conn = Redis.        Redis (host= ' 10.211.55.4 ') self.chan_sub = ' fm104.5 ' self.chan_pub = ' fm104.5 ' def public (self, msg):        Self.__conn.publish (Self.chan_pub, msg) return True def subscribe (self): pub = Self.__conn.pubsub () Pub.subscribe (self.chan_sub) pub.parse_response () return pub

Subscription

From Monitor. Redishelper import Redishelper obj = Redishelper () redis_sub = Obj.subscribe () while true:msg= Redis_sub.parse_response () Print MSG

Release

From Monitor. Redishelper import Redishelper obj = Redishelper () obj.public (' Hello ')


This article is from the "Eight Miles" blog, so be sure to keep this source http://5921271.blog.51cto.com/5911271/1912399

The path of Python 49-redis

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.