shardmap 0.2.1

Sharded embedded in-memory map with optional cache, protocol, and server internals
Documentation
use bytes::BytesMut;

use crate::commands::redis::{define_redis_command, int, write_frame, wrong_arity};
use crate::protocol::Frame;
#[cfg(feature = "server")]
use crate::server::wire::ServerWire;
use crate::storage::EmbeddedStore;

define_redis_command!(Unlink, "UNLINK", true);

impl crate::commands::redis::RedisCommand for Unlink {
    fn execute(store: &EmbeddedStore, args: &[&[u8]]) -> Frame {
        if args.is_empty() {
            return wrong_arity("UNLINK");
        }
        int(args.iter().filter(|key| store.delete(key)).count() as i64)
    }

    #[cfg(feature = "server")]
    fn write_resp(store: &EmbeddedStore, args: &[&[u8]], out: &mut BytesMut) {
        if args.is_empty() {
            write_frame(out, &wrong_arity("UNLINK"));
            return;
        }
        ServerWire::write_resp_integer(
            out,
            args.iter().filter(|key| store.delete(key)).count() as i64,
        );
    }
}