-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.dart
74 lines (61 loc) · 2.18 KB
/
example.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import 'dart:async';
import 'package:dedis/dedis.dart';
Future<void> main() async {
final cli = await RedisClient.connect(
'localhost',
6379,
db: 1,
password: '123456789',
);
final com = cli.getCommands<String, String>();
print(await com.keys('*'));
print('set get exists');
print(await com.set('key', 'value1'));
print(await com.get('key'));
print(await com.exists('key'));
print('set get exists');
print(await com.set('key', 'value2'));
print(await com.get('key'));
print(await com.exists('key'));
print('del get exists');
print(await com.del('key'));
print(await com.get('key'));
print(await com.exists('key'));
print('set get getdel exists');
print(await com.set('key', 'value2'));
print(await com.get('key'));
print(await com.getdel('key'));
print(await com.exists('key'));
print('set set set set keys keys');
print(await com.set('key', 'value'));
print(await com.set('key2', 'value'));
print(await com.set('key3', 'value'));
print(await com.set('key4', 'value'));
print(await com.keys('*'));
print(await com.keys('key*'));
print('set expire exists exists');
print(await com.set('key', 'value'));
print(await com.expire('key', Duration(seconds: 1)));
print(await com.exists('key'));
await Future.delayed(Duration(seconds: 1));
print(await com.exists('key'));
print('lpush lrange lpush lrange rpush lset');
print(await com.lpush('list_key', ['value1']));
print(await com.lrange('list_key', 0, -1));
print(await com.lpush('list_key', ['value l1']));
print(await com.lrange('list_key', 0, -1));
print(await com.rpush('list_key', ['value r1']));
print(await com.lset('list_key', 1, 'value2'));
print('pubsub');
final psCli = await RedisClient.connect('localhost', 6379, db: 1);
final PubSubCommands<String> psCom = psCli.getCommands<String, String>();
unawaited(psCom.psubscribe('/test/*').forEach((element) {
print('psubscribe: $element');
}));
print(await com.publish('/test/1', 'message/1'));
print(await com.publish('/test/2', 'message/2'));
print(await com.publish('/test/3', 'message/3'));
print(await com.publish('/test1/1', 'message1/1'));
await cli.close();
await psCli.close();
}