Databases 4 min read

Understanding Redis Commands and Its Five Data Types

This article explains how to access the Redis CLI on Linux, connect to remote servers, and provides detailed examples of common commands for each of Redis's five data types—String, List, Set, Sorted Set, and Hash—highlighting key syntax and usage patterns.

Coder Trainee
Coder Trainee
Coder Trainee
Understanding Redis Commands and Its Five Data Types

Redis Commands

Redis commands are used to perform specific operations on a Redis server.

Example on Linux:

cd /tools/redis-7.0.5/bin
./redis-cli

To connect to a remote server: redis-cli -h host -p port -a password Replace host with the IP address, port with the port number, and password with the appropriate password.

Redis Five Data Types

String – The most common type for simple values. Common commands:

set key value – set the value of a key

get key – retrieve the value of a key

getrange key start end – get a substring of the value

setex key seconds value – set the value and its expiration time (seconds)

setnx key value – set the value only if the key does not already exist

List – An ordered collection of strings, sorted by insertion order.

Set – A collection of unique string members; duplicate elements are not allowed.

Sorted Set – Similar to a Set but each member is associated with a double‑precision score that determines the ordering from low to high.

Hash – A map of string fields to string values, ideal for representing objects. A single hash can store roughly 4 billion field‑value pairs. Common commands:

HDEL key field1 [field2] – delete one or more fields from the hash

HEXISTS key field – test whether a field exists in the hash

HGET key field – retrieve the value of a specific field

These are the commands we use most frequently; many other commands exist but are omitted here.

We will continue to use these five data types in future articles, such as detailed explanations of implementing likes and unlikes with Redis.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

RedisData TypesStringHashListCommandsSorted SetSet
Coder Trainee
Written by

Coder Trainee

Experienced in Java and Python, we share and learn together. For submissions or collaborations, DM us.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.