https://discord.cloudflare.com logo
Join Discord
Powered by
# kv
  • j

    jessec

    05/24/2023, 3:59 PM
    Anyone know a method to clear out all keys in a namespace using the api without listing them and looping or using bulk delete or delete/recreating the namespace?
  • j

    jessec

    05/24/2023, 4:01 PM
    Hmm, maybe I can just put a month long expiration on everything instead so old/unused keys just fall out automatically.
  • v

    Vitali

    05/24/2023, 4:29 PM
    That's currently the best mechanism if that works for you.
  • a

    albert

    05/24/2023, 5:14 PM
    Beware expiration is from when you write. It does not refresh on read. So a key can be read a lot and still expire once the TTL is over.
  • j

    jessec

    05/24/2023, 5:58 PM
    Yeah, the idea was to run my updates once a month, but I just ended up writing the code to remove the old keys instead. Probably better I don't end up where I forget to run it, go on vacation and then all the keys go poof. Ha!
  • t

    TheDevMinerTV

    05/25/2023, 6:48 AM
    Small bug report: the name of a KV namespace on the website uses default input styling
  • a

    albert

    05/25/2023, 9:27 AM
    Could you please share a screenshot of what you mean by this?
  • t

    TheDevMinerTV

    05/25/2023, 9:32 AM
    (yes, that input field is not censored, that's just the way it is)

    https://cdn.discordapp.com/attachments/874727019479437372/1111225161530748968/Screenshot_2023-05-25_at_11.30.12.png▾

  • v

    Vitali

    05/25/2023, 2:07 PM
    Are you saying because it's got a black background in the dark theme? Or because it's non-obvious that it's editable?
  • t

    TheDevMinerTV

    05/25/2023, 2:55 PM
    it's style doesn't fit the rest of the page
  • t

    TheDevMinerTV

    05/25/2023, 2:56 PM
    it literally just is an
    <input>
    with
    background-color: #000
  • t

    TheDevMinerTV

    05/25/2023, 2:57 PM
    IMO, that
    Namespace Name
    field should look like the input for
    Key
  • b

    b-fuze (Mike32)

    05/27/2023, 2:56 AM
    Is there a way to list keys from KV in reverse?
  • b

    b-fuze (Mike32)

    05/27/2023, 2:57 AM
    As far as I understand it, KV orders keys in ascending order lexicographically righ?
  • b

    b-fuze (Mike32)

    05/27/2023, 2:57 AM
    Is there a way to get the "top 10" keys or something?
  • d

    DigiRare_NFTs

    05/27/2023, 4:07 AM
    you familiar with postma?
  • d

    DigiRare_NFTs

    05/27/2023, 4:07 AM
    postman*
  • d

    DigiRare_NFTs

    05/27/2023, 4:07 AM
    id check documentation there if anything /shrug
  • u

    Unsmart | Tech debt

    05/27/2023, 4:30 AM
    Not currently sadly
  • b

    b-fuze (Mike32)

    05/27/2023, 4:31 AM
    Ah, okay. I'll have to store my keys in reverse then
  • u

    Unsmart | Tech debt

    05/27/2023, 4:31 AM
    #773219443911819284 do support reverse sort and you could add cache api on top of DOs which would make it somewhat close to KV
  • b

    b-fuze (Mike32)

    05/27/2023, 4:31 AM
    Thanks
  • b

    b-fuze (Mike32)

    05/27/2023, 4:49 PM
    So I have a problem, I write data to KV (via a CF worker), then in another request (to a CF worker) I
    list
    keys then run
    get
    on those keys. My problem is that
    get
    returns
    null
    if I
    get
    those keys too quickly (after the write request)... What is the proper solution here? I'm thinking of writing a
    while
    loop that keeps `get`ing those keys until KV returns something other than
    null
    ?
  • j

    James

    05/27/2023, 5:47 PM
    This is really by design with the way that KV's eventual consistency model works: https://developers.cloudflare.com/workers/learning/how-kv-works/
  • j

    James

    05/27/2023, 5:48 PM
    You could do a
    while
    loop, but it really sounds like you want more durable storage, so something like Durable Objects would likely be better suited: https://developers.cloudflare.com/workers/learning/using-durable-objects/
  • b

    b-fuze (Mike32)

    05/27/2023, 6:17 PM
    Thanks!
  • u

    Unsmart | Tech debt

    05/27/2023, 7:35 PM
    That is interesting that the list shows it though on first get it shouldn’t be cached. Unless you tried to do a get before the list then get 🤔
  • b

    b-fuze (Mike32)

    05/27/2023, 10:16 PM
    Yeah, Idk what's going on
  • b

    b-fuze (Mike32)

    05/27/2023, 10:17 PM
    What I've decided to do was store the creation date in the key metadata, and wait 60 seconds after it's created (if I'm trying to get the value before that time)
  • b

    b-fuze (Mike32)

    05/27/2023, 10:18 PM
    I tried using lower values like 30 seconds, etc, but I was still getting nulls. It seems like 60 seconds is how long I should wait before I can confidently not get a null value