0

When using Basho's Python client, getting a value for a key consists of two operations:

  • getting a bucket
  • getting a value from a bucket

Like this:

bucket = client.bucket(bucket_name)
value = bucket.get(key)

I occasionally get None back for the very same bucket. That seems nonsensical because the bucket is clearly there (I checked manually all the nodes client is created with). So the question is, can/should I cache/locally store the bucket object?

Schultz9999
  • 8,717
  • 8
  • 48
  • 87
  • Hello, I am a maintainer of the Riak Python client. I don't really follow your use of the client via your description. If you believe you have found a bug, or would like further assistance, please open an issue [in the GitHub repository.](https://github.com/basho/riak-python-client) – Luke Bakken Jan 29 '16 at 16:50
  • @Luke Hi Luke! Thank you for dropping by. I hope there is no bug. What we see is that every now and then, `client.bucket(bucket_name)` returns `None` while the bucket is clearly there on every one (I checked manually). So the supposition is that asking Riak for a bucket often enough does something that result `None` returned. I played with caching a bucket for 10 seconds and it appears mitigates the problem. I would love to understand better though why this happens. – Schultz9999 Jan 29 '16 at 19:15
  • Please direct this conversation to [this GitHub issue](https://github.com/basho/riak-python-client/issues/428). Thank you. It is much easier for me to request information and code snippets from you there than it is here. At this time I don't know why you're seeing what you're seeing. – Luke Bakken Jan 30 '16 at 00:08

1 Answers1

0

I'm not an expert with the python client, but as far as I understand, you should keep your client.bucket instance around and use it multiple time to perform operations on it. However, I wouldn't cache it, if by caching you mean serialize it to disk or store it in a shared memory cache. Actually I would also avoid sharing it accross multiple threads. And definitely not across different processes.

Getting a bucket instance is cheap enough that you can create it quite often. However it's best practice to keep it and issue multiple operations on it in tight loops or while you haven't finished the current work.

If you use some connection pools, make sure you recreate your bucket instances when you reconnect.

Hope that helps. If not, give us more details, maybe show us some code :)

dams
  • 399
  • 1
  • 5