How to Quickly Connect to Redis using Python
Step 1: Install Dependencies
To get started, you need to install the
redis library. Open your terminal or command prompt and run the following command:
pip3 install redis
Step 2: Run the Python Script
Once you have installed the necessary dependencies, you can proceed with running the Python script. Open your preferred Python development environment or a text editor and follow these steps:
import redis # Replace '126.96.36.199' with your Redis server IP address # Replace 'MY_PASSWORD' with your Redis server password r = redis.Redis(host='188.8.131.52', password='MY_PASSWORD') # Get the value of the key 'aaa' print(r.get('aaa')) # Set the value of the key 'aaa' to '1' print(r.set('aaa', '1')) # Get the value of the key 'aaa' again to verify the successful connection print(r.get('aaa')) # Delete the key 'aaa' print(r.delete('aaa')) # Get the value of the key 'aaa' once more to confirm deletion print(r.get('aaa'))
Make sure to replace
'184.108.40.206' with the actual IP address of your Redis server, and
'MY_PASSWORD' with the appropriate password.
By following these simple steps, you can quickly connect to Redis using Python.