Compare Redis Arrays and Lists
Store ten items in Redis lists and arrays, then compare their commands.
Introduction
30 Second Summary
Two containers can hold the same items yet behave very differently when you try to add or retrieve them. Those differences become clear when you test each container yourself.
In this project, you will store the same ten items twice in a free Upstash Redis database. One copy uses a list. The other uses an Array.
What You'll Build
You'll run commands against both versions of your dataset and watch their differences appear directly in the console.
By the end of this project, you'll have:
- A live Redis database that answers your console commands.
- A side-by-side dataset that you can read as a list or an Array.
- A commands file that captures successful operations plus errors and surprising results.
- Secret Mission: An optional challenge to push your Redis data structure skills further.
Are there any prerequisites?
You'll need a free Upstash account. The web console handles every command in this project, so no local installation is required.
Before We Start
A Redis list and an Array can hold the same ten items. The operations that succeed or fail expose why these data types behave differently.
First, you need reliable browser access to the Upstash Console. You also need a local place to record each result.
In this step, get ready to:
- Open the Upstash Console in a separate browser tab.
- Sign in to an existing account or create a free account.
- Keep a local text editor ready for your future commands file.
Open the Upstash Console
The Upstash Console gives you a browser-based place to run commands later. This route avoids a local Redis installation.
- Press Cmd+T (macOS) or Ctrl+T (Windows) to open a new browser tab.
- Type https://console.upstash.com in the address bar.
- Press Enter.
You should see the Upstash account access screen. An active session may take you straight to the Redis area.
Prepare your Upstash account
Account access connects the database you create later to your workspace.
Signing in to a cloud service can feel like the moment charges begin. Upstash says free databases do not require a credit card.
✔️ I already have an Upstash account
Use the account method already connected to your Upstash workspace.
- Select Log in.
- Complete the authentication prompts for your existing account.
- Return to this project after the Redis area loads.
ⓧ I need to create an Upstash account
Upstash supports registration through Amazon, GitHub, Google, or email and password.
- Select Sign up for a free account.
- Choose your preferred registration method.
- Complete the account registration prompts.
- Return to this project after the Redis area loads.
- Stop before selecting + Create Database.
The Redis area should now be visible. No database or key exists yet.
Prepare a place for command notes
Some operations in this project succeed. Other operations reveal each data type's limits through errors or unexpected results.
Keeping those outputs in one plain-text file makes the final comparison easier. For now, you only need a blank document ready.
macOS
- Press Cmd+Space to open Spotlight.
- Type TextEdit.
- Press Enter to open TextEdit.
- Select New Document if the TextEdit dialog appears.
- Keep the blank document open for the command results you record later.
Windows
- Press the Windows key to open search.
- Type Notepad.
- Select Notepad from the search results.
- Keep the blank document open for the command results you record later.
Before the final check, picture the two windows you expect to have ready.
- Switch to your Upstash browser tab.
You should see the Redis area with no project database created.
- Switch to your local text editor.
You should see a blank document waiting for future command results.
Your Upstash access is ready. Next, you'll create the free Redis database.
Create and Test Your Redis Database
Before you compare lists with arrays, you need a database that accepts commands. Your free Upstash workspace gives you a hosted Redis database without a local installation.
In this step, you'll create an empty database for the comparison. You'll send it a health check to prove that it is ready.
In this step, get ready to:
- Sign in to the Upstash Console.
- Create a free database named redis-array-comparison.
- Prove the database connection with PING.
Sign in to the Upstash Console
The Upstash Console is where you create the database. It also includes a browser-based command area for testing it.
- Switch back to the browser from earlier.
- Visit the Upstash Console.
You'll see an account screen or your existing Upstash workspace.
- Complete the account flow shown by Upstash to reach the console.
You're in. Your Upstash workspace is now ready for its first database.
- Select the Redis tab.
You'll see the Redis database list with the + Create Database control in the upper-right corner.
Create the free database
A Redis database needs a name. Upstash also asks for the primary region that receives its writes.
- Click + Create Database in the upper-right corner.
You'll see a dialog with the database settings.
- Enter redis-array-comparison in the Database Name field.
- Select the Primary Region closest to your location.
- Click Next to reach the plan selection.
The plan screen can feel like a billing checkpoint. The Free plan costs $0/month.
- Select the Free plan.
- Complete the plan dialog using the confirmation control shown.
Good. You'll see the database page for redis-array-comparison with its plan shown as Free.
Run the connection check
The browser-based CLI sends Redis commands directly to your database. This gives you a quick connection test without installing anything locally.
The command area is easy to overlook because it sits inside the database page.
- Find the browser-based CLI on the database page from the last substep.
- Click the command input.
Before you send the check, do you expect the new database to answer immediately?
- Check the database connection by running this command:
PING
What does this command do?
- The PING command sends a health check to the Redis server.
- A PONG response proves that the connection is active.
- The command does not create a data key.
You'll see PONG beneath the command. That's your first successful Redis response from the database you'll use throughout the comparison.
Not seeing PONG?
- Confirm that redis-array-comparison is the database currently open in the console.
- Wait for the database page to finish loading.
- Retry PING with no extra text.
- Help me troubleshoot why my Upstash Redis database does not return PONG.
Your Redis database is live and answering commands. Next, you'll store ten items in a list and read them back in order.
Store the Dataset as a List
Your Upstash Redis database answered with PONG in the previous step. That response proves the database is ready for its first dataset.
In this step, you will push ten values into a Redis list. You will then read the full range to prove the original order survived.
In this step, get ready to:
- Create comparison:list with ten values.
- Read every list item with a range query.
- Confirm the values return in insertion order.
Push ten items into the list
A Redis list keeps values in insertion order. RPUSH adds each new value to the tail of that list.
- Create comparison:list in the database console from earlier by running this command:
RPUSH comparison:list item-01 item-02 item-03 item-04 item-05 item-06 item-07 item-08 item-09 item-10
What does this command do?
- RPUSH appends each supplied value to the tail of the list.
- Redis creates comparison:list as a list because the key does not exist yet.
- The values enter the list from left to right.
- The returned number reports the list length after the push.
- Confirm the console returns 10.
Good progress. Your first comparison key now holds all ten items.
Did the command return a different number?
- Check that you entered every value from item-01 through item-10.
- Confirm the key is spelled comparison:list.
- Remove comparison:list with the console if the returned number is greater than 10.
- Run the push command once after removing the repeated key.
- Help me check why my Redis list length is different from 10.
Read the list in order
LRANGE reads a section of a list using zero-based indexes. A stop index of -1 means the final item.
Before you run the range read, consider whether insertion order should put item-01 or item-10 first.
- Read the entire list by running this command:
LRANGE comparison:list 0 -1
How does the range work?
- LRANGE returns values from the requested section of the list.
- The start index 0 points to the first item.
- The stop index -1 points to the last item.
- Together, these indexes request every value in comparison:list.
- Count the values returned by the console.
- Compare their sequence with the values in your push command.
You should count 10 values.
The sequence should start with item-01. It should continue without gaps through item-10.
That is the baseline locked in. Your list returns all ten values in insertion order.
Missing values or seeing the wrong order?
- Check that both commands use the exact key comparison:list.
- Compare the returned sequence with the value order in the RPUSH command.
- Run the range command again after correcting the key name.
- Help me debug the values returned by LRANGE.
✔️ Awesome, I've got everything!
Great. Your comparison:list key now matches the target state.
ⓧ I'd like to double check the full code
Use this checklist to compare the stored list with the required result.
- Confirm the key name is comparison:list.
- Confirm the list contains item-01, item-02, item-03, item-04, item-05, item-06, item-07, item-08, item-09, and item-10 in that order.
- Confirm the range read returned the same ten values in the same order.
Your list baseline is ready. Next, you will store the same dataset a second way for a direct comparison.
Store the Dataset as an Array
Your list in Upstash Redis already holds all ten items in order. Now the comparison needs those values stored under a second data type.
A Redis Array gives every value a numeric address. You will place the ten items at indexes 0 through 9.
In this step, get ready to:
- Store the ten list values in comparison:array at indexes 0 through 9.
- Read the Array range to confirm every value kept its index.
Map the dataset to fixed indexes
The ARSET command writes one or more values into an Array from a chosen starting index. Each later value occupies the next index.
- Return to the console input in the database console from earlier.
- Write the complete mapping to comparison:array by running this command:
ARSET comparison:array 0 item-01 item-02 item-03 item-04 item-05 item-06 item-07 item-08 item-09 item-10
What does this command do?
- The ARSET command writes all ten values to comparison:array in one operation.
- The starting index 0 places item-01 in the first slot.
- Each following value occupies the next index until item-10 reaches index 9.
- The reply counts how many previously empty slots became occupied.
- Check the command result in the console.
You should see 10. The reply counts the ten newly occupied indexes.
Solid progress. Your Array now has one occupied slot at each index from 0 through 9.
Array Write Looks Wrong?
- Check that the key is named comparison:array.
- Confirm that the starting index is 0.
- Count the values from item-01 through item-10.
- Help me troubleshoot the Array write.
Read the complete Array range
The ARGETRANGE command returns every slot between an inclusive start index and end index. The reply preserves the indexes in range order.
Before you run the read, decide which values you expect at indexes 0 and 9.
- Read indexes 0 through 9 from comparison:array by running this command:
ARGETRANGE comparison:array 0 9
What does this command do?
- The ARGETRANGE command reads every Array slot from index 0 through index 9.
- Both range boundaries are included in the result.
- Each returned position corresponds to the same index in comparison:array.
- Check the returned values in the console.
You should see ten results in this exact order: item-01, item-02, item-03, item-04, item-05, item-06, item-07, item-08, item-09, item-10.
That's the match you needed. The Array contains the same dataset in the same order as the list.
Missing or Misordered Values?
- Check that the read targets comparison:array.
- Confirm that the range begins at 0.
- Confirm that the range ends at 9.
- Help me troubleshoot the Array range read.
✔️ Awesome, I've got everything!
Your Array and list now hold matching ten-item datasets.
ⓧ I'd like to double check the full code
- Compare your Array write and read commands with this reference:
ARSET comparison:array 0 item-01 item-02 item-03 item-04 item-05 item-06 item-07 item-08 item-09 item-10
ARGETRANGE comparison:array 0 9
How Do These Commands Match the Target State?
- The first line stores item-01 through item-10 at indexes 0 through 9 in comparison:array.
- The second line reads all ten Array slots in index order.
- Neither command targets comparison:list. Your existing list remains unchanged.
Your two datasets now match. Next, you will test each data type with an operation designed for the other.
Test the Type Boundaries
Your Redis list now holds ten items in order. Your Array holds the same ten items at matching indexes.
Native read commands make these structures look interchangeable. This step crosses their command boundaries so you can capture where that assumption falls short.
In this step, get ready to:
- Test a list-only operation against the Array.
- Test an Array-only operation against the list.
- Record both boundary results in commands.md.
Try a list command on the Array
The LRANGE command reads a sequence from a Redis list. Applying it to comparison:array tests whether matching values are enough to make the command compatible.
Before you run this, do you expect an error or returned values? Keep your prediction in mind.
- Test the Array with the list read command by running this in the database console:
LRANGE comparison:array 0 -1
What does this test do?
- The LRANGE command reads an inclusive range from a list.
- The 0 -1 range requests every stored list element.
- This command only reads data. It leaves comparison:array unchanged.
The console response is your first boundary result. It shows how a list command behaves when the key holds an Array.
- Keep the command response visible in the console history for your commands log.
No response from the console?
- Confirm the redis-array-comparison database console is still active.
- Copy the command from the code block again to remove any typing mistakes.
- Ask for help with the console response: Help me understand why my LRANGE boundary test is not producing a response.
Try an Array command on the list
The ARGETRANGE command reads Array slots by index. Applying it to comparison:list tests the boundary in the opposite direction.
Before you run this, do you expect the second mismatch to behave like the first one? Keep your prediction in mind.
- Test the list with the Array range command by running this in the database console:
ARGETRANGE comparison:list 0 9
What does this test do?
- The ARGETRANGE command reads every Array slot in an inclusive index range.
- The 0 9 range requests the ten indexes used by your dataset.
- This command only reads data. It leaves comparison:list unchanged.
The second console response completes the comparison. You now have direct evidence from both crossed operations.
- Keep this command response visible in the console history for your commands log.
Did the second test fail differently?
The two crossed commands do not need to produce identical responses. Capture the exact result shown by your console.
Ask for help if the response is unclear: Help me interpret my ARGETRANGE boundary test result.
Save the evidence and verify both keys
A boundary test becomes useful when its commands stay beside their results. The commands.md file preserves the successful path plus both mismatches.
- Return to the local notes location from earlier.
- Create a plain-text file named commands.md using the location's new-file control.
- Add the successful PING command with its returned result.
- Add the successful list write command with its returned result.
- Add the successful list read command with its returned values.
- Add the successful Array write command with its returned result.
- Add the successful Array read command with its returned values.
Good work. The first half of your log now preserves every successful command from the earlier steps.
- Add the first cross-type command exactly as shown in the console.
- Place its observed result directly below the command.
- Add the second cross-type command exactly as shown in the console.
- Place its observed result directly below the command.
- Save commands.md.
- Confirm the file exists by checking the local notes file list.
You should see commands.md in the local notes location.
Before you read both keys again, do you expect either dataset to have changed? Keep your prediction in mind.
- Verify the original list and Array contents by running these native read commands in the database console:
LRANGE comparison:list 0 -1
ARGETRANGE comparison:array 0 9
What does this verification prove?
- The first command reads every value from comparison:list with its native list operation.
- The second command reads indexes 0 through 9 from comparison:array with its native Array operation.
- Matching output confirms that both cross-type tests were read-only.
Both commands return item-01 through item-10 in order. That confirms the crossed reads left both original keys unchanged.
Do the values look different?
- Check that the list command targets comparison:list.
- Check that the Array command targets comparison:array.
- Ask for help comparing the results: Help me check why my Redis list and Array verification results differ.
✔️ My commands log is complete
Your commands.md file now captures every successful command plus both boundary results.
ⓧ I'd like to double check the full log
A complete commands.md contains these entries.
- The successful PING command with its returned result.
- The successful list write command with its returned result.
- The successful list read command with its returned values.
- The successful Array write command with its returned result.
- The successful Array read command with its returned values.
- The list-only command attempted against comparison:array with its observed result.
- The Array-only command attempted against comparison:list with its observed result.
Your commands log now captures the successful paths plus the type boundaries. Next up, you will turn that evidence into a short rule for choosing between a list and an Array.
Document When to Use Each Type
Your Upstash comparison now stores ten items as a Redis list. It also stores the same ten items as a Redis Array.
The cross-type tests exposed where each command model stops. A raw command log still leaves the final choice to its reader.
In this step, you turn your observations into a short decision rule. The evidence stays directly underneath it in commands.md.
In this step, get ready to:
- Write a recommendation for choosing a Redis list.
- Write a recommendation for choosing a Redis Array.
- Keep the recorded commands below the conclusion as supporting evidence.
Turn the observations into a decision rule
The key question is whether insertion order carries the meaning or numeric position carries the meaning. Your test results show how that distinction appears at the command level.
- Open commands.md in the text editor you used earlier.
- Move to the top of commands.md.
- Add a short conclusion section above the existing command log.
You should now see the new conclusion section above the untouched command evidence.
- Write one sentence recommending a Redis list when insertion order matters.
- Write one sentence recommending a Redis Array when each numeric position has meaning.
- Save commands.md.
Why This Decision Rule Works
A list treats each index as a position in insertion order. It fits queues or feeds where items enter through the ends.
An Array treats each numeric index as an address in the data model. It fits numbered slots or steps where a specific position must keep its meaning.
You should now be able to identify the suitable type without scanning every command in the file.
Tie the conclusion to the recorded evidence
A recommendation becomes useful when the reader can check the evidence behind it. Your successful operations show each type working on its own terms.
- Review the successful list commands in the existing log.
- Review the successful Array commands in the existing log.
- Review the two recorded cross-type results.
- Add one final sentence that points readers to the commands below as evidence.
- Keep every recorded command result unchanged.
- Save commands.md.
Before you check the finished file, do you expect a reader to reach the same recommendation using only the evidence underneath it?
- Read commands.md from top to bottom.
- Confirm the list recommendation appears before the command log.
- Confirm the Array recommendation appears before the command log.
- Confirm the successful database check remains in the command log.
- Confirm the successful list operations remain in the command log.
- Confirm the successful Array operations remain in the command log.
- Confirm both cross-type commands retain their observed results.
You should see a short recommendation first. The successful commands plus both cross-type tests should follow as supporting evidence.
Conclusion Still Feels Vague?
- Check that each recommendation names the data behavior that makes the type suitable.
- Use your recorded cross-type outcomes to show why the two command families cannot be swapped.
- Keep performance claims out of the conclusion because ten items cannot support them.
- Help me sharpen my Redis list versus Redis Array conclusion.
✔️ Awesome, I've got everything!
Great work. Your commands.md file now explains the choice before presenting the evidence.
ⓧ I'd like to double check the full code
Compare commands.md against this required order:
- A short conclusion recommends a Redis list when insertion order carries the meaning.
- The conclusion recommends a Redis Array when numeric positions carry the meaning.
- The successful database check follows the conclusion.
- The successful list write operation follows with its read operation.
- The successful Array write operation follows with its read operation.
- The list-only command tested against comparison:array remains with its observed result.
- The Array-only command tested against comparison:list remains with its observed result.
That completes the comparison. Your command log is now a reusable reference that connects each recommendation to evidence you observed yourself.
Secret mission
Make the Data Structure Call
Your comparison showed how two structures behave with the same ten values. Now use that evidence to recommend the right structure for three real design scenarios, then test how your recommendation changes when a requirement shifts.
Clean Up Your Resources
Clean Up Your Resources
Your free Upstash Redis database does not add ongoing project costs while it stays on the free plan. Decide whether to keep your resources available, set them aside for later, or delete them.
Resources you used:
- Cloud resource: The free Upstash Redis database redis-array-comparison. It contains the comparison:list Redis list. It also contains the comparison:array Redis Array.
- Local artifact: The commands.md file. It records your conclusion. It also preserves the commands plus their observed results.
Keep everything running
No action needed. Choose this if you want to rerun the comparison or inspect both data structures again.
- Leave redis-array-comparison in your Upstash account.
- Keep commands.md as your comparison reference.
- Use the database console later to rerun the recorded commands.
Pause - I'll come back to this later
No local process is running. Pausing only changes what stays open on your screen.
- Close the browser tab showing redis-array-comparison.
- Leave commands.md on your computer.
- Return to the Upstash console when you want to continue.
Delete - I don't want to use this again
Deleting redis-array-comparison permanently removes both stored versions of the dataset. Your evidence remains in commands.md until you remove that file too.
- Switch back to the redis-array-comparison database console from earlier.
- Open the database settings for redis-array-comparison.
- Use the database deletion control to delete redis-array-comparison.
- Approve the confirmation prompt.
- Return to your Upstash database list.
You should no longer see redis-array-comparison in the database list. This confirms that both Redis keys are gone.
- Use your computer's file search to locate commands.md.
- Delete commands.md from its saved location.
- Search for commands.md again.
The search should no longer show commands.md. That clears both project resources.
Nice Work!
Nice Work!
You did it! You built a working comparison of a Redis list and a Redis Array in an Upstash database.
Your results now live in commands.md. That file captures the successful commands plus the cross-type tests that exposed where each structure falls short.
You've learned how to:
- Create a free Upstash Redis database. You also confirmed that it responds to commands from the console.
- Store the same ten values in a Redis list plus a Redis Array. You then read both datasets back in index order.
- Run cross-type tests that reveal incompatible operations. You used the observed results to write a practical recommendation in commands.md.
- Take on an optional Secret Mission to push your comparison skills further.
Ready to quiz yourself?