Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zonyitoo/memcached-rs
Memcached library in Rust
https://github.com/zonyitoo/memcached-rs
Last synced: 5 days ago
JSON representation
Memcached library in Rust
- Host: GitHub
- URL: https://github.com/zonyitoo/memcached-rs
- Owner: zonyitoo
- License: mit
- Created: 2014-11-04T02:48:38.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2023-08-29T10:01:07.000Z (over 1 year ago)
- Last Synced: 2024-12-09T14:50:03.279Z (14 days ago)
- Language: Rust
- Size: 225 KB
- Stars: 26
- Watchers: 6
- Forks: 20
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# memcached-rs
[![Build & Test](https://github.com/zonyitoo/memcached-rs/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/zonyitoo/memcached-rs/actions/workflows/build-and-test.yml)
[![crates.io](https://img.shields.io/crates/v/memcached-rs.svg)](https://crates.io/crates/memcached-rs)
[![dependency status](https://deps.rs/repo/github/zonyitoo/memcached-rs/status.svg)](https://deps.rs/repo/github/zonyitoo/memcached-rs)Memcached library in Rust
## Usage
```rust
use std::collections::TreeMap;use memcached::Client;
use memcached::proto::{Operation, MultiOperation, NoReplyOperation, CasOperation, ProtoType};fn main() {
let servers = [
("tcp://127.0.0.1:11211", 1),
];
let mut client = Client::connect(&servers, ProtoType::Binary).unwrap();client.set(b"Foo", b"Bar", 0xdeadbeef, 2).unwrap();
let (value, flags) = client.get(b"Foo").unwrap();
assert_eq!(value.as_slice(), b"Bar");
assert_eq!(flags, 0xdeadbeef);client.set_noreply(b"key:dontreply", b"1", 0x00000001, 20).unwrap();
let (_, cas_val) = client.increment_cas(b"key:numerical", 10, 1, 20, 0).unwrap();
client.increment_cas(b"key:numerical", 1, 1, 20, cas_val).unwrap();
}
```Run `cargo doc --open` for more details.
### SASL authentication
TCP connections support `PLAIN` SASL authentication:
```rust
use memcached::proto::{Operation, ProtoType};
use memcached::Client;fn main() {
let servers = [
("tcp://my-sasl-memcached-server.com:11211", 1)
];
let mut client = Client::connect_sasl(&servers, ProtoType::Binary, "my-username", "my-password").unwrap();client.set(b"Foo", b"Bar", 0xdeadbeef, 2).unwrap();
let (value, flags) = client.get(b"Foo").unwrap();
assert_eq!(&value[..], b"Bar");
assert_eq!(flags, 0xdeadbeef);
}
```## TODO
* Auto-disable failed servers
## License
Licensed under either of
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)at your option.
### Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.