how key-value pairs having same key are stored in multichain stream?

+15 votes
when we publish data using same key value, separate transactions are created for every publish.

$ multichain-cli str liststreamitems s1
{"method":"liststreamitems","params":["s1"],"id":"54837938-1702194153","chain_name":"str"}

[
    {
        "publishers" : [
            "1UcZCK8r2SGfevz1xDWdFLe49FsCqHyrFtowzH"
        ],
        "key" : "k1",
        "data" : "11",
        "confirmations" : 13,
        "blocktime" : 1702188538,
        "txid" : "ec4042b12624b463bec52747b0de7ae88a4723cc8a602546f0ecf8e946133a78"
    },
    {
        "publishers" : [
            "1UcZCK8r2SGfevz1xDWdFLe49FsCqHyrFtowzH"
        ],
        "key" : "k1",
        "data" : "11",
        "confirmations" : 12,
        "blocktime" : 1702188543,
        "txid" : "0f7f0f414c43b323e7581d4037f60e0ceb294a2732c0bb04f58e26e9e5c38f90"
    },
    {
        "publishers" : [
            "1UcZCK8r2SGfevz1xDWdFLe49FsCqHyrFtowzH"
        ],
        "key" : "k1",
        "data" : "12",
        "confirmations" : 11,
        "blocktime" : 1702188563,
        "txid" : "1d84ed95425e4a84c938ab0d342f3fe87b20c835e3e758c02479071e8b819f7b"
    }
]
anju@DESKTOP-FFAFKFO:~$ multichain-cli str liststreamkeys s1
{"method":"liststreamkeys","params":["s1"],"id":"79880957-1702194238","chain_name":"str"}

[
    {
        "key" : "k1",
        "items" : 3,
        "confirmed" : 3
    }
]

does that mean- when we publish different copies of same key are created for every data item published , since blockchain is a append-only structure.

and when we list streamkeys, it only list unique keys with no. of items it is mapped. But in memory, multiple copies of same key value exist in different transactions.  thus avoiding unnecessary repeated key valued being loaded since data items are not required now.
asked Dec 10, 2023 by anju

1 Answer

0 votes
Yes, blockchains are an append-only data structure, so you can have multiple items with the same key. And all MultiChain APIs are designed around this fact.

The stream items are not all in memory, they're stored and indexed on disk.
answered Dec 10, 2023 by MultiChain
so on disk multiple copies of same key exist for every item, but in memory only unique values are available when "liststreamkeys " is used
The difference is not related to memory or disk. The liststreamkeys API lists all the different keys used in the stream.
...