{"id":379,"date":"2026-05-16T09:00:00","date_gmt":"2026-05-16T03:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/go-redis-caching\/"},"modified":"2026-10-10T21:21:28","modified_gmt":"2026-10-10T15:51:28","slug":"go-redis-caching","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/go-redis-caching\/","title":{"rendered":"Go Redis Caching: Speed Up Your API"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Go Redis caching keeps copies of popular data in fast memory. So your API can answer in a millisecond instead of waiting on the database. In this post, you will learn what a cache is and how the cache-aside pattern works. Then we will add Redis to a Go book API with expiry times and safe invalidation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So far, every request in our book store went to PostgreSQL, as in <a href=\"https:\/\/smitabharat.com\/blog\/go-postgresql-pgx\/\">Go PostgreSQL with pgx<\/a>. That is fine for small traffic. However, popular pages ask for the same rows again and again. We also store cached values as JSON, which you learned in <a href=\"https:\/\/smitabharat.com\/blog\/go-json-encoding-decoding\/\">Go JSON encoding and decoding<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Is Go Redis Caching?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A cache is a small, fast store that keeps copies of data you read often. Redis is a popular in-memory data store that works well as that cache. So with Go Redis caching, your service checks Redis first. Then it asks the database only when Redis does not have the answer.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, think of a shop counter and a back store room. The shopkeeper keeps the best-selling items on the counter, so most customers get served in seconds. Only rare items need a trip to the back. Similarly, Redis is the counter, and PostgreSQL is the store room.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Redis keeps data in memory, so reads are extremely fast. Also, every key can have an expiry time, after which Redis deletes it automatically.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Go Redis Caching Matters<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A database is the slowest part of most web requests. Therefore, cutting even a few queries can make a big difference. Here is where Go Redis caching helps most.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Popular product or book pages<\/strong>: thousands of users read the same few records.<\/li>\n\n\n\n<li><strong>Expensive reports<\/strong>: a slow query runs once, and the result serves everyone for a few minutes.<\/li>\n\n\n\n<li><strong>Session data<\/strong>: login sessions live in Redis, so any app server can read them.<\/li>\n\n\n\n<li><strong>Rate limits and counters<\/strong>: Redis increments numbers safely across many servers.<\/li>\n\n\n\n<li><strong>Protecting the database<\/strong>: during a traffic spike, the cache absorbs most reads.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">In short, Go Redis caching makes your API faster and your database calmer.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How Go Redis Caching Works: Cache-Aside<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The most common pattern is called cache-aside, or lazy loading. First, the handler asks Redis for the key. If Redis has it, that is a cache hit, and we return it at once. Otherwise, it is a cache miss. Then we load the data from the database, save a copy in Redis with an expiry time and return it.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-redis-caching-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-redis-caching-diagram-1-1024x640.png\" alt=\"Go Redis Caching diagram showing the cache-aside flow with hits, misses, TTL and invalidation\" class=\"wp-image-364\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-redis-caching-diagram-1-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-redis-caching-diagram-1-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-redis-caching-diagram-1-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-redis-caching-diagram-1-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-redis-caching-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">On a cache hit the handler answers straight from Redis, and on a miss it reads PostgreSQL, stores a copy in Redis with a TTL and then answers.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">When data changes, the cache must not keep the old copy forever. So on every update, we delete the key. As a result, the next read misses, loads fresh data and caches it again.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Key Redis Commands for Caching<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Redis has many commands, but caching needs only a few. We ran each of them in <code>redis-cli<\/code> against Redis 7, and this table shows what they return.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Command<\/th><th>Example<\/th><th>Result<\/th><\/tr><\/thead><tbody><tr><td><code>SET<\/code> with <code>EX<\/code><\/td><td><code>SET book:1 '{...}' EX 300<\/code><\/td><td><code>OK<\/code>, key expires in 300 seconds<\/td><\/tr><tr><td><code>GET<\/code><\/td><td><code>GET book:1<\/code><\/td><td>The stored JSON, or nil if missing<\/td><\/tr><tr><td><code>TTL<\/code><\/td><td><code>TTL book:1<\/code><\/td><td>Seconds left, such as <code>300<\/code><\/td><\/tr><tr><td><code>DEL<\/code><\/td><td><code>DEL book:1<\/code><\/td><td><code>1<\/code> if a key was deleted<\/td><\/tr><tr><td><code>SET<\/code> with <code>NX<\/code><\/td><td><code>SET lock:report 1 NX EX 30<\/code><\/td><td><code>OK<\/code> only if the key did not exist<\/td><\/tr><tr><td><code>INCR<\/code><\/td><td><code>INCR views:book:1<\/code><\/td><td>The new count, such as <code>1<\/code>, then <code>2<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Keys and Naming<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Redis keys are plain strings. So pick a clear pattern such as <code>book:42<\/code> or <code>user:7:profile<\/code>. As a result, you can find and delete related keys easily.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">TTL: Time To Live<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">TTL is how long a key lives before Redis removes it. A short TTL means fresher data, while a long TTL means fewer database hits. For most API reads, 1 to 10 minutes is a good start.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Local Map Cache vs Go Redis Caching<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You could also cache data in a Go map inside your process. The table below compares the two choices.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>In-process Go map<\/th><th>Redis<\/th><\/tr><\/thead><tbody><tr><td>Speed<\/td><td>Fastest, no network<\/td><td>Very fast, one network hop<\/td><\/tr><tr><td>Shared across servers<\/td><td>No, each server has its own<\/td><td>Yes, one shared cache<\/td><\/tr><tr><td>Survives a restart<\/td><td>No<\/td><td>Yes, with persistence on<\/td><\/tr><tr><td>Built-in expiry<\/td><td>You write it yourself<\/td><td><code>EX<\/code> and <code>TTL<\/code> built in<\/td><\/tr><tr><td>Memory limit<\/td><td>Your app&#8217;s memory<\/td><td>A separate server you can size<\/td><\/tr><tr><td>Best for<\/td><td>Tiny, rarely changing data<\/td><td>Most web APIs<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-redis-caching-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-redis-caching-diagram-2-1024x640.png\" alt=\"Go Redis Caching diagram comparing per-server map caches with one shared Redis cache\" class=\"wp-image-365\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-redis-caching-diagram-2-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-redis-caching-diagram-2-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-redis-caching-diagram-2-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-redis-caching-diagram-2-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-redis-caching-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">An in-process map gives each server its own cache, while Redis gives every server one shared cache with built-in expiry.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So when should you use which? Use a local map only for small data that rarely changes, such as a country list. Otherwise, use Redis, because every server then sees the same cached values.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Hands-On: Add Go Redis Caching to a Book API<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s add Go Redis caching to the book lookup. We will use the official <code>go-redis<\/code> client.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Start Redis and Add the Client<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">First, run Redis with Docker, then add the Go package.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker run -d --name redis -p 6379:6379 redis:7\ngo get github.com\/redis\/go-redis\/v9<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Connect to Redis<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Next, create one client at startup and check the connection.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rdb := redis.NewClient(&amp;redis.Options{\n\tAddr: \"localhost:6379\",\n})\ndefer rdb.Close()\n\nctx := context.Background()\nif err := rdb.Ping(ctx).Err(); err != nil {\n\tlog.Fatalf(\"cannot reach redis: %v\", err)\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The client keeps its own connection pool. So, like the pgx pool, you create it once and share it across all handlers.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: The Cache-Aside Function<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This function does the full hit and miss logic for one book.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func getBook(ctx context.Context, rdb *redis.Client, db BookStore, id int64) (Book, error) {\n\tkey := fmt.Sprintf(\"book:%d\", id)\n\n\t\/\/ 1. Try the cache first.\n\tdata, err := rdb.Get(ctx, key).Bytes()\n\tif err == nil {\n\t\tvar b Book\n\t\tif json.Unmarshal(data, &amp;b) == nil {\n\t\t\tlog.Println(\"cache hit\", key)\n\t\t\treturn b, nil\n\t\t}\n\t} else if !errors.Is(err, redis.Nil) {\n\t\tlog.Println(\"redis error, using database:\", err)\n\t}\n\n\t\/\/ 2. Cache miss: load from the database.\n\tb, err := db.GetBook(ctx, id)\n\tif err != nil {\n\t\treturn Book{}, err\n\t}\n\n\t\/\/ 3. Save a copy for five minutes.\n\tif data, err := json.Marshal(b); err == nil {\n\t\tif err := rdb.Set(ctx, key, data, 5*time.Minute).Err(); err != nil {\n\t\t\tlog.Println(\"cache set failed:\", err)\n\t\t}\n\t}\n\tlog.Println(\"cache miss\", key)\n\treturn b, nil\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s walk through the important lines. First, <code>redis.Nil<\/code> is the special error for &#8220;key not found&#8221;, so it is a normal miss, not a failure. Next, if Redis itself is down, we log the problem and still serve from the database. Then <code>Set<\/code> with <code>5*time.Minute<\/code> stores the JSON with a TTL. Finally, a failed <code>Set<\/code> only logs a warning, because the user already has the right data.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4: Invalidate on Update<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">When a book changes, we update the database first and then delete the cached copy.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func updatePrice(ctx context.Context, rdb *redis.Client, db BookStore, id int64, price int) error {\n\tif err := db.UpdatePrice(ctx, id, price); err != nil {\n\t\treturn err\n\t}\n\treturn rdb.Del(ctx, fmt.Sprintf(\"book:%d\", id)).Err()\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Deleting is safer than writing the new value into the cache. Otherwise, two updates racing each other could leave an old price in Redis.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 5: See It Work<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To test our Go Redis caching code, call <code>getBook<\/code> twice for the same ID, update the price, and call it again. If the database lookup takes about 40 ms, the log looks roughly like this.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cache miss book:1    (about 40ms)\ncache hit book:1     (under 1ms)\nprice updated, key book:1 deleted\ncache miss book:1    (about 40ms)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The second read skips PostgreSQL completely. Meanwhile, the read after the update misses on purpose, so users never see the old price.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Avoiding a Cache Stampede<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Imagine a very popular book page whose key just expired. Suddenly, hundreds of requests miss at the same moment, and all of them hit PostgreSQL together. This is called a cache stampede, and it can overload the database in seconds.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One simple fix uses the <code>SET ... NX<\/code> command from the table above. Only the request that wins a short lock reloads the data. Meanwhile, the others wait briefly and then read the fresh cache.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ok, err := rdb.SetNX(ctx, \"lock:\"+key, 1, 10*time.Second).Result()\nif err == nil &amp;&amp; ok {\n\tdefer rdb.Del(ctx, \"lock:\"+key)\n\t\/\/ This request reloads from the database and fills the cache.\n} else {\n\ttime.Sleep(50 * time.Millisecond)\n\t\/\/ Then try reading the cache again.\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here, <code>SetNX<\/code> returns <code>true<\/code> only for the first caller. Also, the 10 second expiry frees the lock even if that request crashes. For most small apps, you will not need this. However, it is worth knowing once your Go Redis caching layer serves heavy traffic.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with Go Redis Caching<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>No TTL on keys<\/strong>: Redis fills up and serves stale data forever. So always set an expiry.<\/li>\n\n\n\n<li>**Treating <code>redis.Nil<\/code> as an error**: every miss then returns a 500. Check it with <code>errors.Is<\/code>.<\/li>\n\n\n\n<li><strong>Failing the request when Redis is down<\/strong>: the cache becomes a single point of failure. Fall back to the database instead.<\/li>\n\n\n\n<li><strong>Updating the cache instead of deleting it<\/strong>: racing writes can store old values. Delete the key on change.<\/li>\n\n\n\n<li><strong>Caching per-user secrets under shared keys<\/strong>: users may see each other&#8217;s data. Include the user ID in the key.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Go Redis Caching<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Cache data that is read often and changes rarely<\/strong>, because that gives the biggest win.<\/li>\n\n\n\n<li><strong>Use clear key names with prefixes<\/strong>, so you can debug and clean up easily.<\/li>\n\n\n\n<li><strong>Add a little random jitter to TTLs<\/strong>, as many keys expiring together can flood the database.<\/li>\n\n\n\n<li><strong>Set timeouts on the Redis client<\/strong>, since a slow cache should never slow the whole request.<\/li>\n\n\n\n<li><strong>Measure hit rate<\/strong>, because a cache with a low hit rate only adds work.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Cache the list of books by author under the key <code>books:author:Asha<\/code>. Then make sure <code>updatePrice<\/code> also deletes that list key, so the list never shows an old price.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Hint: decide carefully which keys each update can affect.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These pages cover the client and the Redis commands in detail.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/pkg.go.dev\/github.com\/redis\/go-redis\/v9\">go-redis v9 package documentation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/redis.io\/docs\/latest\/commands\/set\/\">Redis docs: SET command<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/redis.io\/docs\/latest\/commands\/expire\/\">Redis docs: EXPIRE and key expiry<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Go Redis caching stores copies of popular data in fast memory.<\/li>\n\n\n\n<li>Cache-aside checks Redis first and loads from the database on a miss.<\/li>\n\n\n\n<li><code>redis.Nil<\/code> means &#8220;not found&#8221;, so treat it as a normal miss.<\/li>\n\n\n\n<li>Always set a TTL, and delete keys when the data changes.<\/li>\n\n\n\n<li>Fall back to the database when Redis is slow or down.<\/li>\n\n\n\n<li>Use Redis instead of a local map when you run more than one server.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Our API is fast now, so it is time to protect it. Next, we will store user passwords safely with bcrypt before building login.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next lesson: <a href=\"https:\/\/smitabharat.com\/blog\/go-password-hashing-bcrypt\/\">Go Password Hashing with bcrypt Explained<\/a><\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>Go Redis caching keeps copies of popular data in fast memory. So your API can answer in a millisecond instead of waiting on the&hellip;<\/p>\n","protected":false},"author":1,"featured_media":363,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[15],"tags":[11,73,23,21],"swapz_series":[],"class_list":["post-379","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go-lang","tag-go-lang","tag-go-redis","tag-go-tutorial","tag-golang-basics"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Go Redis Caching: Make Your Go API Much Faster<\/title>\n<meta name=\"description\" content=\"Learn Go Redis caching step by step: the cache-aside pattern, TTLs, cache invalidation and safe fallbacks when Redis is slow or down.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/smitabharat.com\/blog\/go-redis-caching\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go Redis Caching: Make Your Go API Much Faster\" \/>\n<meta property=\"og:description\" content=\"Learn Go Redis caching step by step: the cache-aside pattern, TTLs, cache invalidation and safe fallbacks when Redis is slow or down.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/go-redis-caching\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-05-16T03:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-10-10T15:51:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-redis-caching-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Smita\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Smita\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-redis-caching\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-redis-caching\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"Go Redis Caching: Speed Up Your API\",\"datePublished\":\"2026-05-16T03:30:00+00:00\",\"dateModified\":\"2026-10-10T15:51:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-redis-caching\\\/\"},\"wordCount\":1484,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-redis-caching\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-redis-caching-featured.png\",\"keywords\":[\"Go Lang\",\"Go Redis\",\"Go Tutorial\",\"Golang Basics\"],\"articleSection\":[\"Go Lang\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-redis-caching\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-redis-caching\\\/\",\"name\":\"Go Redis Caching: Make Your Go API Much Faster\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-redis-caching\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-redis-caching\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-redis-caching-featured.png\",\"datePublished\":\"2026-05-16T03:30:00+00:00\",\"dateModified\":\"2026-10-10T15:51:28+00:00\",\"description\":\"Learn Go Redis caching step by step: the cache-aside pattern, TTLs, cache invalidation and safe fallbacks when Redis is slow or down.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-redis-caching\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-redis-caching\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-redis-caching\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-redis-caching-featured.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-redis-caching-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Go Redis Caching featured image: cards for cache hits, misses and invalidation\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-redis-caching\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go Redis Caching: Speed Up Your API\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\",\"name\":\"Smita Bharat Blog\",\"description\":\"Golang &amp; Backend Development Tutorials and Interview Questions\",\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"alternateName\":\"Smita Bharat\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\",\"name\":\"Smita\",\"logo\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/smitabharat.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Go Redis Caching: Make Your Go API Much Faster","description":"Learn Go Redis caching step by step: the cache-aside pattern, TTLs, cache invalidation and safe fallbacks when Redis is slow or down.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/smitabharat.com\/blog\/go-redis-caching\/","og_locale":"en_US","og_type":"article","og_title":"Go Redis Caching: Make Your Go API Much Faster","og_description":"Learn Go Redis caching step by step: the cache-aside pattern, TTLs, cache invalidation and safe fallbacks when Redis is slow or down.","og_url":"https:\/\/smitabharat.com\/blog\/go-redis-caching\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-05-16T03:30:00+00:00","article_modified_time":"2026-10-10T15:51:28+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-redis-caching-featured.png","type":"image\/png"}],"author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/go-redis-caching\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/go-redis-caching\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"Go Redis Caching: Speed Up Your API","datePublished":"2026-05-16T03:30:00+00:00","dateModified":"2026-10-10T15:51:28+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-redis-caching\/"},"wordCount":1484,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-redis-caching\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-redis-caching-featured.png","keywords":["Go Lang","Go Redis","Go Tutorial","Golang Basics"],"articleSection":["Go Lang"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/go-redis-caching\/","url":"https:\/\/smitabharat.com\/blog\/go-redis-caching\/","name":"Go Redis Caching: Make Your Go API Much Faster","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-redis-caching\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-redis-caching\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-redis-caching-featured.png","datePublished":"2026-05-16T03:30:00+00:00","dateModified":"2026-10-10T15:51:28+00:00","description":"Learn Go Redis caching step by step: the cache-aside pattern, TTLs, cache invalidation and safe fallbacks when Redis is slow or down.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/go-redis-caching\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/go-redis-caching\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/go-redis-caching\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-redis-caching-featured.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-redis-caching-featured.png","width":2400,"height":1260,"caption":"Go Redis Caching featured image: cards for cache hits, misses and invalidation"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/go-redis-caching\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Go Redis Caching: Speed Up Your API"}]},{"@type":"WebSite","@id":"https:\/\/smitabharat.com\/blog\/#website","url":"https:\/\/smitabharat.com\/blog\/","name":"Smita Bharat Blog","description":"Golang &amp; Backend Development Tutorials and Interview Questions","publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"alternateName":"Smita Bharat","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/smitabharat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339","name":"Smita","logo":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/smitabharat.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/379","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/comments?post=379"}],"version-history":[{"count":1,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/379\/revisions"}],"predecessor-version":[{"id":389,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/379\/revisions\/389"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/363"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=379"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=379"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=379"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=379"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}