{"id":14386,"date":"2023-02-17T07:25:53","date_gmt":"2023-02-17T07:25:53","guid":{"rendered":"http:\/\/www.withdata.com\/blog\/?p=14386"},"modified":"2023-10-14T04:11:25","modified_gmt":"2023-10-14T04:11:25","slug":"store-object-in-redis","status":"publish","type":"post","link":"https:\/\/www.withdata.com\/blog\/redisdatastudio\/store-object-in-redis.html","title":{"rendered":"Store Object in Redis"},"content":{"rendered":"<p>There are many ways to store an array of Objects in Redis.<\/p>\n<p>For example, you have this data:<\/p>\n<pre>id,name,age\r\n1,Fred,25\r\n2,Tom,28\r\n<\/pre>\n<p>1. Store the entire object as JSON-encoded string in a single key.<\/p>\n<pre>SET user:1 '{\"name\":\"Fred\",\"age\":25}'\r\nSET user:2 '{\"name\":\"Tom\",\"age\":28}'\r\n<\/pre>\n<p>2. Store each Object&#8217;s properties in a Redis hash.<\/p>\n<pre>HMSET user:1 name \"Fred\" age 25\r\nHMSET user:2 name \"Tom\" age 28\r\n<\/pre>\n<p>3. Store each Object as a JSON string in a Redis hash.<\/p>\n<pre>HMSET users 1 '{\"name\":\"Fred\",\"age\":25}'\r\nHMSET users 2 '{\"name\":\"Tom\",\"age\":28}'\r\n<\/pre>\n<p>4. Store each property of each Object in a dedicated key.<\/p>\n<pre>SET user:1:name \"Fred\"\r\nSET user:1:age 25\r\nSET user:2:name \"Tom\"\r\nSET user:2:age 28\r\n<\/pre>\n<p>You can use <a href=\"https:\/\/www.withdata.com\/redis-data-studio\/\">RedisDataStudio<\/a> to import object data from files to Redis key.<\/p>\n<p>For 1. Store the entire object as JSON-encoded string in a single key, you can see:<\/p>\n<p><a href=\"http:\/\/www.withdata.com\/blog\/redisdatastudio\/import-data-from-csv-file-to-redis-string-keys-in-same-namespace-without-programming.html\">Import data from CSV file to Redis string keys in same namespace<\/a> &nbsp;&nbsp;&nbsp; <a href=\"https:\/\/youtu.be\/RlPd4SZZPNI\" target=\"_blank\">Video<\/a><\/p>\n<p><a href=\"http:\/\/www.withdata.com\/blog\/redisdatastudio\/import-data-from-excel-file-to-redis-string-keys-in-same-namespace-without-programming.html\">Import data from Excel file to Redis string keys in same namespace<\/a> &nbsp;&nbsp;&nbsp; <a href=\"https:\/\/youtu.be\/9QYeZC_G9b4\" target=\"_blank\">Video<\/a><\/p>\n<p><a href=\"http:\/\/www.withdata.com\/blog\/redisdatastudio\/import-data-from-json-file-to-redis-string-keys-in-same-namespace-without-programming.html\">Import data from JSON file to Redis string keys in same namespace<\/a> &nbsp;&nbsp;&nbsp; <a href=\"https:\/\/youtu.be\/5uEqYq1rcQ4\" target=\"_blank\">Video<\/a><\/p>\n<p><a href=\"http:\/\/www.withdata.com\/blog\/redisdatastudio\/batch-import-data-from-csv-files-to-redis-string-keys-in-same-namespace-without-programming.html\">Batch import data from CSV files to Redis string keys in same namespace<\/a> &nbsp;&nbsp;&nbsp; <a href=\"https:\/\/youtu.be\/h-38uraxuz0\" target=\"_blank\">Video<\/a><\/p>\n<p><a href=\"http:\/\/www.withdata.com\/blog\/redisdatastudio\/batch-import-data-from-excel-files-to-redis-string-keys-in-same-namespace-without-programming.html\">Batch import data from Excel files to Redis string keys in same namespace<\/a> &nbsp;&nbsp;&nbsp; <a href=\"https:\/\/youtu.be\/p1dzN8VpOU8\" target=\"_blank\">Video<\/a><\/p>\n<p><a href=\"http:\/\/www.withdata.com\/blog\/redisdatastudio\/batch-import-data-from-json-files-to-redis-string-keys-in-same-namespace-without-programming.html\">Batch import data from JSON files to Redis string keys in same namespace<\/a> &nbsp;&nbsp;&nbsp; <a href=\"https:\/\/youtu.be\/IYnim9yybro\" target=\"_blank\">Video<\/a><\/p>\n<p>For 2. Store each Object&#8217;s properties in a Redis hash, you can see:<\/p>\n<p><a href=\"http:\/\/www.withdata.com\/blog\/redisdatastudio\/import-data-from-csv-file-to-redis-hash-keys-in-same-namespace-without-programming.html\">Import data from CSV file to Redis hash keys in same namespace<\/a> &nbsp;&nbsp;&nbsp; <a href=\"https:\/\/youtu.be\/_XzUzfLug9Q\" target=\"_blank\">Video<\/a><\/p>\n<p><a href=\"http:\/\/www.withdata.com\/blog\/redisdatastudio\/import-data-from-excel-file-to-redis-hash-keys-in-same-namespace-without-programming.html\">Import data from Excel file to Redis hash keys in same namespace<\/a> &nbsp;&nbsp;&nbsp; <a href=\"https:\/\/youtu.be\/d7NeWR93iY4\" target=\"_blank\">Video<\/a><\/p>\n<p><a href=\"http:\/\/www.withdata.com\/blog\/redisdatastudio\/import-data-from-json-file-to-redis-hash-keys-in-same-namespace-without-programming.html\">Import data from JSON file to Redis hash keys in same namespace<\/a> &nbsp;&nbsp;&nbsp; <a href=\"https:\/\/youtu.be\/kiRWShiMqLE\" target=\"_blank\">Video<\/a><\/p>\n<p><a href=\"http:\/\/www.withdata.com\/blog\/redisdatastudio\/batch-import-data-from-csv-files-to-redis-hash-keys-in-same-namespace-without-programming.html\">Batch import data from CSV files to Redis hash keys in same namespace<\/a> &nbsp;&nbsp;&nbsp; <a href=\"https:\/\/youtu.be\/iux0izGkouU\" target=\"_blank\">Video<\/a><\/p>\n<p><a href=\"http:\/\/www.withdata.com\/blog\/redisdatastudio\/batch-import-data-from-excel-files-to-redis-hash-keys-in-same-namespace-without-programming.html\">Batch import data from Excel files to Redis hash keys in same namespace<\/a> &nbsp;&nbsp;&nbsp; <a href=\"https:\/\/youtu.be\/sJu7Zth-Wus\" target=\"_blank\">Video<\/a><\/p>\n<p><a href=\"http:\/\/www.withdata.com\/blog\/redisdatastudio\/batch-import-data-from-json-files-to-redis-hash-keys-in-same-namespace-without-programming.html\">Batch import data from JSON files to Redis hash keys in same namespace<\/a> &nbsp;&nbsp;&nbsp; <a href=\"https:\/\/youtu.be\/IYnim9yybro\" target=\"_blank\">Video<\/a><\/p>\n<p>For 3. Store each Object as a JSON string in a Redis hash, you can see:<\/p>\n<p><a href=\"http:\/\/www.withdata.com\/blog\/redisdatastudio\/import-data-from-csv-file-to-redis-hash-key-without-programming.html\">Import data from CSV file to Redis hash key<\/a> &nbsp;&nbsp;&nbsp; <a href=\"https:\/\/youtu.be\/eOLR9ANHzq0\" target=\"_blank\">Video<\/a><\/p>\n<p><a href=\"http:\/\/www.withdata.com\/blog\/redisdatastudio\/import-data-from-excel-file-to-redis-hash-key-without-programming.html\">Import data from Excel file to Redis hash key<\/a> &nbsp;&nbsp;&nbsp; <a href=\"https:\/\/youtu.be\/gW1N_DEkjBo\" target=\"_blank\">Video<\/a><\/p>\n<p><a href=\"http:\/\/www.withdata.com\/blog\/redisdatastudio\/import-data-from-json-file-to-redis-hash-key-without-programming.html\">Import data from JSON file to Redis hash key<\/a> &nbsp;&nbsp;&nbsp; <a href=\"https:\/\/youtu.be\/el4KyI4H9hA\" target=\"_blank\">Video<\/a><\/p>\n<p><a href=\"http:\/\/www.withdata.com\/blog\/redisdatastudio\/batch-import-data-from-csv-files-to-redis-1-hash-key-without-programming.html\">Batch import data from CSV files to Redis 1 hash key<\/a> &nbsp;&nbsp;&nbsp; <a href=\"https:\/\/youtu.be\/NltN7ToBtvI\" target=\"_blank\">Video<\/a><\/p>\n<p><a href=\"http:\/\/www.withdata.com\/blog\/redisdatastudio\/batch-import-data-from-excel-files-to-redis-1-hash-key-without-programming.html\">Batch import data from Excel files to Redis 1 hash key<\/a> &nbsp;&nbsp;&nbsp; <a href=\"https:\/\/youtu.be\/Xnt1TrSV2MA\" target=\"_blank\">Video<\/a><\/p>\n<p><a href=\"http:\/\/www.withdata.com\/blog\/redisdatastudio\/batch-import-data-from-json-files-to-redis-1-hash-key-without-programming.html\">Batch import data from JSON files to Redis 1 hash key<\/a> &nbsp;&nbsp;&nbsp; <a href=\"https:\/\/youtu.be\/hIPFscfSptY\" target=\"_blank\">Video<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are many ways to store an array of Objects in Redis. For example, you have this data: id,name,age 1,Fred,25 2,Tom,28 1. Store the entire object as JSON-encoded string in a single key. SET user:1 &#8216;{&#8220;name&#8221;:&#8221;Fred&#8221;,&#8221;age&#8221;:25}&#8217; SET user:2 &#8216;{&#8220;name&#8221;:&#8221;Tom&#8221;,&#8221;age&#8221;:28}&#8217; 2. Store each Object&#8217;s properties in a Redis hash. HMSET user:1 name &#8220;Fred&#8221; age 25 HMSET [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3136],"tags":[3134,3139],"class_list":["post-14386","post","type-post","status-publish","format-standard","hentry","category-redisdatastudio","tag-redis","tag-redis-import"],"_links":{"self":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/14386","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/comments?post=14386"}],"version-history":[{"count":3,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/14386\/revisions"}],"predecessor-version":[{"id":14843,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/14386\/revisions\/14843"}],"wp:attachment":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/media?parent=14386"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/categories?post=14386"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/tags?post=14386"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}