Add example scripts for common Redis operations#4032
Add example scripts for common Redis operations#4032yosofbadr wants to merge 2 commits intoredis:masterfrom
Conversation
Add an examples/ directory with three self-contained scripts covering the most common redis-py usage patterns: - string_operations.py: SET/GET, MSET/MGET, atomic counters, key expiry - hash_operations.py: HSET/HGET/HGETALL, HMGET, HINCRBY, field inspection - pubsub.py: SUBSCRIBE, PSUBSCRIBE, PUBLISH with a threaded demo Closes redis#1744
|
Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset. In case there are security findings, they will be communicated to you as a comment inside the PR. Hope you’ll enjoy using Jit. Questions? Comments? Want to learn more? Get in touch with us. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 08846a0. Configure here.
|
Hi @yosofbadr, thank you for your contribution! In redis-py, examples are stored under docs/examples as Jupyter notebooks and are then referenced in the Read the Docs documentation. Could you please update the examples you added to follow this existing pattern? |

Summary
examples/directory with self-contained, well-commented scripts demonstrating common redis-py usage patternsstring_operations.py-- SET/GET, MSET/MGET, atomic counters (INCR/DECR), key expiration with EX/NX/XX flagshash_operations.py-- HSET/HGET/HGETALL, HMGET, HINCRBY, HEXISTS/HKEYS/HVALS/HDELpubsub.py-- SUBSCRIBE, PSUBSCRIBE (pattern-based), PUBLISH with a threaded demo that runs subscriber and publisher in one processEach script includes a docstring with prerequisites (pip install, Docker command to start Redis), cleans up after itself, and can be run standalone.
Closes #1744
Test plan
Note
Low Risk
Only adds new example scripts and does not modify library/runtime code; risk is limited to developer documentation/usage expectations.
Overview
Adds a new
examples/directory with three standaloneredis-pyscripts demonstrating core Redis usage: basic string commands and TTLs (string_operations.py), hash CRUD and atomic increments (hash_operations.py), and a threaded pub/sub end-to-end demo with clean shutdown (pubsub.py).Each script includes prerequisite/run instructions, uses
decode_responses=Truefor readable output, and cleans up any keys/subscriptions it creates.Reviewed by Cursor Bugbot for commit baa52e5. Bugbot is set up for automated code reviews on this repo. Configure here.