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.
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-cliTo 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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Coder Trainee
Experienced in Java and Python, we share and learn together. For submissions or collaborations, DM us.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
