resp_client 0.1.6

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 68

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.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']));

  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.6

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages 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';
  
Version Uploaded Documentation Archive
0.1.6 Oct 3, 2018 Go to the documentation of resp_client 0.1.6 Download resp_client 0.1.6 archive
0.1.5 Sep 12, 2018 Go to the documentation of resp_client 0.1.5 Download resp_client 0.1.5 archive
0.1.4+2 Sep 1, 2018 Go to the documentation of resp_client 0.1.4+2 Download resp_client 0.1.4+2 archive
0.1.4+1 Sep 1, 2018 Go to the documentation of resp_client 0.1.4+1 Download resp_client 0.1.4+1 archive
0.1.4 Aug 26, 2018 Go to the documentation of resp_client 0.1.4 Download resp_client 0.1.4 archive
0.1.3 Aug 23, 2018 Go to the documentation of resp_client 0.1.3 Download resp_client 0.1.3 archive
0.1.2 Aug 8, 2018 Go to the documentation of resp_client 0.1.2 Download resp_client 0.1.2 archive
0.1.1 Jul 27, 2018 Go to the documentation of resp_client 0.1.1 Download resp_client 0.1.1 archive
0.1.0 Jul 27, 2018 Go to the documentation of resp_client 0.1.0 Download resp_client 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
44
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
68
Learn more about scoring.

We analyzed this package on Oct 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.4

Platforms

Detected platforms: Flutter, other

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

Health suggestions

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 description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Dependencies

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