mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-22 16:18:28 -05:00
Streams: move ID ms/seq separator from '.' to '-'
After checking with the community via Twitter (here: https://twitter.com/antirez/status/915130876861788161) the verdict was to use ":". However I later realized, after users lamented the fact that it's hard to copy IDs just with double click, that this was the reason why I moved to "." in the first instance. Fortunately "-", that was the other option with most votes, also gets selected with double click on most terminal applications on Linux and MacOS. So my reasoning was: 1) We can't retain "." because it's actually confusing to newcomers, it looks like a floating number, people may be tricked into thinking they can order IDs numerically as floats. 2) Moving to a double-click-to-select format is much better. People will work with such IDs for long time when coding / debugging. Why making now a choice that will impact this for the next years? The only other viable option was "-", and that's what I did. Thanks.
This commit is contained in:
parent
50595a5889
commit
5082ec6419
@ -574,7 +574,7 @@ size_t streamReplyWithRange(client *c, stream *s, streamID *start, streamID *end
|
||||
while(streamIteratorGetID(&si,&id,&numfields)) {
|
||||
/* Emit a two elements array for each item. The first is
|
||||
* the ID, the second is an array of field-value pairs. */
|
||||
sds replyid = sdscatfmt(sdsempty(),"+%U.%U\r\n",id.ms,id.seq);
|
||||
sds replyid = sdscatfmt(sdsempty(),"+%U-%U\r\n",id.ms,id.seq);
|
||||
addReplyMultiBulkLen(c,2);
|
||||
addReplySds(c,replyid);
|
||||
addReplyMultiBulkLen(c,numfields*2);
|
||||
@ -660,7 +660,7 @@ int streamParseIDOrReply(client *c, robj *o, streamID *id, uint64_t missing_seq)
|
||||
}
|
||||
|
||||
/* Parse <ms>.<seq> form. */
|
||||
char *dot = strchr(buf,'.');
|
||||
char *dot = strchr(buf,'-');
|
||||
if (dot) *dot = '\0';
|
||||
uint64_t ms, seq;
|
||||
if (string2ull(buf,&ms) == 0) goto invalid;
|
||||
@ -740,7 +740,7 @@ void xaddCommand(client *c) {
|
||||
"target stream top item");
|
||||
return;
|
||||
}
|
||||
sds reply = sdscatfmt(sdsempty(),"+%U.%U\r\n",id.ms,id.seq);
|
||||
sds reply = sdscatfmt(sdsempty(),"+%U-%U\r\n",id.ms,id.seq);
|
||||
addReplySds(c,reply);
|
||||
|
||||
signalModifiedKey(c->db,c->argv[1]);
|
||||
@ -764,7 +764,7 @@ void xaddCommand(client *c) {
|
||||
/* Let's rewrite the ID argument with the one actually generated for
|
||||
* AOF/replication propagation. */
|
||||
robj *idarg = createObject(OBJ_STRING,
|
||||
sdscatfmt(sdsempty(),"%U.%U",id.ms,id.seq));
|
||||
sdscatfmt(sdsempty(),"%U-%U",id.ms,id.seq));
|
||||
rewriteClientCommandArgument(c,i,idarg);
|
||||
decrRefCount(idarg);
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
# return value is like strcmp() and similar.
|
||||
proc streamCompareID {a b} {
|
||||
if {$a eq $b} {return 0}
|
||||
lassign [split $a .] a_ms a_seq
|
||||
lassign [split $b .] b_ms b_seq
|
||||
lassign [split $a -] a_ms a_seq
|
||||
lassign [split $b -] b_ms b_seq
|
||||
if {$a_ms > $b_ms} {return 1}
|
||||
if {$a_ms < $b_ms} {return -1}
|
||||
# Same ms case, compare seq.
|
||||
@ -14,9 +14,9 @@ proc streamCompareID {a b} {
|
||||
# Note that this function does not care to handle 'seq' overflow
|
||||
# since it's a 64 bit value.
|
||||
proc streamNextID {id} {
|
||||
lassign [split $id .] ms seq
|
||||
lassign [split $id -] ms seq
|
||||
incr seq
|
||||
join [list $ms $seq] .
|
||||
join [list $ms $seq] -
|
||||
}
|
||||
|
||||
# Generate a random stream entry ID with the ms part between min and max
|
||||
@ -24,12 +24,12 @@ proc streamNextID {id} {
|
||||
# XRANGE against a Tcl implementation implementing the same concept
|
||||
# with Tcl-only code in a linear array.
|
||||
proc streamRandomID {min_id max_id} {
|
||||
lassign [split $min_id .] min_ms min_seq
|
||||
lassign [split $max_id .] max_ms max_seq
|
||||
lassign [split $min_id -] min_ms min_seq
|
||||
lassign [split $max_id -] max_ms max_seq
|
||||
set delta [expr {$max_ms-$min_ms+1}]
|
||||
set ms [expr {$min_ms+[randomInt $delta]}]
|
||||
set seq [randomInt 1000]
|
||||
return $ms.$seq
|
||||
return $ms-$seq
|
||||
}
|
||||
|
||||
# Tcl-side implementation of XRANGE to perform fuzz testing in the Redis
|
||||
|
Loading…
Reference in New Issue
Block a user