Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@upstash/redis

Package Overview
Dependencies
Maintainers
4
Versions
797
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@upstash/redis

An HTTP/REST based Redis client built on top of Upstash REST API.

  • 0.0.0-ci.ab13a19fb29aed87c738632a215dbb1ec16a825e-20241004200556
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
229K
decreased by-41.46%
Maintainers
4
Weekly downloads
 
Created

What is @upstash/redis?

@upstash/redis is an npm package that provides a serverless Redis solution. It allows developers to interact with a Redis database using a simple and efficient API. The package is designed to work seamlessly with serverless environments, making it ideal for modern cloud-based applications.

What are @upstash/redis's main functionalities?

Basic Redis Commands

This feature allows you to perform basic Redis commands such as SET and GET. The code sample demonstrates how to set a key-value pair and retrieve it.

const { Redis } = require('@upstash/redis');
const redis = new Redis({ url: 'your-upstash-redis-url', token: 'your-upstash-token' });

async function run() {
  await redis.set('key', 'value');
  const value = await redis.get('key');
  console.log(value); // Output: 'value'
}

run();

Pub/Sub

This feature allows you to use the Pub/Sub (publish/subscribe) pattern. The code sample demonstrates how to subscribe to a channel and publish a message to it.

const { Redis } = require('@upstash/redis');
const redis = new Redis({ url: 'your-upstash-redis-url', token: 'your-upstash-token' });

async function run() {
  const subscriber = redis.duplicate();
  await subscriber.subscribe('channel', (message) => {
    console.log('Received message:', message);
  });

  await redis.publish('channel', 'Hello, World!');
}

run();

Transactions

This feature allows you to perform transactions in Redis. The code sample demonstrates how to use the MULTI and EXEC commands to execute multiple commands atomically.

const { Redis } = require('@upstash/redis');
const redis = new Redis({ url: 'your-upstash-redis-url', token: 'your-upstash-token' });

async function run() {
  const transaction = redis.multi();
  transaction.set('key1', 'value1');
  transaction.set('key2', 'value2');
  const results = await transaction.exec();
  console.log(results); // Output: [ 'OK', 'OK' ]
}

run();

Other packages similar to @upstash/redis

Keywords

FAQs

Package last updated on 04 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc