Skip to content

Commit

Permalink
add example code BITCOUNT commands
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemIsmagilov committed Nov 22, 2024
1 parent e22443e commit 1b12f5c
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/commands/bitmap_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,42 @@ pub trait BitmapCommands<'a> {
/// # Return
/// The number of bits set to 1.
///
/// # Example
/// ```
/// # use rustis::{
/// # client::Client,
/// # commands::{BitRange, BitUnit},
/// # Result,
/// # };
/// # #[cfg_attr(feature = "tokio-runtime", tokio::test)]
/// # #[cfg_attr(feature = "async-std-runtime", async_std::test)]
/// # async fn bitcount() -> Result<()> {
/// # let client = get_test_client().await?;
/// client.set("mykey", "foobar").await?;
///
/// let count = client.bitcount("mykey", BitRange::default()).await?;
/// assert_eq!(26, count);
///
/// let count = client.bitcount("mykey", BitRange::range(0, 0)).await?;
/// assert_eq!(4, count);
///
/// let count = client.bitcount("mykey", BitRange::range(1, 1)).await?;
/// assert_eq!(6, count);
///
/// let count = client
/// .bitcount("mykey", BitRange::range(1, 1).unit(BitUnit::Byte))
/// .await?;
/// assert_eq!(6, count);
///
/// let count = client
/// .bitcount("mykey", BitRange::range(5, 30).unit(BitUnit::Bit))
/// .await?;
/// assert_eq!(17, count);
/// # client.close().await?;
///
/// # Ok(())
/// # }
///```
/// # See Also
/// [<https://redis.io/commands/bitcount/>](https://redis.io/commands/bitcount/)
#[must_use]
Expand Down

0 comments on commit 1b12f5c

Please sign in to comment.