Using Amazon Q Developer to update Valkey client code

Using Amazon Q Developer to update Valkey client code

How I used Amazon Q Developer to create sample code in Python using the new Valkey GLIDE client

Ricardo Sueiras
Amazon Employee
Published Jul 19, 2024
Today is the last day of WeAreDevelopers in Berlin. I have been speaking with developers over the past two days about Valkey, and as part of that I wanted to put together some demos to show. Yesterday I shared a post about how you can use Valkey with Finch (Getting started with Valkey and Finch), but today I wanted to share how I used Amazon Q Developer to help me put together some demo code that demonstrated how Valkey works.
Amazon Q Developer helped me put together some simple demo applications that I have been demonstrating, that shows how Valkey works with existing as well as the new Valkey Python libraries, and how it is business as usual for developers as they transition to Valkey.
This is all good, but recently I read about a new Valkey client library, called GLIDE (Introducing Valkey GLIDE, an open source client library for Valkey and Redis open source). I wanted to test this out using my simple demo application, so I thought I would get Amazon Q Developer to help me out, using the recently launched new capability that allows it to read the files in my local workspace to provide additional context.
The first thing I did was to clone the valkey glide client into the current workspace
git cloned https://github.com/valkey-io/valkey-glide/blob/main/python/README.md
I then cleaned it up a bit to remove all the non python stuff I was not interested in, which left me with
└── valkey-glide
├── examples
│ └── python
│ ├── README.md
│ ├── cluster_example.py
│ ├── requirements.txt
│ └── standalone_example.py
└── python
├── python
│ ├── glide
│ │ ├── __init__.py
│ │ ├── async_commands
│ │ │ ├── __init__.py
│ │ │ ├── bitmap.py
│ │ │ ├── cluster_commands.py
│ │ │ ├── command_args.py
│ │ │ ├── core.py
│ │ │ ├── server_modules
│ │ │ │ └── json.py
│ │ │ ├── sorted_set.py
│ │ │ ├── standalone_commands.py
│ │ │ ├── stream.py
│ │ │ └── transaction.py
│ │ ├── config.py
│ │ ├── constants.py
│ │ ├── exceptions.py
│ │ ├── glide.pyi
│ │ ├── glide_client.py
│ │ ├── logger.py
│ │ ├── protobuf_codec.py
│ │ ├── py.typed
│ │ └── routes.py
│ └── tests
│ ├── __init__.py
│ ├── conftest.py
│ ├── test_async_client.py
│ ├── test_config.py
│ ├── test_proto_coded.py
│ ├── test_pubsub.py
│ ├── test_scan.py
│ ├── test_transaction.py
│ ├── test_utils.py
│ ├── tests_server_modules
│ │ └── test_json.py
│ └── utils
│ ├── cluster.py
│ └── utils.py
I then went into the Amazon Q Developer settings, and enabled the Amazon Q Developer workspace settings
Screenshot of workspace enabled
Which I could then confirm was working by checking out the logs (Output > Amazon Q Language Server).
I then used the following prompt
Amazon Q Developer "@workspace using the existing demo-app-with-valkey-library.py file, can you update this to use the Glide library, using the example in standalone_example.py. It will be accessing a Valkey server at 127.0.0.1."
and it then provided the following code
We can now run the application, but it does not load and generates this error.
RuntimeError: There is no current event loop in thread 'Thread-2 (process_request_thread)'.
You know what I am about to say right....yup, back to Amazon Q Developer.
Amazon Q Developer "The code generates this error - "this errors with RuntimeError: There is no current event loop in thread 'Thread-2 (processrequestthread)'." Can you provide suggested code changes on how to fix"
It provides some details around the error and then provides updated code
When I access this via a browser, it now loads but when I try and add a new message it generates a new error.
TypeError: can only concatenate list (not "str") to list
I try using Amazon Q Developer to help me fix this problem, but this time it doesn't really help. This was the prompt I used
Amazon Q Developer "@workspace I am having issues with using rpush from the valkey-glide/python directory. It is generating an error when using rpush. Can you confirm that the code in demo-app-with-glide.py is using rpush correctly"
And whilst the output is helpful, the suggestions this time do not work.
I check the code, and it looks like rpush needs to have the format ("my_list", ["value2", "value3"]), and so I update the line
await glide_client.rpush('messages', message)
to be
await glide_client.rpush('messages', [message])
The code now runs, and we now have our simple demo app using the new Glide client. You can find all the code I (ok, Amazon Q Developer) created in the support GitHub repo
screenshot of the demo app
In this quick post, I wanted to share how I am using Amazon Q Developer together with the new capabilities that allow it to understand files in the local workspace. Amazon Q Developer was able to help me update code with new code that the underlying language models would not have known about. Whilst it is not always perfect, it is safe to say that it generated most of the code for me, helped me fix some of the problems, but then left it me to earn my keep!
How are you going to use Amazon Q Developer?
 

Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.

Comments