Redis Subscription Publishing Features

Source: Internet
Author: User
Tags download redis redis server

Redis installation uses1. Download Redis:Http://redis.io/download2, decompression installation:    #tar zxfredis-3.0.6.tar.gz    #make                            
3. Start        #cd/usr/local/src/redis-3.0.6          #Src/redis-server &
4. Check
5. Login        #src/redis-cli               
6. Common Commands            set name ' YANGMV ' Save Data
           Get name                    Fetch Data
           
set name ' NB ' EX to save data, and sets the timeout time to 10 seconds
  lpush name_list ' Shanghai ' Beijing ' Save a list, reverse
         R push name_list ' Shanghai ' Beijing ' rpush list positive order             lrange name_list 0 2                                according to the subscript to take the value0-1 View All
          Save                                          save data to hard disk
             Keys *                                    View All data
  python operation Redis Installing the Python redis module
wget Https://pypi.python.org/packages/source/r/redis/redis-2.9.1.tar.gztar Zxfredis-2.9.1.tar.gzcdredis-2.9.1python Setup.pyinstall
 
access List Connection pool:Redis-py uses connection pool to manage all connections to a Redis server, avoiding the overhead of each establishment and release of the connection. By default, each Redis instance maintains its own pool of connections. You can create a connection pool directly, and then as a parameter Redis, you can implement multiple Redis instances to share a single connection pool.


Redis Subscription Publishing Features

Server side:
Import Redisclass redishelper:    def __init__ (self):        self.__conn = Redis. Redis (host= ' 127.0.0.1 ')        self.chan_sub = ' fm87.7 '    def subscribe (self):        pub = Self.__conn.pubsub ()        Pub.subscribe (self.chan_sub)        pub.parse_response ()        return pubif __name__ = = ' __main__ ':    r = Redishelper ()    recv = R.subscribe ()            #订阅fm87.7 Channel while    True:                     #循环监听接收        print recv.parse_response ()     # Listen to the channel and receive messages from the client
Client side:
Import Redisclass redishelper:    def __init__ (self):        self.__conn = Redis. Redis (host= ' 127.0.0.1 ')        self.chan_pub = ' fm87.7 '    def Public (self,msg):   #发布内容到fm87. Channel 7        self.__ Conn.publish (Self.chan_pub, msg)        return trueif __name__ = = ' __main__ ':    t = redishelper ()    t.public (' Test ')        #test为发布的内容
Server subscribes to fm87.7 messages

  

after executing the Python client.py publish message, the server gets the subscribed message



Redis Subscription Publishing Features

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.