Main commands

The following are the main commands listed with their usages:

  • SADD: It adds the element in a requested key. Also, the return of this command is the number of the element added to the set:
        SADD "unique-visitors" "joe"        SADD "unique-visitors" "mary"

As we can see, the command returned one because we added one user each time.

  • SMEMBERS: It returns all the members of a requested key:
       SMEMBERS "unique-visitors"

The command will return joe and mary because those are the values stored in the unique-visitors key.

  • SCARD: It returns the numbers of elements of a requested key:
        SCARD "unique-visitors"

The command will return the number of elements stored in the requested keys, in this case, the output will be 2.

Get Spring 5.0 By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.