resp_client 0.1.7

resp_client #

A RESP (REdis Serialization Protocol) client for Dart. This package contains 2 libraries. resp_client implements the Redis serialization protocol. resp_commands provides an easy to use API for Redis commands.

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
  • RespCommands - Easy to use API of the Redis commands

Usage #

Initialization #


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

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

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

  // create RESP commands using the client
  final commands = RespCommands(client);

  // ... execute Redis commands

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

Use commands #

If the command needed is already implemented, just use the RespCommands class.


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 RESP commands using the client
  final commands = RespCommands(client);

  // execute a command
  final value = await commands.get('someKey');

  // ... close connection
}

Use low-level API #

If the command needed is not implemented, use the low-level API (or create an issue or pull request on GitHub).


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

void main(List<String> args) async {

  // ... setup connection and client
  
  // execute a command...
  final RespType result1 = await client.writeType(RespArray([RespBulkString('GET'), RespBulkString('someKey')]));

  // ...or shorter
  final RespType result2 = await client.writeArrayOfBulk(['GET', 'someKey']);

  // ... close connection
}

Changelog #

0.1.7 #

  • Added SCAN command

0.1.6 #

  • Bugfix: RespClient hangs when pipelining commands

0.1.5 #

  • Added list commands (LPUSH, LPOP, etc.)

0.1.4 #

  • Added hash commands (HSET, HGET, etc.)

0.1.3 #

  • Added AUTH command

0.1.2 #

  • Bugfix: Fixed handling of null bulk strings and arrays in deserialization.
  • Added SELECT, FLUSHDB and FLUSHALL commands.
  • Cleaned up dependencies.
  • Changed Dart SDK constraint to Dart 2 stable.

0.1.1 #

  • Added PEXPIRE command.

0.1.0 #

  • Initial version

example/example.dart

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

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

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

  // create RESP commands using the client
  final commands = RespCommands(client);

  final clientList = await commands.clientList();
  print(clientList);

  await commands.select(1);

  final set = await commands.set('test', 'foobar', expire: Duration(seconds: 10));
  print(set);

  final exists = await commands.exists(['test']);
  print(exists);

  final ttl = await commands.ttl('test');
  print(ttl);

  final get = await commands.get('test');
  print(get);

  final del = await commands.del(['test']);
  print(del);

  print('--- hash operations ---');

  final hset1 = await commands.hset('hsh', 'f1', 'foo');
  print(hset1);

  final hset2 = await commands.hset('hsh', 'f2', 'bar');
  print(hset2);

  final hsetnx1 = await commands.hsetnx('hsh', 'f3', 'baz');
  print(hsetnx1);

  final hsetnx2 = await commands.hsetnx('hsh', 'f3', 'baz');
  print(hsetnx2);

  final hmset = await commands.hmset('hsh', {'f4': 'v1', 'f5': 'v2'});
  print(hmset);

  final hexists = await commands.hexists('hsh', 'f1');
  print(hexists);

  print(await commands.hget('hsh', 'f2'));

  print(await commands.hmget('hsh', ['f1', 'f2']));

  print(await commands.hgetall('hsh'));

  print(await commands.hkeys('hsh'));

  print(await commands.hvals('hsh'));

  print(await commands.hdel('hsh', ['f1', 'f3']));

  print(await commands.hgetall('hsh'));

  print(await commands.blpop(['keys'], 1));
  print(await commands.brpop(['keys'], 1));
  print(await commands.brpoplpush('source', 'destination', 1));
  print(await commands.lindex('key', 0));
  print(await commands.linsert('key', InsertMode.before, 'pivot', 'value'));
  print(await commands.llen('key'));
  print(await commands.lpop('key'));
  print(await commands.lpush('key', ['value']));
  print(await commands.lpushx('key', ['value']));
  print(await commands.lrange('key', 1, 2));
  print(await commands.lrem('key', 1, 'value'));
  print(await commands.lset('key', 1, 'value'));
  await commands.ltrim('key', 1, 2);
  print(await commands.rpop('key'));
  print(await commands.rpoplpush('source', 'destination'));
  print(await commands.rpush('key', ['values']));
  print(await commands.rpushx('key', ['values']));

  print(await commands.scan(0));

  await commands.flushAll();

  server.close();
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  resp_client: ^0.1.7

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:resp_client/resp_client.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
33
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
89
Overall:
Weighted score of the above. [more]
64
Learn more about scoring.

We analyzed this package on Jul 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, other

Primary library: package:resp_client/resp_client.dart with components: io.

Health suggestions

Fix lib/src/client/streamreader.dart. (-0.50 points)

Analysis of lib/src/client/streamreader.dart reported 1 hint:

line 40 col 46: Avoid types as parameter names.

Format lib/src/client/respclient.dart.

Run dartfmt to format lib/src/client/respclient.dart.

Format lib/src/client/socket.dart.

Run dartfmt to format lib/src/client/socket.dart.

Format lib/src/client/types.dart.

Run dartfmt to format lib/src/client/types.dart.

Format lib/src/commands/commands.dart.

Run dartfmt to format lib/src/commands/commands.dart.

Maintenance suggestions

The package description is too short. (-6 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Homepage URL is insecure. (-5 points)

Update the homepage field and use a secure (https) URL.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.3.0 <3.0.0
Dev dependencies
test ^1.3.3

Admin