Unlike list, the order does not matter with set. It’s most useful when you want to maintain a unique set of data.
In the example below, you can add and remove data using SADD and SREM. Both commands are variadic, meaning they can accept multiple arguments to add and remove list members respectively. The set remains the same if you try to add an existing data or remove a non-existing data. SCARD command shows the total number of items in the set. SMEMBERS lists all items of a set.
➜ ~ docker exec -it redis redis-cli
127.0.0.1:6379> SADD visitors guest1
(integer) 1
127.0.0.1:6379> SADD visitors guest2 guest3 guest4 guest5
(integer) 4
127.0.0.1:6379> SCARD visitors
(integer) 5
127.0.0.1:6379> SMEMBERS visitors
1) "guest1"
2) "guest2"
3) "guest3"
4) "guest4"
5) "guest5"
127.0.0.1:6379> SADD visitors guest1
(integer) 0
127.0.0.1:6379> SREM visitors guest2 guest3
(integer) 2
127.0.0.1:6379> SMEMBERS visitors
1) "guest1"
2) "guest4"
3) "guest5"
127.0.0.1:6379> SREM visitors guest2
(integer) 0
127.0.0.1:6379> SADD visitors guest1
(integer) 0
127.0.0.1:6379> SMEMBERS visitors
1) "guest1"
2) "guest4"
3) "guest5"
127.0.0.1:6379>