Skip to main content

Module sharded

Module sharded 

Source
Expand description

Ketama-sharded client for ringline-memcache.

Routes commands to independent Memcache instances using consistent hashing (ketama). Each server has a pool of connections with round-robin dispatch and lazy reconnection.

§Example

use ringline_memcache::{ShardedClient, ShardedConfig};

async fn example() -> Result<(), ringline_memcache::Error> {
    let config = ShardedConfig {
        servers: vec![
            "127.0.0.1:11211".parse().unwrap(),
            "127.0.0.1:11212".parse().unwrap(),
        ],
        pool_size: 2,
        connect_timeout_ms: 1000,
        tls_server_name: None,
    };
    let mut sharded = ShardedClient::new(config);
    sharded.connect_all().await?;
    sharded.set("hello", "world").await?;
    let val = sharded.get("hello").await?;
    assert_eq!(val.unwrap().data.as_ref(), b"world");
    sharded.close_all();
    Ok(())
}

Structs§

ShardedClient
A ketama-sharded Memcache client.
ShardedConfig
Configuration for a ketama-sharded client.