• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jcmellado / dartis / 53

pending completion
53

Pull #25

travis-ci

web-flow
- Fixed coverage configuration
Pull Request #25: Release 0.4.0

2 of 2 new or added lines in 1 file covered. (100.0%)

1238 of 1434 relevant lines covered (86.33%)

1.41 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.62
/lib/src/commands/key.dart
1
// Copyright (c) 2018, Juan Mellado. All rights reserved. Use of this source
2
// is governed by a MIT-style license that can be found in the LICENSE file.
3

4
import 'dart:async' show Future;
5

6
import '../command.dart';
7
import '../protocol.dart';
8

9
/// Redis keys commands.
10
abstract class KeyCommands<K, V> {
11
  /// Removes the specified keys.
12
  ///
13
  /// Returns the number of keys that were removed.
14
  ///
15
  /// See https://redis.io/commands/del
16
  Future<int> del({K key, Iterable<K> keys = const []});
17

18
  /// Returns a serialized version of the value stored at [key] in a
19
  /// Redis-specific format.
20
  ///
21
  /// See https://redis.io/commands/dump
22
  Future<List<int>> dump(K key);
23

24
  /// Determines if a set of keys exist.
25
  ///
26
  /// Returns the number of keys existing among the ones specified as arguments.
27
  ///
28
  /// See https://redis.io/commands/exists
29
  Future<int> exists({K key, Iterable<K> keys = const []});
30

31
  /// Sets a [key]'s time to live in [seconds].
32
  ///
33
  /// Returns `1` if the timeout was set, `0` if [key] does not exist.
34
  ///
35
  /// See https://redis.io/commands/expire
36
  Future<int> expire(K key, int seconds);
37

38
  /// Sets the expiration for a [key] as a UNIX timestamp.
39
  ///
40
  /// Returns `1` if the timeout was set, `0` if [key] does not exist.
41
  ///
42
  /// See https://redis.io/commands/expireat
43
  Future<int> expireat(K key, int timestamp);
44

45
  /// Returns all keys matching [pattern].
46
  ///
47
  /// See https://redis.io/commands/keys
48
  Future<List<K>> keys(K pattern);
49

50
  /// Atomically transfers some keys from a source Redis instance to a
51
  /// destination Redis instance.
52
  ///
53
  /// Returns `OK` on success, `NOKEY` if no keys were found in the
54
  /// source instance.
55
  ///
56
  /// See https://redis.io/commands/migrate
57
  Future<String> migrate(String host, int port, int destinationDb, int timeout,
58
      {bool copy = false,
59
      bool replace = false,
60
      K key,
61
      Iterable<K> keys = const []});
62

63
  /// Moves [key] from the currently selected database to the specified
64
  /// destination database.
65
  ///
66
  /// Returns `1` if [key] was moved, `0` if [key] was not moved.
67
  ///
68
  /// See https://redis.io/commands/move
69
  Future<int> move(K key, int db);
70

71
  /// Inspects the internals of the Redis Object associated with a [key].
72
  ///
73
  /// See [objectHelp].
74
  ///
75
  /// See https://redis.io/commands/object
76
  Future<String> object(ObjectSubcommand subcommand, K key);
77

78
  /// Returns a succint help text for the OBJECT command.
79
  ///
80
  /// See [object].
81
  ///
82
  /// See https://redis.io/commands/object
83
  Future<List<String>> objectHelp();
84

85
  /// Removes the existing timeout on [key].
86
  ///
87
  /// Returns `1` if the timeout was removed, `0` if [key] does not exist
88
  /// or does not have an associated timeout.
89
  ///
90
  /// See https://redis.io/commands/persist
91
  Future<int> persist(K key);
92

93
  /// Sets a [key]'s time to live in milliseconds.
94
  ///
95
  /// Returns `1` if the timeout was set, `0` if [key] does not exist.
96
  ///
97
  /// See https://redis.io/commands/pexpire
98
  Future<int> pexpire(K key, int milliseconds);
99

100
  /// Sets the expiration for a [key] as a UNIX timestamp specified
101
  /// in milliseconds.
102
  ///
103
  /// Returns `1` if the timeout was set, `0` if [key] does not exist.
104
  ///
105
  /// See https://redis.io/commands/pexpireat
106
  Future<int> pexpireat(K key, int millisecondsTimestamp);
107

108
  /// Returns the time to live for a [key] in milliseconds.
109
  ///
110
  /// See https://redis.io/commands/pttl
111
  Future<int> pttl(K key);
112

113
  /// Returns a random key from the currently selected database.
114
  ///
115
  /// See https://redis.io/commands/randomkey
116
  Future<K> randomkey();
117

118
  /// Renames [key] to [newkey].
119
  ///
120
  /// See https://redis.io/commands/rename
121
  Future<void> rename(K key, K newkey);
122

123
  /// Renames [key] to [newkey] if [newkey] does not yet exist.
124
  ///
125
  /// Returns `1` if [key] was renamed to [newkey], `0` if [newkey]
126
  /// already exists.
127
  ///
128
  /// See https://redis.io/commands/renamenx
129
  Future<int> renamenx(K key, K newkey);
130

131
  /// Creates a [key] associated with a value that is obtained by
132
  /// deserializing the provided serialized value (obtained via [dump]).
133
  ///
134
  /// See https://redis.io/commands/restore
135
  Future<void> restore(K key, int ttl, List<int> serializedValue,
136
      {bool replace = false});
137

138
  /// Incrementally iterates the keys space.
139
  ///
140
  /// See https://redis.io/commands/scan
141
  Future<KeyScanResult<K>> scan(int cursor, {K pattern, int count});
142

143
  /// Sort the elements in a list, set or sorted set.
144
  ///
145
  /// Returns the sorted elements.
146
  ///
147
  /// See [sortStore].
148
  ///
149
  /// See https://redis.io/commands/sort
150
  Future<List<V>> sort(K key,
151
      {K by,
152
      int offset,
153
      int count,
154
      Iterable<K> get = const [],
155
      SortOrder order,
156
      bool alpha = false});
157

158
  /// Sort the elements in a list, set or sorted set and stores the result
159
  /// at [destination].
160
  ///
161
  /// Returns the number of sorted elements in the destination list.
162
  ///
163
  /// See [sort].
164
  ///
165
  /// See https://redis.io/commands/sort
166
  Future<int> sortStore(K key, K destination,
167
      {K by,
168
      int offset,
169
      int count,
170
      Iterable<K> get = const [],
171
      SortOrder order,
172
      bool alpha = false});
173

174
  /// Alters the last access time of a key.
175
  ///
176
  /// Returns the number of keys that were touched.
177
  ///
178
  /// See https://redis.io/commands/touch
179
  Future<int> touch({K key, Iterable<K> keys = const []});
180

181
  /// Returns the remaining time to live of a [key].
182
  ///
183
  /// See https://redis.io/commands/ttl
184
  Future<int> ttl(K key);
185

186
  /// Returns the string representation of the type of the value stored
187
  /// at [key].
188
  ///
189
  /// See https://redis.io/commands/type
190
  Future<String> type(K key);
191

192
  /// Removes the specified keys asynchronously in another thread.
193
  ///
194
  /// Returns the number of keys that were unlinked.
195
  ///
196
  /// See https://redis.io/commands/unlink
197
  Future<int> unlink({K key, Iterable<K> keys = const []});
198

199
  /// Blocks the current client until all the previous write commands
200
  /// are successfully transferred and acknowledged by at least the
201
  /// specified number of slave.
202
  ///
203
  /// Returns the number of slaves reached by all the writes performed
204
  /// in the context of the current connection.
205
  ///
206
  /// See https://redis.io/commands/wait
207
  Future<int> wait(int numslaves, int timeout);
208
}
209

210
/// Orders.
211
class SortOrder {
212
  /// The name of the order.
213
  final String name;
214

215
  const SortOrder._(this.name);
×
216

217
  /// Ascending.
218
  static const SortOrder ascending = SortOrder._(r'ASC');
219

220
  /// Descending.
221
  static const SortOrder descending = SortOrder._(r'DESC');
222

223
  @override
1✔
224
  String toString() => 'SortOrder: $name';
2✔
225
}
226

227
/// Allowed subcommands for the OBJECT command.
228
class ObjectSubcommand {
229
  /// The name of the command.
230
  final String name;
231

232
  const ObjectSubcommand._(this.name);
×
233

234
  /// Returns the number of references of the value associated with the
235
  /// specified key.
236
  static const ObjectSubcommand refcount = ObjectSubcommand._(r'REFCOUNT');
237

238
  /// Returns the kind of internal representation used in order to store
239
  /// the value associated with a key.
240
  static const ObjectSubcommand encoding = ObjectSubcommand._(r'ENCODING');
241

242
  /// Returns the number of seconds since the object stored at the
243
  /// specified key is idle.
244
  static const ObjectSubcommand idletime = ObjectSubcommand._(r'IDLETIME');
245

246
  /// Returns the logarithmic access frequency counter of the object
247
  /// stored at the specified key.
248
  static const ObjectSubcommand freq = ObjectSubcommand._(r'FREQ');
249

250
  @override
1✔
251
  String toString() => 'ObjectSubcommand: $name';
2✔
252
}
253

254
/// Result of the SCAN command.
255
class KeyScanResult<K> {
256
  /// The cursor.
257
  final int cursor;
258

259
  /// The keys.
260
  final List<K> keys;
261

262
  /// Creates a [KeyScanResult] instance.
263
  const KeyScanResult(this.cursor, this.keys);
1✔
264

265
  @override
1✔
266
  String toString() => 'KeyScanResult<$K>: {cursor=$cursor, keys=$keys}';
3✔
267
}
268

269
/// A mapper for the SCAN command.
270
class KeyScanMapper<K> implements Mapper<KeyScanResult<K>> {
271
  @override
1✔
272
  KeyScanResult<K> map(covariant ArrayReply reply, RedisCodec codec) {
273
    final cursor = codec.decode<int>(reply.array[0]);
3✔
274
    final keys = codec.decode<List<K>>(reply.array[1]);
3✔
275

276
    return KeyScanResult<K>(cursor, keys);
1✔
277
  }
278
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2023 Coveralls, Inc