Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

currecting signature SELECT command #303

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
currecting signature SELECT command
  • Loading branch information
ArtemIsmagilov committed Oct 20, 2024
commit 3e80f9eb1b45a9e0ff4c03a5adc013ce29b53a99
5 changes: 2 additions & 3 deletions src/commands/impls/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,8 @@ pub async fn ping<C: ClientLike>(client: &C) -> Result<RedisValue, RedisError> {
protocol_utils::frame_to_results(frame)
}

pub async fn select<C: ClientLike>(client: &C, db: u8) -> Result<RedisValue, RedisError> {
let frame = utils::request_response(client, || Ok((RedisCommandKind::Select, vec![db.into()]))).await?;
protocol_utils::frame_to_results(frame)
pub async fn select<C: ClientLike>(client: &C, index: RedisValue) -> Result<RedisValue, RedisError> {
one_arg_value_cmd(client, RedisCommandKind::Select, index).await
}

pub async fn info<C: ClientLike>(client: &C, section: Option<InfoKind>) -> Result<RedisValue, RedisError> {
Expand Down
13 changes: 10 additions & 3 deletions src/commands/interfaces/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
commands,
error::RedisError,
interfaces::{ClientLike, RedisResult},
types::{FromRedis, Server},
types::{FromRedis, RedisValue, Server},
};
use fred_macros::rm_send_if;
use futures::Future;
Expand Down Expand Up @@ -43,8 +43,15 @@ pub trait ServerInterface: ClientLike {
/// Select the database this client should use.
///
/// <https://redis.io/commands/select>
fn select(&self, db: u8) -> impl Future<Output = RedisResult<()>> + Send {
async move { commands::server::select(self, db).await?.convert() }
fn select<I>(&self, index: I) -> impl Future<Output = RedisResult<()>> + Send
where
I: TryInto<RedisValue> + Send,
I::Error: Into<RedisError> + Send,
{
async move {
try_into!(index);
commands::server::select(self, index).await?.convert()
}
}

/// This command will start a coordinated failover between the currently-connected-to master and one of its
Expand Down
1 change: 1 addition & 0 deletions tests/integration/centralized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ mod server {
centralized_test!(server, should_read_db_size);
centralized_test!(server, should_start_bgsave);
centralized_test!(server, should_do_bgrewriteaof);
centralized_test!(server, should_select_index_command);
}

#[cfg(feature = "i-sets")]
Expand Down
5 changes: 5 additions & 0 deletions tests/integration/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,8 @@ pub async fn should_do_bgrewriteaof(client: RedisClient, _: RedisConfig) -> Resu
sleep(Duration::from_millis(1000)).await;
Ok(())
}

pub async fn should_select_index_command(client: RedisClient, _: RedisConfig) -> Result<(), RedisError> {
assert_eq!(client.select(0).await, Ok(()));
Ok(())
}