Basic Redis Types and Commands

2024 年 6 月 2 日 星期日(已编辑)
/
28

Basic Redis Types and Commands

Still writing

This article shows some basic Redis data types and their commands using in this site.

Data types

Redis sets

Introduction to Redis sets

A Redis set is an unordered collection of unique strings (members). You can use Redis sets to efficiently:

  • Track unique items (e.g., track all unique IP addresses accessing a given blog post).
  • Represent relations (e.g., the set of all users with a given role).
  • Perform common set operations such as intersection, unions, and differences.

Basic commands

CommandDescription
SADDadds a new member to a set.
SREMremoves the specified member from the set.
SISMEMBERtests a string for set membership.
SINTERreturns the set of members that two or more sets have in common (i.e., the intersection).
SCARDreturns the size (a.k.a. cardinality) of a set.
SMEMBERSreturns all the members of the set value stored at key.

See the complete list of set commands.

Used for

Sets type is used for storing the collections of unique ip strings who liked this site today.

Deploy and Run Redis in Docker

Please refer to this article, How to Deploy and Run Redis in a Docker Container

In particular, it shows how to use Redis-Client in docker: Step 3: Connect to your database

The following uses the first three alphanumeric characters of your Container ID and opens up sh shell of the Redis Docker container:

$ docker exec -it 885 sh
> redis-cli
Excalidraw Loading...
  • Loading...
  • Loading...
  • Loading...
  • Loading...
  • Loading...