python redis
import redis
# Read from standalone REDIS
rd = redis.Redis(host='localhost',
port=6379,
db=0)
# write a key
rd.set("Key1", "hello")
# read a key
rd.get("Key1")
python redis
import redis
# Read from standalone REDIS
rd = redis.Redis(host='localhost',
port=6379,
db=0)
# write a key
rd.set("Key1", "hello")
# read a key
rd.get("Key1")
python redis
from redis.sentinel import Sentinel
# This way you can connect to a REDIS cluster via its sentinels
sentinel = Sentinel([('SENTINEL-1', 26379),
('SENTINEL-2', 26379),
('SENTINEL-3', 26379)],
socket_timeout=1, password="password", decode_responses=True)
# Get the current main
main = sentinel.master_for('main_key', socket_timeout=1)
# Get the current subordinates
subordinate = sentinel.slave_for('main_key', socket_timeout=1)
# Set some key on the main
# Writes work only on main
main.set("Py_key1", "hello")
# Read/Get the key from a Subordinate
test = subordinate.get("Py_key1")
print (test)
# Delete a key on the active (main)
main.delete("Py_key1")
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us