By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
10alert.com10alert.com10alert.com
  • Threats
    • WordPress ThreatsDanger
    Threats
    A cyber or cybersecurity threat is a malicious act that seeks to damage data, steal data, or disrupt digital life in general. Cyber threats include…
    Show More
    Top News
    Web Malware: Out of the Shadows and Hiding in Plain Sight
    12 months ago
    7 Reasons Kaspersky Internet Security 2015 is better than ever
    12 months ago
    Multi-stage phishing that starts with real links
    12 months ago
    Latest News
    Know your Malware – A Beginner’s Guide to Encoding Techniques Used to Obfuscate Malware
    8 hours ago
    Beware of scammers! Dangerous apps in the App Store
    3 days ago
    How To Limit Login Attempts on WordPress (+ Should You?)
    4 days ago
    Wordfence Intelligence Weekly WordPress Vulnerability Report (September 18, 2023 to September 24, 2023)
    4 days ago
  • Fix
    Fix
    Troubleshooting guide you need when errors, bugs or technical glitches might ruin your digital experience.
    Show More
    Top News
    Critical vulnerability fixed in popular WordPress plugin Jetpack
    Critical vulnerability fixed in popular WordPress plugin Jetpack
    12 months ago
    Windows 10 22H2 new features and changes
    12 months ago
    Windows 11 build 22000.652 (KB5012643) out as preview
    12 months ago
    Latest News
    How automatically delete unused files from my Downloads folder?
    8 months ago
    Now you can speed up any video in your browser
    8 months ago
    How to restore access to a file after EFS or view it on another computer?
    8 months ago
    18 Proven Tips to Speed Up Your WordPress Site and Improve SEO | 2023 Guide
    9 months ago
  • How To
    How ToShow More
    Xbox celebrates gaming and disability community
    7 hours ago
    A Socket API that works across JavaScript runtimes — announcing a WinterCG spec and Node.js implementation of connect()
    A Socket API that works across JavaScript runtimes — announcing a WinterCG spec and Node.js implementation of connect()
    7 hours ago
    Running Serverless Puppeteer with Workers and Durable Objects
    Running Serverless Puppeteer with Workers and Durable Objects
    7 hours ago
    everything we announced — plus an AI-powered opportunity for startups
    everything we announced — plus an AI-powered opportunity for startups
    7 hours ago
    Easily manage AI crawlers with our new bot categories
    Easily manage AI crawlers with our new bot categories
    1 day ago
  • News
    News
    This category of resources includes the latest technology news and updates, covering a wide range of topics and innovations in the tech industry. From new…
    Show More
    Top News
    Bug in Facebook Messenger Kids
    12 months ago
    Categories of chats in Telegram X
    12 months ago
    JavaScript magic on the example of TgStat
    12 months ago
    Latest News
    How to create Copilot desktop shortcut on Windows 11
    16 hours ago
    How to enable extensions for Google Bard AI
    3 days ago
    Window 11 Copilot: 10 Best tips and tricks
    4 days ago
    How to create AI images with Cocreator on Paint for Windows 11
    5 days ago
  • Glossary
  • My Bookmarks
Reading: Cloudflare Workers database integration with Upstash
Share
Notification Show More
Aa
Aa
10alert.com10alert.com
  • Threats
  • Fix
  • How To
  • News
  • Glossary
  • My Bookmarks
  • Threats
    • WordPress ThreatsDanger
  • Fix
  • How To
  • News
  • Glossary
  • My Bookmarks
Follow US
Apps

Cloudflare Workers database integration with Upstash

Andra Smith
Last updated: 2 August
Andra Smith 2 months ago
Share
4 Min Read

Cloudflare and Upstash partnership

Contents
Add the integrationImplementation example Try it now

During Developer Week we announced Database Integrations on Workers  a new and seamless way to connect with some of the most popular databases. You select the provider, authorize through an OAuth2 flow and automatically get the right configuration stored as encrypted environment variables to your Worker.

Today we are thrilled to announce that we have been working with Upstash to expand our integrations catalog. We are now offering three new integrations: Upstash Redis, Upstash Kafka and Upstash QStash. These integrations allow our customers to unlock new capabilities on Workers. Providing them with a broader range of options to meet their specific requirements.

Add the integration

We are going to show the setup process using the Upstash Redis integration.

Select your Worker, go to the Settings tab, select the Integrations tab to see all the available integrations.

Workers Integration tab showing all Integrations

After selecting the Upstash Redis integration we will get the following page.

Upstash Integration flow showing all steps to complete this Integration

First, you need to review and grant permissions, so the Integration can add secrets to your Worker. Second, we need to connect to Upstash using the OAuth2 flow. Third, select the Redis database we want to use. Then, the Integration will fetch the right information to generate the credentials. Finally, click “Add Integration” and it’s done! We can now use the credentials as environment variables on our Worker.

Implementation example

On this occasion we are going to use the CF-IPCountry  header to conditionally return a custom greeting message to visitors from Paraguay, United States, Great Britain and Netherlands. While returning a generic message to visitors from other countries.

To begin we are going to load the custom greeting messages using Upstash’s online CLI tool.

➜ set PY "Mba'ẽichapa 🇵🇾" OK ➜ set US "How are you? 🇺🇸" OK ➜ set GB "How do you do? 🇬🇧" OK ➜ set NL "Hoe gaat het met u? 🇳🇱" OK

We also need to install @upstash/redis package on our Worker before we upload the following code.

import { Redis } from '@upstash/redis/cloudflare'   export default {   async fetch(request, env, ctx) {     const country=request.headers.get("cf-ipcountry");     const redis=Redis.fromEnv(env);     if (country) {       const localizedMessage=await redis.get(country);       if (localizedMessage) {         return new Response(localizedMessage);       }     }     return new Response("👋👋 Hello there! 👋👋");   }, }; 

Just like that we are returning a localized message from the Redis instance depending on the country which the request originated from. Furthermore, we have a couple ways to improve performance, for write heavy use cases we can use Smart Placement with no replicas, so the Worker code will be executed near the Redis instance provided by Upstash. Otherwise, creating a Global Database on Upstash to have multiple read replicas across regions will help.

Try it now

Upstash Redis, Kafka and QStash are now available for all users! Stay tuned for more updates as we continue to expand our Database Integrations catalog.


Source: cloudflare.com

Translate this article

TAGGED: Cloudflare, DoS
Andra Smith August 2, 2023 August 2, 2023
Share This Article
Facebook Twitter Reddit Telegram Email Copy Link Print

STAY CONECTED

24.8k Followers Like
253.9k Followers Follow
33.7k Subscribers Subscribe
124.8k Members Follow

LAST 10 ALERT

Xbox celebrates gaming and disability community
Windows 7 hours ago
A Socket API that works across JavaScript runtimes — announcing a WinterCG spec and Node.js implementation of connect()
A Socket API that works across JavaScript runtimes — announcing a WinterCG spec and Node.js implementation of connect()
Apps 7 hours ago
Running Serverless Puppeteer with Workers and Durable Objects
Running Serverless Puppeteer with Workers and Durable Objects
Apps 7 hours ago
everything we announced — plus an AI-powered opportunity for startups
everything we announced — plus an AI-powered opportunity for startups
Apps 7 hours ago
Know your Malware – A Beginner’s Guide to Encoding Techniques Used to Obfuscate Malware
Know your Malware – A Beginner’s Guide to Encoding Techniques Used to Obfuscate Malware
Wordpress Threats 11 hours ago

You Might Also Like

A Socket API that works across JavaScript runtimes — announcing a WinterCG spec and Node.js implementation of connect()
Apps

A Socket API that works across JavaScript runtimes — announcing a WinterCG spec and Node.js implementation of connect()

7 hours ago
Running Serverless Puppeteer with Workers and Durable Objects
Apps

Running Serverless Puppeteer with Workers and Durable Objects

7 hours ago
everything we announced — plus an AI-powered opportunity for startups
Apps

everything we announced — plus an AI-powered opportunity for startups

7 hours ago
Easily manage AI crawlers with our new bot categories
Apps

Easily manage AI crawlers with our new bot categories

1 day ago
Show More

Related stories

How to install September 2023 update with 23H2 features for Windows 11
How to upgrade to Windows 11 23H2 with Installation Assistant
How to get the latest Windows 11 innovations
How to blur image background in Photos for Windows 11
How to download official Windows 11 23H2 ISO file
PHP Object Injection Vulnerability in Flatsome Theme

10 New Stories

How to create Copilot desktop shortcut on Windows 11
Easily manage AI crawlers with our new bot categories
Cloudflare is free of CAPTCHAs; Turnstile is free for everyone
Post-quantum cryptography goes GA
Detecting zero-days before zero-day
See what threats are lurking in your Office 365 with Cloudflare Email Retro Scan
Previous Next
Hot News
Xbox celebrates gaming and disability community
A Socket API that works across JavaScript runtimes — announcing a WinterCG spec and Node.js implementation of connect()
Running Serverless Puppeteer with Workers and Durable Objects
everything we announced — plus an AI-powered opportunity for startups
Know your Malware – A Beginner’s Guide to Encoding Techniques Used to Obfuscate Malware
10alert.com10alert.com
Follow US
© 10 Alert Network. All Rights Reserved.
  • Privacy Policy
  • Contact
  • Customize Interests
  • My Bookmarks
  • Glossary
Go to mobile version
adbanner
AdBlock Detected
Our site is an advertising supported site. Please whitelist to support our site.
Okay, I'll Whitelist
Welcome Back!

Sign in to your account

Lost your password?