Skip to content

Conversation

@gautamomento
Copy link
Contributor

@gautamomento gautamomento commented Nov 2, 2021

import momento.momento as momento

if __name__ == "__main__":
    with momento.init('<AUTH_TOKEN>') as momento_client:
        with momento_client.get_cache("dummy", ttl_seconds=60, create_if_absent=True) as cache_client:
            resp = cache_client.set('MyKey', 'MyData')
            get_resp = cache_client.get('MyKey')
            print(get_resp.result())
            print(get_resp.str_utf8())

@gautamomento gautamomento marked this pull request as draft November 2, 2021 04:35
@gautamomento gautamomento marked this pull request as ready for review November 4, 2021 16:25
def __enter__(self):
return self

def __exit__(self, exc_type, exc_value, exc_traceback):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we also want to close the client too? Or does this take care of that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stub doesn't have a close. As per examples and documentation, the channel needs to be closed:
https://github.com/grpc/grpc/blob/v1.41.0/examples/python/helloworld/greeter_client.py#L29

from . import _cache_service_errors_converter as error_converter


class CacheResult(Enum):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this, only Get needs a result

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we are over the SDK spikes, I would like to go cleanup other SDKs as well and potentially remove these results from MR2 responses as well.

return self

def __exit__(self, exc_type, exc_value, exc_traceback):
self._secure_channel.close()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here do we also want to close the client?

Copy link
Contributor

@bruuuuuuuce bruuuuuuuce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few minor comments, but otherwise lgtm as a first pass

@gautamomento gautamomento merged commit 39bbe5b into main Nov 4, 2021
@gautamomento gautamomento deleted the u/gautamomento/create-cache branch November 4, 2021 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants