Get the App
SLTechnology News&Howtos  ›  Database  › 

Redis installation, syntax and Python connection

Shulou Source: shulou.com Published: 2022-06-01 04:08:14 10月22日 Update

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

Tags: Order member element index parameter interval position score multiple character data string online byte time binary user storage middle finger intersection Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Technology macOS vpn Huawei