Day 2 Course Notes

In [2]:
from rediscluster import StrictRedisCluster
startup_nodes = [{"host": "127.0.0.1", "port": "7001"}]
messenger_cluster = StrictRedisCluster(startup_nodes=startup_nodes, decode_responses=True)
In [3]:
messenger_cluster.dbsize()
Out[3]:
{'127.0.0.1:7001': 0,
 '127.0.0.1:7002': 0,
 '127.0.0.1:7003': 0,
 '127.0.0.1:7004': 0,
 '127.0.0.1:7005': 0,
 '127.0.0.1:7006': 0}
In [4]:
person_consumer = messenger_cluster.pubsub()
person_consumer.subscribe("chat_room")
In [6]:
person_consumer.get_message()
Out[6]:
{'channel': 'chat_room',
 'data': 'with great message\n',
 'pattern': None,
 'type': 'message'}
In [7]:
person_consumer.subscribe("chat_room", "chat_breakroom")
In [8]:
import redis
cloud_redis = redis.StrictRedis(host='159.203.239.23')
cloud_redis.dbsize()
Out[8]:
0
In [9]:
slave_redis = redis.StrictRedis(host='159.203.239.23', port=6380)
In [10]:
slave_redis.dbsize()
Out[10]:
0
In [16]:
slave_redis.slaveof(host='159.203.239.23', port=6379)
Out[16]:
True
In [12]:
cloud_redis.set("master-key", "This is a master key")
Out[12]:
True
In [21]:
slave_redis.keys("*")
Out[21]:
[]
In [14]:
cloud_redis.keys("*")
Out[14]:
[b'master-key']
In [27]:
import redis
vm_redis = redis.StrictRedis()
lua_script = "return {KEYS[1], ARGV[1]}"
saved_sha1 = vm_redis.script_load(lua_script)
print(saved_sha1)
vm_redis.evalsha(saved_sha1, 1, "Happy", "Lucky")
d006f1a90249474274c76f5be725b8f5804a346b
Out[27]:
[b'Happy', b'Lucky']
In [ ]:
EVALSHA a42