패키지, 저장소 및 앱 카테고리 검색

패키지 상세v1.2.0

resp_client

Dart용 RESP(Reedis 직렬화 프로토콜) 클라이언트입니다. Redis 명령을 실행하기 위한 저수준 및 고수준 API를 제공합니다.

AndroidiOSLinuxmacOSWindows
30일 다운로드
11.5만
좋아요
7
Pub 점수
140

패키지 설치

flutter pub add resp_client

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

Redis 데이터베이스와 상호 작용하기 위해 Redis 시리얼라이제이션 프로토콜(RESP)을 구현한 Dart 패키지입니다. Redis 명령을 전송하기 위한 저수준 및 고수준 API를 제공하여 Redis 서버와의 효율적인 통신을 가능하게 합니다. RESP 메시지에 대한 직접적인 제어가 필요한 개발자 또는 일반 작업을 위한 단순화된 인터페이스를 원하는 개발자를 대상으로 하며, Android, iOS, Linux, macOS, Windows 등 모든 주요 플랫폼을 지원합니다. 가볍고 빠르며 신뢰할 수 있는 Redis 통합이 필요한 애플리케이션에 적합합니다.

사용 사례

  • Flutter 앱에서 Redis에 연결하기
  • 프로그래밍 방식으로 Redis 명령 실행
  • 실시간 데이터 서비스 구축
  • 백엔드 시스템에 Redis 통합
  • Redis 발행/구독 메시지 처리

주요 기능

  • 저수준 RESP 메시지 처리
  • 고수준 명령 API
  • 크로스 플랫폼 지원
  • 경량이고 효율적
  • Redis 연결 풀링을 지원합니다

적합한 대상

  • Redis를 사용하는 Dart 개발자
  • Redis 통합이 필요한 Flutter 앱
  • Redis를 사용하는 백엔드 서비스
  • 실시간 애플리케이션 개발자
  • 고성능 데이터 저장을 요구하는 시스템

고려 사항

  • RESP 응답에 대한 오류 처리를 수동으로 수행해야 합니다
  • 고급 라이브러리에 비해 문서가 제한적
  • RESP 프로토콜에 익숙한 개발자에게 적합
  • 추가적인 추상화 없이 복잡한 Redis 사용 사례에 적합하지 않음
  • 고급 Redis 기능을 사용하려면 사용자 정의 래퍼가 필요할 수 있습니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

resp_client

A RESP (REdis Serialization Protocol) client for Dart. This package contains 3 libraries. resp_server implements the connectionn to the server, resp_client implements the Redis serialization protocol. resp_commands provides implementations of Redis commands in differents levels of convenience from low-level to easy-to-use.

3 Building blocks

There 3 fundamental building block:

  • RespServerConnection - A connection to a RESP server
  • RespClient - A RESP client connected to a RESP server implementing the request/response model and the RESP types
  • RespCommandsTierN - Implementation of Redis commands

Usage

Initialization and cleanup


import 'package:resp_client/resp_client.dart';
import 'package:resp_client/resp_commands.dart';
import 'package:resp_client/resp_server.dart';

void main(List<String> args) async {
  // create a server connection using sockets
  final server = await connectSocket('localhost');

  // create a client using the server connection
  final client = RespClient(server);

  // create commands of tier 2 using the client
  final commands = RespCommandsTier2(client);

  // execute some commands...

  // close connection to the server
  await server.close();
}

RESP Types

The RESP types are implemented by the classes:

  • RespSimpleString - payload type String
  • RespBulkString - payload type String?
  • RespInteger - payload type int
  • RespArray - payload type List<RespType>?
  • RespError - payload type String

All classes extends the class RestType. You can access the payload of a type using the getter payload.

The class RespType provides methods to convert to a concrete type and getters to check if it is a concrete type.

Use commands

Not all Redis commands are implemented in all tiers yet. Nevertheless, it is possible to execute very Redis command using tier 0. You can create a command object of every tier using a RespClient. It is allowed to create multiple command objects on the same client. Command objects of tier 1 and 2 provides a getter to the underlying tier.

Tier 0

This is the most basic and flexible tier. You can execute every Redis command using this tier. You have to provide a list of elements. All elements are converted to bulk strings using toString(). The result is a RespType. It is up to the user to convert the result to a concrete RESP type.


import 'package:resp_client/resp_server.dart';
import 'package:resp_client/resp_client.dart';
import 'package:resp_client/resp_commands.dart';

void main(List<String> args) async {

  // ... setup connection and client
  
  // create commands using the client
  final commands = RespCommandsTier0(client);

  // execute a command
  final result = await commands.execute(['SET', 'myKey', 'myValue', 'NX']);
  print(result.payload);

  // ... close connection
}

Tier 1

Commands of tier 1 provide some convenience on the parameter side. The user no longer has to build the commands from ground up. Instead, the commands are calle in a more Dart-like style. The result is always a RespType like in tier 0.


import 'package:resp_client/resp_server.dart';
import 'package:resp_client/resp_client.dart';
import 'package:resp_client/resp_commands.dart';

void main(List<String> args) async {

  // ... setup connection and client
  
  // create commands using the client
  final commands = RespCommandsTier1(client);

  // Execute the GET command. You don't have to build the command from ground up.
  // The result is a RespType. This is flexible but you have to convert to the
  // concrete type yourself.
  final result = await commands.get('mKey', 'myValue', mode: SetMode.onlyIfNotExists);
  print(result.toBulkString().payload);

  // ... close connection
}

Tier 2

Commands of tier 2 provide the same convenience on the parameter side as tier 1 commands. Additionally, the result of a command is converted for easy handling.

To convert the result, assumptions are made. As an example the GET command returns a bulk string. Thus, the implementation tries to convert the result from a RespType to a RespBulkString and then return the payload of type String?. But, if a GET command is executed as part of a transaction, the result is a RespSimpleString and the payload has different meaning. Thus, the command will fail. To get out of this, use the same command of the underlying tier.


void main(List<String> args) async {

  // ... setup connection and client
  
  // create commands using the client
  final commands = RespCommandsTier2(client);

  // Like tier 1 commands but the result is already convert.
  // In this case, result is of type String?.
  final result = await commands.get('mKey', 'myValue', mode: SetMode.onlyIfNotExists);
  print(result)

  // ... close connection
}

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.

순위