Skip to content

Commit

Permalink
Make get return Bytes instead of Vec<u8>
Browse files Browse the repository at this point in the history
  • Loading branch information
Bajix committed Mar 24, 2024
1 parent 3d26481 commit e3521cd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions crates/redis-swapplex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ rust-version = "1.75"

[dependencies]
arc-swap = "1.7"
bytes = "1.5.0"
derive-redis-swapplex = { version = "0.10.0", path = "../derive-redis-swapplex" }
env-url = "2"
futures-util = "0.3"
Expand Down
9 changes: 5 additions & 4 deletions crates/redis-swapplex/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ extern crate self as redis_swapplex;

mod bytes;

pub use bytes::IntoBytes;
pub use crate::bytes::IntoBytes;
pub use ::bytes::Bytes;

use arc_swap::{ArcSwapAny, ArcSwapOption, Cache};
pub use derive_redis_swapplex::ConnectionManagerContext;
Expand Down Expand Up @@ -522,13 +523,13 @@ where
}

/// Get the value of a key using auto-batched MGET commands
pub async fn get<K: IntoBytes>(key: K) -> Result<Option<Vec<u8>>, ErrorKind> {
pub async fn get<K: IntoBytes>(key: K) -> Result<Option<Bytes>, ErrorKind> {
struct MGetQueue;

#[local_queue(buffer_size = 2048)]
impl TaskQueue for MGetQueue {
type Task = Vec<u8>;
type Value = Result<Option<Vec<u8>>, ErrorKind>;
type Value = Result<Option<Bytes>, ErrorKind>;

async fn batch_process<const N: usize>(
batch: PendingAssignment<'_, Self, N>,
Expand All @@ -537,7 +538,7 @@ pub async fn get<K: IntoBytes>(key: K) -> Result<Option<Vec<u8>>, ErrorKind> {
let assignment = batch.into_assignment();
let (front, back) = assignment.as_slices();

let data: Result<Vec<Option<Vec<u8>>>, RedisError> = redis::cmd("MGET")
let data: Result<Vec<Option<Bytes>>, RedisError> = redis::cmd("MGET")
.arg(front)
.arg(back)
.query_async(&mut conn)
Expand Down

0 comments on commit e3521cd

Please sign in to comment.