@@ -89,6 +89,162 @@ def redis_keys(pattern):
8989 return jsonify ({"error" : str (e )}), 500
9090
9191
92+ @app .route ("/test/mget-mset" , methods = ["GET" ])
93+ def test_mget_mset ():
94+ """Test MGET/MSET - multiple key operations."""
95+ try :
96+ # MSET multiple keys
97+ redis_client .mset ({"test:mset:key1" : "value1" , "test:mset:key2" : "value2" , "test:mset:key3" : "value3" })
98+ # MGET multiple keys
99+ result = redis_client .mget (["test:mset:key1" , "test:mset:key2" , "test:mset:key3" , "test:mset:nonexistent" ])
100+ # Clean up
101+ redis_client .delete ("test:mset:key1" , "test:mset:key2" , "test:mset:key3" )
102+ return jsonify ({"success" : True , "result" : result })
103+ except Exception as e :
104+ return jsonify ({"error" : str (e )}), 500
105+
106+
107+ @app .route ("/test/pipeline-basic" , methods = ["GET" ])
108+ def test_pipeline_basic ():
109+ """Test basic pipeline operations."""
110+ try :
111+ pipe = redis_client .pipeline ()
112+ pipe .set ("test:pipe:key1" , "value1" )
113+ pipe .set ("test:pipe:key2" , "value2" )
114+ pipe .get ("test:pipe:key1" )
115+ pipe .get ("test:pipe:key2" )
116+ results = pipe .execute ()
117+ # Clean up
118+ redis_client .delete ("test:pipe:key1" , "test:pipe:key2" )
119+ return jsonify ({"success" : True , "results" : results })
120+ except Exception as e :
121+ return jsonify ({"error" : str (e )}), 500
122+
123+
124+ @app .route ("/test/pipeline-no-transaction" , methods = ["GET" ])
125+ def test_pipeline_no_transaction ():
126+ """Test pipeline with transaction=False."""
127+ try :
128+ pipe = redis_client .pipeline (transaction = False )
129+ pipe .set ("test:pipe:notx:key1" , "value1" )
130+ pipe .incr ("test:pipe:notx:counter" )
131+ pipe .get ("test:pipe:notx:key1" )
132+ results = pipe .execute ()
133+ # Clean up
134+ redis_client .delete ("test:pipe:notx:key1" , "test:pipe:notx:counter" )
135+ return jsonify ({"success" : True , "results" : results })
136+ except Exception as e :
137+ return jsonify ({"error" : str (e )}), 500
138+
139+
140+ @app .route ("/test/async-pipeline" , methods = ["GET" ])
141+ def test_async_pipeline ():
142+ """Test async pipeline operations using asyncio."""
143+ import asyncio
144+
145+ import redis .asyncio as aioredis
146+
147+ async def run_async_pipeline ():
148+ # Create async Redis client
149+ async_client = aioredis .Redis (
150+ host = os .getenv ("REDIS_HOST" , "redis" ),
151+ port = int (os .getenv ("REDIS_PORT" , "6379" )),
152+ db = 0 ,
153+ decode_responses = True ,
154+ )
155+
156+ try :
157+ # Create async pipeline
158+ pipe = async_client .pipeline ()
159+ pipe .set ("test:async:pipe:key1" , "async_value1" )
160+ pipe .set ("test:async:pipe:key2" , "async_value2" )
161+ pipe .get ("test:async:pipe:key1" )
162+ pipe .get ("test:async:pipe:key2" )
163+ results = await pipe .execute ()
164+
165+ # Clean up
166+ await async_client .delete ("test:async:pipe:key1" , "test:async:pipe:key2" )
167+
168+ return results
169+ finally :
170+ await async_client .aclose ()
171+
172+ try :
173+ results = asyncio .run (run_async_pipeline ())
174+ return jsonify ({"success" : True , "results" : results })
175+ except Exception as e :
176+ return jsonify ({"error" : str (e )}), 500
177+
178+
179+ @app .route ("/test/binary-data" , methods = ["GET" ])
180+ def test_binary_data ():
181+ """Test binary data that cannot be decoded as UTF-8."""
182+ try :
183+ # Create a Redis client without decode_responses for binary data
184+ binary_client = redis .Redis (
185+ host = os .getenv ("REDIS_HOST" , "redis" ),
186+ port = int (os .getenv ("REDIS_PORT" , "6379" )),
187+ db = 0 ,
188+ decode_responses = False ,
189+ )
190+
191+ # Binary data that cannot be decoded as UTF-8
192+ binary_value = bytes ([0x80 , 0x81 , 0x82 , 0xFF , 0xFE , 0xFD ])
193+
194+ # Set binary data
195+ binary_client .set ("test:binary:key" , binary_value )
196+
197+ # Get binary data back
198+ retrieved = binary_client .get ("test:binary:key" )
199+
200+ # Clean up
201+ binary_client .delete ("test:binary:key" )
202+
203+ return jsonify (
204+ {
205+ "success" : True ,
206+ "original_hex" : binary_value .hex (),
207+ "retrieved_hex" : retrieved .hex () if retrieved else None ,
208+ "match" : binary_value == retrieved ,
209+ }
210+ )
211+ except Exception as e :
212+ return jsonify ({"error" : str (e )}), 500
213+
214+
215+ @app .route ("/test/transaction-watch" , methods = ["GET" ])
216+ def test_transaction_watch ():
217+ """Test transaction with WATCH pattern.
218+
219+ This tests whether WATCH/MULTI/EXEC transaction pattern works correctly.
220+ """
221+ try :
222+ # Set initial value
223+ redis_client .set ("test:watch:counter" , "10" )
224+
225+ # Start a watched transaction
226+ pipe = redis_client .pipeline (transaction = True )
227+ pipe .watch ("test:watch:counter" )
228+
229+ # Get current value (this happens outside the transaction)
230+ current = int (redis_client .get ("test:watch:counter" ))
231+
232+ # Start the transaction
233+ pipe .multi ()
234+ pipe .set ("test:watch:counter" , str (current + 5 ))
235+ pipe .get ("test:watch:counter" )
236+
237+ # Execute
238+ results = pipe .execute ()
239+
240+ # Clean up
241+ redis_client .delete ("test:watch:counter" )
242+
243+ return jsonify ({"success" : True , "initial_value" : 10 , "expected_final" : 15 , "results" : results })
244+ except Exception as e :
245+ return jsonify ({"error" : str (e )}), 500
246+
247+
92248if __name__ == "__main__" :
93249 sdk .mark_app_as_ready ()
94250 app .run (host = "0.0.0.0" , port = 8000 , debug = False )
0 commit comments