Skip to main content
ubuntuask.com

Back to all posts

How to Use ETS (Erlang Term Storage) For Data Storage?

Published on
4 min read
How to Use ETS (Erlang Term Storage) For Data Storage? image

Best Tools to Use ETS for Data Storage to Buy in January 2026

1 EasyTime Watch Repair Tool Kit for Watch Link Removal and Battery Replacement, 149 PCS Watch Back Remover for DIY Beginners Professional Collectors with Case and Instructions

EasyTime Watch Repair Tool Kit for Watch Link Removal and Battery Replacement, 149 PCS Watch Back Remover for DIY Beginners Professional Collectors with Case and Instructions

  • EASY REPAIRS: COMPLETE KIT MAKES WATCH FIXES SIMPLE FOR BEGINNERS.

  • DURABLE TOOLS: ANTI-CORROSION AND STAINLESS STEEL FOR LASTING USE.

  • PERFECT GIFT: NEATLY ORGANIZED KIT IDEAL FOR WATCH LOVERS ON THE GO.

BUY & SAVE
$16.99
EasyTime Watch Repair Tool Kit for Watch Link Removal and Battery Replacement, 149 PCS Watch Back Remover for DIY Beginners Professional Collectors with Case and Instructions
2 TOPDON Upgraded AD600S OBD2 Scanner, Diagnostic Tool, ABS SRS Transmission Engine Code Reader, 9 Reset Services Scan Tool, Oil/Brake/BMS/SAS/DPF/TPMS/ETS Reset, Injector Coding, Lifetime Free Update

TOPDON Upgraded AD600S OBD2 Scanner, Diagnostic Tool, ABS SRS Transmission Engine Code Reader, 9 Reset Services Scan Tool, Oil/Brake/BMS/SAS/DPF/TPMS/ETS Reset, Injector Coding, Lifetime Free Update

  • ENHANCED HD DISPLAY: CLEAR 5 SCREEN FOR EFFORTLESS DIAGNOSTICS.
  • 9 RESET FUNCTIONS: SAVE TIME AND MONEY ON ROUTINE MAINTENANCE RESETS.
  • 10K+ MODELS SUPPORTED: BROAD COMPATIBILITY WITH VEHICLES WORLDWIDE.
BUY & SAVE
$215.99
TOPDON Upgraded AD600S OBD2 Scanner, Diagnostic Tool, ABS SRS Transmission Engine Code Reader, 9 Reset Services Scan Tool, Oil/Brake/BMS/SAS/DPF/TPMS/ETS Reset, Injector Coding, Lifetime Free Update
3 OBD2 Scanner TOPDON AD600S Scan Tool, Code Reader, Diagnostics Scanner for ABS/SRS/AT/Engine, 9 Reset Services, Oil/Brake/BMS/SAS/DPF/TPMS/ETS Reset/ABS Bleeding/Injector Coding, Free Lifetime Upgrade

OBD2 Scanner TOPDON AD600S Scan Tool, Code Reader, Diagnostics Scanner for ABS/SRS/AT/Engine, 9 Reset Services, Oil/Brake/BMS/SAS/DPF/TPMS/ETS Reset/ABS Bleeding/Injector Coding, Free Lifetime Upgrade

  • ADVANCED RESET FUNCTIONS: INCLUDES 11 RESETS, SURPASSING AD600 & AD500.
  • LIFETIME FREE UPDATES: ENJOY ONE-CLICK UPDATES FOR CONTINUOUS SOFTWARE SUPPORT.
  • BROAD VEHICLE COMPATIBILITY: WORKS WITH 90+ BRANDS, FROM 1996 OBDII VEHICLES.
BUY & SAVE
$209.99
OBD2 Scanner TOPDON AD600S Scan Tool, Code Reader, Diagnostics Scanner for ABS/SRS/AT/Engine, 9 Reset Services, Oil/Brake/BMS/SAS/DPF/TPMS/ETS Reset/ABS Bleeding/Injector Coding, Free Lifetime Upgrade
4 EasyTime Watch Link Removal Kit: Professional Watch Strap Adjustment Tool Band Replacement Bracelet Resize Kit for All Size with 108 PCS Spring Bars 20 PCS Link Pins

EasyTime Watch Link Removal Kit: Professional Watch Strap Adjustment Tool Band Replacement Bracelet Resize Kit for All Size with 108 PCS Spring Bars 20 PCS Link Pins

  • COMPREHENSIVE KIT: ALL-IN-ONE TOOLS FOR QUICK WATCH BAND REPAIRS.
  • EASY STRAP CHANGES: QUICKLY REPLACE VARIOUS STRAPS WITH EASE.
  • USER-FRIENDLY GUIDES: LEARN FAST WITH VIDEO AND ILLUSTRATED INSTRUCTIONS.
BUY & SAVE
$7.99
EasyTime Watch Link Removal Kit: Professional Watch Strap Adjustment Tool Band Replacement Bracelet Resize Kit for All Size with 108 PCS Spring Bars 20 PCS Link Pins
5 ANCEL DS100 OBD2 Scanner - ABS, SRS, Transmission & Check Engine Code Reader with 7 Reset, Oil/Brake/BMS/SAS/ETS Reset, ABS Bleeding, Gear Learning, Lifetime Free Update, Online Customer Service

ANCEL DS100 OBD2 Scanner - ABS, SRS, Transmission & Check Engine Code Reader with 7 Reset, Oil/Brake/BMS/SAS/ETS Reset, ABS Bleeding, Gear Learning, Lifetime Free Update, Online Customer Service

  • ENHANCED FUNCTIONS FOR DIY REPAIRS - ACCESS ESSENTIAL MAINTENANCE FEATURES.

  • DEEPER DIAGNOSTICS & REAL-TIME DATA - IDENTIFY ISSUES, AVOID UNNECESSARY REPAIRS.

  • ONE-CLICK REPORTS FOR CLEAR COMMUNICATION - GENERATE AND SHARE PROFESSIONAL PDF REPORTS EASILY.

BUY & SAVE
$199.99
ANCEL DS100 OBD2 Scanner - ABS, SRS, Transmission & Check Engine Code Reader with 7 Reset, Oil/Brake/BMS/SAS/ETS Reset, ABS Bleeding, Gear Learning, Lifetime Free Update, Online Customer Service
6 Mesee 5 Pieces Weller ET Soldering Tip Set ETS Solder Iron Tips Replacement Lead-Free Welding Head Tool Accessory for Weller WE1010NA WES51 WES50 PES51 PES50 WEP70 EC1002 EC1201A

Mesee 5 Pieces Weller ET Soldering Tip Set ETS Solder Iron Tips Replacement Lead-Free Welding Head Tool Accessory for Weller WE1010NA WES51 WES50 PES51 PES50 WEP70 EC1002 EC1201A

  • PRECISION MICRO SOLDERING: LONG CONICAL TIPS FOR TIGHT SPACES!
  • HIGH-QUALITY DURABILITY: MULTI-LAYER PLATING FOR MAXIMUM HEAT TRANSFER!
  • VERSATILE COMPATIBILITY: FITS VARIOUS WELLER SOLDERING TOOLS SEAMLESSLY!
BUY & SAVE
$11.79
Mesee 5 Pieces Weller ET Soldering Tip Set ETS Solder Iron Tips Replacement Lead-Free Welding Head Tool Accessory for Weller WE1010NA WES51 WES50 PES51 PES50 WEP70 EC1002 EC1201A
+
ONE MORE?

ETS (Erlang Term Storage) is a mechanism in the Erlang programming language that allows for efficient storage and retrieval of data. It is primarily used for in-memory storage within an Erlang application.

To use ETS for data storage, you first need to create a table using the ets:new/2 function. This function takes two arguments: a table name (an atom) and a set of options (a list of key-value pairs). The options define the type of table and its characteristics, such as whether it is ordered or unordered, protected or private.

Once the table is created, you can insert data into it using the ets:insert/2 or ets:insert_new/2 functions. The former overwrites any existing data with the same key, while the latter only inserts if the key does not already exist. You can use any Erlang term as the key and value pair.

To retrieve data from the table, you can use the ets:lookup/2 function, specifying the table name and the key. It returns a list of matching values or an empty list if there are no matches.

In addition to single-key retrieval, ETS supports more advanced operations such as matching patterns using ets:match/2, iterating over all elements using ets:tab2list/1, and performing aggregations with ets:foldl/3 or ets:foldr/3.

If you need to update or delete data in the table, you can use the ets:update_element/3 or ets:delete/2 functions, respectively. These functions modify the data in place within the table.

Finally, when you are done with a table, you can delete it using the ets:delete/1 function, providing the table name as an argument.

It is important to note that ETS tables are not persisted between different Erlang nodes or system restarts. If you need persistent storage, you would need to implement additional logic to handle that.

ETS provides a fast and efficient way of storing and accessing data in Erlang applications, making it a valuable tool for various use cases such as caching, storing transient data, or maintaining shared state in concurrent systems.

How to retrieve data from an ETS table?

To retrieve data from an ETS (Erlang Term Storage) table in Erlang/OTP, you can use the ets:tab2list/1 function to convert the table into a list of tuples or the ets:tab2list/2 function to convert the table into a list of terms.

Here is an example of how to retrieve data from an ETS table:

  1. Create an ETS table and insert some data into it:

% Create an ordered set table Table = ets:new(my_table, [ordered_set, named_table]).

% Insert data into the table ets:insert(Table, {1, "Alice"}). ets:insert(Table, {2, "Bob"}). ets:insert(Table, {3, "Charlie"}).

  1. Retrieve the data from the ETS table:

% Retrieve the data as a list of tuples DataList = ets:tab2list(Table).

% Print the data io:format("~p~n", [DataList]).

The output will be:

[{1,"Alice"},{2,"Bob"},{3,"Charlie"}]

You can also use ets:tab2list/2 if you want to retrieve only specific fields from the table:

% Retrieve only the names from the table as a list NameList = ets:tab2list(Table, 2).

% Print the names io:format("~p~n", [NameList]).

The output will be:

["Alice","Bob","Charlie"]

Note: Remember to delete the table when you no longer need it using the ets:delete/1 function:

ets:delete(Table).

This will free the memory occupied by the table.

What is the purpose of a bag table in ETS?

In the context of ETS (Educational Testing Service), a bag table is used to conduct the test security procedures during an examination. The purpose of a bag table is to provide a designated area for test takers to securely store their personal belongings, such as bags, backpacks, coats, electronic devices, etc., during the exam. By requiring test takers to place their belongings on a bag table, it helps ensure that they do not take any prohibited items into the testing room that could potentially compromise the integrity and fairness of the test.

How to enable or disable automatic garbage collection in ETS?

By default, Erlang Term Storage (ETS) performs automatic garbage collection. However, you can enable or disable it using the setopts/2 function.

To enable automatic garbage collection in ETS:

ets:setopts(Table, {auto_garbage_collection, true})

To disable automatic garbage collection in ETS:

ets:setopts(Table, {auto_garbage_collection, false})

Here, Table is the identifier of the ETS table you want to modify. By setting the {auto_garbage_collection, true} option, ETS will automatically reclaim memory occupied by removed items. Conversely, setting the {auto_garbage_collection, false} option will disable automatic garbage collection.

Remember to choose the appropriate option based on your specific use case and the impact it may have on memory usage and performance.