You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Can not distinguish between "does not exist" and "has no value" #726
I wrote the pwned passwords into a bucket. Because I only need to know if the hash exists, I wrote an empty value into the bucket.
err := hashes.Put(hash, []byte{})
Now I tried to find a hash, but I had to realize that Go does not distinguish between an empty array and nil. The problem is: Bolt returns nil to indicate that a key does not exist. This is a problem because of Go's limitation.
How to store keys without values in order to check just for existence?
I think Bucket.Get needs to return an additional boolean or Bucket needs an additional function to check just for existence.
Go itself also indicates the existence of a key in a map by an additional boolean:
Activity
Elbehery commentedon Apr 17, 2024
@ceving
Getreturnsnilif the key does not exist, or the value is a nested bucketthis could be a feature cc @ahrtr @fuweid @tjungblu @ivanvc
ahrtr commentedon Apr 17, 2024
For the case of "does not exist",
bucket.Getreturnsnil.For the case "has no value",
bucket.Getreturns[]byte{}, which is obviously notnil.The only known minor problem is that even you write a
nilvalue for a key, when you read it back in a separate transaction, it still returns[]byte{}.ahrtr commentedon Apr 17, 2024
For example,
ahrtr commentedon Apr 17, 2024
In short, no matter what value you write into bbolt, when you read it back, you will always get
[]byte{}as long aslen(value) == 0istrue.The only exception is that when you write a
nilvalue, and you will still get anilvalue when you read it back in the same transaction.Will raise a PR to add a known issue.
ahrtr commentedon Apr 18, 2024
Completed in #730