Skip to content

Commit

Permalink
Improve SET
Browse files Browse the repository at this point in the history
  • Loading branch information
aamalev committed Nov 30, 2023
1 parent 255b5b4 commit 952a541
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
17 changes: 16 additions & 1 deletion redis_rs/client_async.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,22 @@ class AsyncClient:
async def eval(
self, script: str, numkeys: int, *keys_and_args: Arg, encoding: Optional[Encoding] = None
) -> Result: ...
async def set(self, key: str, value: Arg) -> Result: ...
@overload
async def set(
self,
key: str,
value: Arg,
ex: Optional[int] = None,
encoding: Optional[Encoding] = None,
) -> Result: ...
@overload
async def set(
self,
key: str,
value: Arg,
px: Optional[int] = None,
encoding: Optional[Encoding] = None,
) -> Result: ...
async def get(self, key: str, *, encoding: Optional[Encoding] = None) -> Result: ...
@overload
async def hset(self, key: str, field: str, value: Arg, *pairs) -> int: ...
Expand Down
31 changes: 27 additions & 4 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,33 @@ impl Client {
self.cr.execute(py, cmd, encoding)
}

#[pyo3(signature = (key, value))]
fn set<'a>(&self, py: Python<'a>, key: types::Str, value: types::Arg) -> PyResult<&'a PyAny> {
let cmd = redis::cmd("SET").arg(key).arg(value).to_owned();
self.cr.execute(py, cmd, types::Codec::default())
#[pyo3(signature = (
key,
value,
ex = None,
px = None,
**kwargs,
))]
fn set<'a>(
&self,
py: Python<'a>,
key: types::Str,
value: types::Arg,
ex: Option<usize>,
px: Option<usize>,
kwargs: Option<&PyDict>,
) -> PyResult<&'a PyAny> {
let mut cmd = redis::cmd("SET").arg(key).arg(value).to_owned();
if let Some(ex) = ex {
cmd.arg(b"EX");
cmd.arg(ex);
}
if let Some(px) = px {
cmd.arg(b"PX");
cmd.arg(px);
}
let encoding = types::Codec::from(kwargs);
self.cr.execute(py, cmd, encoding)
}

#[pyo3(signature = (key, **kwargs))]
Expand Down

0 comments on commit 952a541

Please sign in to comment.