Problem
You have learned to create and join a group using Tooz. In this coding challenge, you want to go one step further and implement a counter of members of a group. You have to increment a counter when a group joins and decrement the counter when it leaves. The counter is given using a global variable members
.
The code provided below can create groups and add members. However, you have to implement functionality to increment and decrement the members counter when members join or leave the group.
For simplicity, you can assume there is only one group and we can count its members.
To run the following example, click Run and then open another terminal. Use command
etcd
to run etcd. In the first terminal, use the commandpython tooz-test.py client1 group1
. This command will make a groupgroup1
with a memberclient1
. Open another terminal and cd using commandcd examples/group-membership/
, and join another client togroup1
using commandpython tooz-test.py client2 group1
.
Get hands-on with 1400+ tech skills courses.