![]() It is possible to get the number of items inside a Stream just using the XLEN command: > XLEN mystream Returning back at our XADD example, after the key name and ID, the next arguments are the field-value pairs composing our stream entry. The fact that each Stream entry has an ID is another similarity with log files, where line numbers, or the byte offset inside the file, can be used in order to identify a given entry. Auto-generation of IDs by the server is almost always what you want, and the reasons for specifying an ID explicitly are very rare. Every new ID will be monotonically increasing, so in more simple terms, every new entry added will have a higher ID compared to all the past entries. However, in this case, we passed * because we want the server to generate a new ID for us. It gets as its first argument the key name mystream, the second argument is the entry ID that identifies every entry inside a stream. The above call to the XADD command adds an entry sensor-id: 1234, temperature: 19.8 to the stream at key mystream, using an auto-generated entry ID, which is the one returned by the command, specifically 1518951480106-0. ![]() The fundamental write command, called XADD, appends a new entry to the specified stream.Įach stream entry consists of one or more field-value pairs, somewhat like a record or a Redis hash: > XADD mystream * sensor-id 1234 temperature 19.8 Streams are an append-only data structure. ![]() See each command's time complexity for the details. Simply put, Redis streams provide highly efficient inserts and reads. Since stream IDs are typically short and of a fixed length, this effectively reduces to a constant time lookup.įor details on why, note that streams are implemented as radix trees. > XREAD COUNT 100 BLOCK 300 STREAMS temperatures:us-ny:10007 $Īccessing any single entry is O(n), where n is the length of the ID.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |