• 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

68.42
/lib/src/commands/string.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
/// A convenient shared mapper for the SET command.
10
const StringSetMapper stringSetMapper = StringSetMapper();
11

12
/// Redis strings commands.
13
abstract class StringCommands<K, V> {
14
  /// Appends a [value] to a [key].
15
  ///
16
  /// Returns the length of the string after the append operation.
17
  ///
18
  /// See https://redis.io/commands/append
19
  Future<int> append(K key, V value);
20

21
  /// Returns the number of bits set to 1 in a string.
22
  ///
23
  /// See https://redis.io/commands/bitcount
24
  Future<int> bitcount(K key, [int start, int end]);
25

26
  /// Performs arbitrary bitfield integer [operations] in a string.
27
  ///
28
  /// Returns a list with each entry being the corresponding result of
29
  /// the operation given at the same position.
30
  ///
31
  /// See https://redis.io/commands/bitfield
32
  Future<List<int>> bitfield(K key, List<BitfieldOperation> operations);
33

34
  /// Performs bitwise operations between strings.
35
  ///
36
  /// Returns the size of the string stored in the destination key.
37
  ///
38
  /// See https://redis.io/commands/bitop
39
  Future<int> bitop(BitopOperation operation, K destkey,
40
      {K key, Iterable<K> keys = const []});
41

42
  /// Returns the position of the first bit set to 1 or 0 according to the
43
  /// request.
44
  ///
45
  /// See https://redis.io/commands/bitpos
46
  Future<int> bitpos(K key, int bit, [int start, int end]);
47

48
  /// Decrements the number stored at [key] by one.
49
  ///
50
  /// Returns the value of [key] after the decrement.
51
  ///
52
  /// See https://redis.io/commands/decr
53
  Future<int> decr(K key);
54

55
  /// Decrements the number stored at [key] by [decrement].
56
  ///
57
  /// Returns the value of [key] after the decrement.
58
  ///
59
  /// See https://redis.io/commands/decrby
60
  Future<int> decrby(K key, int decrement);
61

62
  /// Returns the value of [key].
63
  ///
64
  /// See https://redis.io/commands/get
65
  Future<V> get(K key);
66

67
  /// Returns the bit value at [offset] in the string value stored at [key].
68
  ///
69
  /// See https://redis.io/commands/getbit
70
  Future<int> getbit(K key, int offset);
71

72
  /// Returns the substring of the string value stored at [key], determined
73
  /// by the offsets [start] and [end].
74
  ///
75
  /// See https://redis.io/commands/getrange
76
  Future<V> getrange(K key, int start, int end);
77

78
  /// Atomically sets [key] to [value] and returns the old value stored
79
  /// at [key].
80
  ///
81
  /// See https://redis.io/commands/getset
82
  Future<V> getset(K key, V value);
83

84
  /// Increments the number stored at [key] by one.
85
  ///
86
  /// Returns the value of [key] after the increment.
87
  ///
88
  /// See https://redis.io/commands/incr
89
  Future<int> incr(K key);
90

91
  /// Increments the number stored at [key] by [increment].
92
  ///
93
  /// Returns the value of [key] after the increment.
94
  ///
95
  /// See https://redis.io/commands/incrby
96
  Future<int> incrby(K key, int increment);
97

98
  /// Increments the floating point number stored at [key] by the
99
  /// specified [increment].
100
  ///
101
  /// Returns the value of [key] after the increment.
102
  ///
103
  /// See https://redis.io/commands/incrbyfloat
104
  Future<double> incrbyfloat(K key, double increment);
105

106
  /// Returns the values of all specified keys.
107
  ///
108
  /// See https://redis.io/commands/mget
109
  Future<List<V>> mget({K key, Iterable<K> keys = const []});
110

111
  /// Sets the given keys to their respective values.
112
  ///
113
  /// See https://redis.io/commands/mset
114
  Future<void> mset({K key, V value, Map<K, V> map = const {}});
115

116
  /// Sets the given keys to their respective values, but only if all keys
117
  /// already exist.
118
  ///
119
  /// Returns `1` if the all the keys were set, `0` if no key was set.
120
  ///
121
  /// See https://redis.io/commands/msetnx
122
  Future<int> msetnx({K key, V value, Map<K, V> map = const {}});
123

124
  /// Sets the [value] and expiration in [milliseconds] of a [key].
125
  ///
126
  /// See https://redis.io/commands/psetex
127
  Future<void> psetex(K key, int milliseconds, V value);
128

129
  /// Sets the [value] of a [key].
130
  ///
131
  /// Returns `true` if the operation was executed correctly, `false` otherwise.
132
  ///
133
  /// See https://redis.io/commands/set
134
  Future<bool> set(K key, V value,
135
      {int seconds, int milliseconds, SetExistMode mode});
136

137
  /// Sets or clears the bit at [offset] in the string value stored at [key].
138
  ///
139
  /// Returns the original bit value stored at [offset].
140
  ///
141
  /// See https://redis.io/commands/setbit
142
  Future<int> setbit(K key, int offset, int value);
143

144
  /// Sets the [value] and expiration of a [key].
145
  ///
146
  /// See https://redis.io/commands/setex
147
  Future<void> setex(K key, int seconds, V value);
148

149
  /// Sets the [value] of a [key], only if the [key] does not exist
150
  ///
151
  /// Returns `1` if the [key] was set, `0` if the [key] was not set.
152
  ///
153
  /// See https://redis.io/commands/setnx
154
  Future<int> setnx(K key, V value);
155

156
  /// Overwrites part of the string stored at [key], starting at the
157
  /// specified [offset], for the entire length of [value].
158
  ///
159
  /// Returns the length of the string after it was modified by the command.
160
  ///
161
  /// See https://redis.io/commands/setrange
162
  Future<int> setrange(K key, int offset, V value);
163

164
  /// Returns the length of the string value stored at [key].
165
  ///
166
  /// See https://redis.io/commands/strlen
167
  Future<int> strlen(K key);
168
}
169

170
/// Allowed commands for the BITFIELD command.
171
class BitfieldCommand {
172
  /// The name of the command.
173
  final String name;
174

175
  const BitfieldCommand._(this.name);
×
176

177
  /// Returns the specified bit field.
178
  static const BitfieldCommand get = BitfieldCommand._(r'GET');
179

180
  /// Set the specified bit field and returns its old value.
181
  static const BitfieldCommand set = BitfieldCommand._(r'SET');
182

183
  /// Increments/decrements the specified bit field and returns the new value.
184
  static const BitfieldCommand incrby = BitfieldCommand._(r'INCRBY');
185

186
  @override
1✔
187
  String toString() => 'BitfieldCommand: $name';
2✔
188
}
189

190
/// The modes used to fine-tune the behavior of the increment and decrement
191
/// overflow (or underflow) for the BITFIELD command.
192
class BitfieldOverflow {
193
  /// The name of the mode.
194
  final String name;
195

196
  const BitfieldOverflow._(this.name);
×
197

198
  /// Wrap around, both with signed and unsigned integers.
199
  static const BitfieldOverflow wrap = BitfieldOverflow._(r'WRAP');
200

201
  /// Uses saturation arithmetic.
202
  static const BitfieldOverflow sat = BitfieldOverflow._(r'SAT');
203

204
  /// No operation is performed on overflows or underflows detected.
205
  static const BitfieldOverflow fail = BitfieldOverflow._(r'FAIL');
206

207
  @override
1✔
208
  String toString() => 'BitfieldOverflow: $name';
2✔
209
}
210

211
/// Allowed operations for the BITOP command.
212
class BitopOperation {
213
  /// The name of the operation.
214
  final String name;
215

216
  const BitopOperation._(this.name);
×
217

218
  /// AND.
219
  static const BitopOperation and = BitopOperation._(r'AND');
220

221
  /// OR.
222
  static const BitopOperation or = BitopOperation._(r'OR');
223

224
  /// XOR.
225
  static const BitopOperation xor = BitopOperation._(r'XOR');
226

227
  /// NOT.
228
  static const BitopOperation not = BitopOperation._(r'NOT');
229

230
  @override
1✔
231
  String toString() => 'BitopOperation: $name';
2✔
232
}
233

234
/// Allowed modes for the SET command.
235
class SetExistMode {
236
  /// The name of the mode.
237
  final String name;
238

239
  const SetExistMode._(this.name);
×
240

241
  /// Only set the key if it does not already exist.
242
  static const SetExistMode nx = SetExistMode._(r'NX');
243

244
  /// Only set the key if it already exist.
245
  static const SetExistMode xx = SetExistMode._(r'XX');
246

247
  @override
1✔
248
  String toString() => 'SetExistMode: $name';
2✔
249
}
250

251
/// Operations to be performed for the BITFIELD command.
252
class BitfieldOperation {
253
  /// The command.
254
  final BitfieldCommand command;
255

256
  /// The type.
257
  final String type;
258

259
  /// The offset.
260
  final String offset;
261

262
  /// The value/increment.
263
  final int value;
264

265
  /// The overflow.
266
  final BitfieldOverflow overflow;
267

268
  /// Creates a [BitfieldOperation] instance.
269
  const BitfieldOperation(this.command, this.type, this.offset,
×
270
      {this.value, this.overflow});
271

272
  @override
1✔
273
  String toString() => '''BitfieldOperation: {command=$command, type=$type,'''
2✔
274
      ''' offset=$offset, value=$value, overflow=$overflow}''';
3✔
275
}
276

277
/// Mapper to be used with the SET command.
278
class StringSetMapper implements Mapper<bool> {
279
  /// Creates a [StringSetMapper] instance.
280
  const StringSetMapper();
×
281

282
  @override
1✔
283
  bool map(Reply reply, RedisCodec codec) => reply.value != null;
1✔
284
}
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