Coding Challenge: Group Membership

Test your group membership in python skill by solving the coding challenge presented below.

We'll cover the following

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 command python tooz-test.py client1 group1. This command will make a group group1 with a member client1. Open another terminal and cd using command cd examples/group-membership/, and join another client to group1 using command python tooz-test.py client2 group1.

Get hands-on with 1400+ tech skills courses.