Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Redis installation, syntax and Python connection

2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Download the program http://down.51cto.com/data/2440789:

Click the client to test the connection. The following figure shows that the test is successful.

Normal connection redis

Pipes: you can execute multiple commands at a time

Import redispool = redis.ConnectionPool (host='127.0.0.1',port=6379) # connection pool # r = redis.Redis (host='127.0.0.1',port=6379) r = redis.Redis (connection_pool=pool) pipe = r.pipeline (transaction=True) r.set ('foo','bar') r.set (' zhangsan','heheheh') pipe.execute ()

Implement subscription and publishing

Server side (publisher side):

Import redispool = redis.ConnectionPool (host= "127.0.0.1", port='6379') rc = redis.Redis (connection_pool=pool) while True: mes = str (input ("Please enter what you want to publish:") rc.publish ('fm100.5', mes)

Client (subscriber):

Import redispool = redis.ConnectionPool (host= "127.0.0.1", port='6379') rc = redis.Redis (connection_pool=pool) ps = rc.pubsub () # Open ps.subscribe (['fm100.5']) # FM for item in ps.listen (): # listening if item [' type'] = 'message': data = item [' data'] print (data.decode ('utf-8'))

Official account of Wechat

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report