upstash_redis 2.0.0 copy "upstash_redis: ^2.0.0" to clipboard
upstash_redis: ^2.0.0 copied to clipboard

upstash/redis is an HTTP/REST based Redis client for dart, built on top of Upstash REST API.

Upstash Redis #

@upstash/redis is an HTTP/REST based Redis client for dart, built on top of Upstash REST API.

This Dart package mirrors the design of official upstash-redis typescript library. Find the documentation here.

It is the only connectionless (HTTP based) Redis client and designed for:

  • Serverless functions (AWS Lambda ...)
  • Cloudflare Workers
  • Fastly Compute@Edge
  • Client side web/mobile applications
  • WebAssembly
  • and other environments where HTTP is preferred over TCP.

See the list of APIs supported.

Quick Start #

Install #

dart pub add upstash_redis

Create database #

Create a new redis database on upstash

Basic Usage: #

import 'package:upstash_redis/upstash_redis.dart';

void main() async {
  const redis = new Redis(
    url: '<UPSTASH_REDIS_REST_URL>',
    token: '<UPSTASH_REDIS_REST_TOKEN>',
  );

  // string
  await redis.set('key', 'value');
  final value1 = await redis.get('key');
  print(value1);

  await redis.set('key2', 'value2', ex: 1);

  // sorted set
  await redis.zadd('scores', score: 1, member: 'team1');
  final value2 = await redis.zrange('scores', 0, 100);
  print(value1);

  // list
  await redis.lpush('elements', ['magnesium']);
  final value3 = await redis.lrange('elements', 0, 100);
  print(value3);

  // hash
  await redis.hset('people', {'name': 'joe'});
  final value4 = await redis.hget('people', 'name');
  print(value4);

  // sets
  await redis.sadd('animals', ['cat']);
  final value5 = await redis.spop<String>('animals', 1);
  print(value5);
  
  // json
  print(await redis.json.set('json', $, {'counter': 1, 'hello': '', 'name': 're'}));
  print(await redis.json.numincrby('json', r'$.counter', 1));
  print(await redis.json.set('json', r'$.hello', '"world"'));
  print(await redis.json.strappend('json', r'$.name', '"baz"'));
  print(await redis.json.strlen('json', r'$.name'));
  print(await redis.json.get('json', [r'$.name']));
}

Contributing #

  • Fork the repo on GitHub
  • Clone the project to your own machine
  • Commit changes to your own branch
  • Push your work back up to your fork
  • Submit a Pull request so that we can review your changes and merge

License #

This repo is licenced under MIT.

Credits #

5
likes
140
pub points
22%
popularity

Publisher

verified publisherswiftytime.com

upstash/redis is an HTTP/REST based Redis client for dart, built on top of Upstash REST API.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

collection, http

More

Packages that depend on upstash_redis