@@ -158,6 +158,13 @@ fn spin_http_module(_py: Python<'_>, module: &PyModule) -> PyResult<()> {
158158 module. add_class :: < HttpResponse > ( )
159159}
160160
161+ #[ pyo3:: pyfunction]
162+ fn redis_del ( address : String , keys : Vec < String > ) -> PyResult < i64 > {
163+ let keys = keys. iter ( ) . map ( |s| s. as_str ( ) ) . collect :: < Vec < _ > > ( ) ;
164+ redis:: del ( & address, & keys)
165+ . map_err ( |_| PyErr :: from ( Anyhow ( anyhow ! ( "Error executing Redis set command" ) ) ) )
166+ }
167+
161168#[ pyo3:: pyfunction]
162169#[ pyo3( pass_module) ]
163170fn redis_get ( module : & PyModule , address : String , key : String ) -> PyResult < Py < PyBytes > > {
@@ -168,17 +175,56 @@ fn redis_get(module: &PyModule, address: String, key: String) -> PyResult<Py<PyB
168175 )
169176}
170177
178+ #[ pyo3:: pyfunction]
179+ fn redis_incr ( address : String , key : String ) -> PyResult < i64 > {
180+ redis:: incr ( & address, & key)
181+ . map_err ( |_| PyErr :: from ( Anyhow ( anyhow ! ( "Error executing Redis incr command" ) ) ) )
182+ }
183+
184+ #[ pyo3:: pyfunction]
185+ fn redis_publish ( address : String , channel : String , payload : & PyBytes ) -> PyResult < ( ) > {
186+ redis:: publish ( & address, & channel, payload. as_bytes ( ) )
187+ . map_err ( |_| PyErr :: from ( Anyhow ( anyhow ! ( "Error executing Redis publish command" ) ) ) )
188+ }
189+
190+ #[ pyo3:: pyfunction]
191+ fn redis_sadd ( address : String , key : String , values : Vec < String > ) -> PyResult < i64 > {
192+ let values = values. iter ( ) . map ( |s| s. as_str ( ) ) . collect :: < Vec < _ > > ( ) ;
193+ redis:: sadd ( & address, & key, & values)
194+ . map_err ( |_| PyErr :: from ( Anyhow ( anyhow ! ( "Error executing Redis set command" ) ) ) )
195+ }
196+
171197#[ pyo3:: pyfunction]
172198fn redis_set ( address : String , key : String , value : & PyBytes ) -> PyResult < ( ) > {
173199 redis:: set ( & address, & key, value. as_bytes ( ) )
174200 . map_err ( |_| PyErr :: from ( Anyhow ( anyhow ! ( "Error executing Redis set command" ) ) ) )
175201}
176202
203+ #[ pyo3:: pyfunction]
204+ fn redis_smembers ( address : String , key : String ) -> PyResult < Vec < String > > {
205+ redis:: smembers ( & address, & key)
206+ . map_err ( |_| PyErr :: from ( Anyhow ( anyhow ! ( "Error executing Redis set command" ) ) ) )
207+ }
208+
209+ #[ pyo3:: pyfunction]
210+ fn redis_srem ( address : String , key : String , values : Vec < String > ) -> PyResult < i64 > {
211+ let values = values. iter ( ) . map ( |s| s. as_str ( ) ) . collect :: < Vec < _ > > ( ) ;
212+ redis:: srem ( & address, & key, & values)
213+ . map_err ( |_| PyErr :: from ( Anyhow ( anyhow ! ( "Error executing Redis set command" ) ) ) )
214+ }
215+
177216#[ pyo3:: pymodule]
178217#[ pyo3( name = "spin_redis" ) ]
179218fn spin_redis_module ( _py : Python < ' _ > , module : & PyModule ) -> PyResult < ( ) > {
219+ module. add_function ( pyo3:: wrap_pyfunction!( redis_del, module) ?) ?;
180220 module. add_function ( pyo3:: wrap_pyfunction!( redis_get, module) ?) ?;
181- module. add_function ( pyo3:: wrap_pyfunction!( redis_set, module) ?)
221+ module. add_function ( pyo3:: wrap_pyfunction!( redis_incr, module) ?) ?;
222+ module. add_function ( pyo3:: wrap_pyfunction!( redis_publish, module) ?) ?;
223+ module. add_function ( pyo3:: wrap_pyfunction!( redis_sadd, module) ?) ?;
224+ module. add_function ( pyo3:: wrap_pyfunction!( redis_set, module) ?) ?;
225+ module. add_function ( pyo3:: wrap_pyfunction!( redis_smembers, module) ?) ?;
226+ module. add_function ( pyo3:: wrap_pyfunction!( redis_srem, module) ?)
227+
182228}
183229
184230#[ pyo3:: pyfunction]
0 commit comments