Skip to content

Commit

Permalink
Merge pull request #11 from tompro/develop
Browse files Browse the repository at this point in the history
Imlement and expose async ts_alter
  • Loading branch information
tompro authored Dec 12, 2021
2 parents 59ccbcd + 1b1bf9b commit 3430c82
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "redis_ts"
version = "0.4.0"
version = "0.4.1"
authors = ["protom <[email protected]>"]
keywords = ["redis", "database"]
description = "API for Redis time series types."
Expand All @@ -13,7 +13,7 @@ edition = "2018"
exclude = ["docker"]

[dependencies]
redis = { version = "^0.20.0", optional = true }
redis = { version = "^0.21.0", optional = true }

[features]
default = ['redis']
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# redis_ts

[![crates.io](https://img.shields.io/badge/crates.io-v0.4.0-orange)](https://crates.io/crates/redis_ts)
[![crates.io](https://img.shields.io/badge/crates.io-v0.4.1-orange)](https://crates.io/crates/redis_ts)
![Continuous integration](https://github.com/tompro/redis_ts/workflows/Continuous%20integration/badge.svg)

redis_ts provides a small trait with extension functions for the
Expand All @@ -10,13 +10,13 @@ a [redis module](https://oss.redislabs.com/redistimeseries). Time
series commands are available as synchronous and asynchronous versions.

The crate is called `redis_ts` and you can depend on it via cargo. You will
also need redis in your dependencies. It has been tested agains redis 0.20.0
also need redis in your dependencies. It has been tested agains redis 0.21.0
but should work with versions higher than that.

```ini
[dependencies]
redis = "0.20.0"
redis_ts = "0.4.0"
redis = "0.21.0"
redis_ts = "0.4.1"
```

Or via git:
Expand All @@ -29,8 +29,8 @@ but should work with versions higher than that.
With async feature inherited from the [redis](https://docs.rs/redis) crate (either: 'async-std-comp' or 'tokio-comp):
```ini
[dependencies]
redis = "0.20.0"
redis_ts = { version = "0.4.0", features = ['tokio-comp'] }
redis = "0.21.0"
redis_ts = { version = "0.4.1", features = ['tokio-comp'] }
```
## Synchronous usage
Expand Down
15 changes: 15 additions & 0 deletions src/async_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ pub trait AsyncTsCommands: ConnectionLike + Send + Sized {
})
}

/// Modifies an existing redis time series configuration.
fn ts_alter<'a, K: ToRedisArgs + Send + Sync + 'a, RV: FromRedisValue>(
&'a mut self,
key: K,
options: TsOptions,
) -> RedisFuture<RV> {
Box::pin(async move {
cmd("TS.ALTER")
.arg(key)
.arg(options.uncompressed(false))
.query_async(self)
.await
})
}

/// Adds a single time series value with a timestamp to an existing redis time series.
fn ts_add<
'a,
Expand Down
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
//! series commands are available as synchronous and asynchronous versions.
//!
//! The crate is called `redis_ts` and you can depend on it via cargo. You will
//! also need redis in your dependencies. It has been tested agains redis 0.20.0
//! also need redis in your dependencies. It has been tested agains redis 0.21.0
//! but should work with versions higher than that.
//!
//! ```ini
//! [dependencies]
//! redis = "0.20.0"
//! redis_ts = "0.4.0"
//! redis = "0.21.0"
//! redis_ts = "0.4.1"
//! ```
//!
//! Or via git:
Expand All @@ -25,8 +25,8 @@
//! crate (either: 'async-std-comp' or 'tokio-comp):
//! ```ini
//! [dependencies]
//! redis = "0.20.0"
//! redis_ts = { version = "0.4.0", features = ['tokio-comp'] }
//! redis = "0.21.0"
//! redis_ts = { version = "0.4.1", features = ['tokio-comp'] }
//! ```
//!
//! # Synchronous usage
Expand Down
31 changes: 31 additions & 0 deletions tests/async_command_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,37 @@ pub async fn ts_get_ts_info(name: &str) {
assert_eq!(info.labels, vec![("a".to_string(), "b".to_string())]);
}

pub async fn ts_alter(name: &str) {
let mut con = get_con().await;
let _: () = con.del(name).await.unwrap();
let _: () = con
.ts_create(
name,
TsOptions::default()
.label("a", "b")
.duplicate_policy(TsDuplicatePolicy::Block)
.chunk_size(4096 * 2),
)
.await
.unwrap();
let _: () = con.ts_add(name, "1234", 2.0).await.unwrap();
let info: TsInfo = con.ts_info(name).await.unwrap();
assert_eq!(info.chunk_count, 1);
assert_eq!(info.chunk_size, 4096 * 2);
assert_eq!(info.labels, vec![("a".to_string(), "b".to_string())]);

let _: () = con
.ts_alter(
name,
TsOptions::default().chunk_size(4096 * 4).label("c", "d"),
)
.await
.unwrap();
let info2: TsInfo = con.ts_info(name).await.unwrap();
assert_eq!(info2.chunk_size, 4096 * 4);
assert_eq!(info2.labels, vec![("c".to_string(), "d".to_string())]);
}

pub async fn ts_range(name: &str) {
let name2 = &format!("{:}2", name);
let mut con = prepare_ts(name).await;
Expand Down
5 changes: 5 additions & 0 deletions tests/test_async_std_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ fn test_ts_get_ts_info() {
let _: () = block_on(ts_get_ts_info("async_test_ts_get_ts_info_std"));
}

#[test]
fn test_ts_alter() {
let _: () = block_on(ts_alter("async_test_ts_alter_std"));
}

#[test]
fn test_ts_range() {
let _: () = block_on(ts_range("async_test_ts_range_std"));
Expand Down
5 changes: 5 additions & 0 deletions tests/test_async_tokio_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ fn test_ts_get_ts_info() {
let _: () = block_on(ts_get_ts_info("async_test_ts_get_ts_info_tokio"));
}

#[test]
fn test_ts_alter() {
let _: () = block_on(ts_alter("async_test_ts_alter_tokio"));
}

#[test]
fn test_ts_range() {
let _: () = block_on(ts_range("async_test_ts_range_tokio"));
Expand Down
28 changes: 28 additions & 0 deletions tests/test_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,34 @@ fn test_ts_get_ts_info() {
assert_eq!(info.labels, vec![("a".to_string(), "b".to_string())]);
}

#[test]
fn test_ts_alter() {
let _: () = get_con().del("test_ts_alter").unwrap();
let _: Value = get_con()
.ts_create(
"test_ts_alter",
default_settings()
.duplicate_policy(TsDuplicatePolicy::Last)
.chunk_size(4096 * 2),
)
.unwrap();
let _: () = get_con().ts_add("test_ts_alter", "1234", 2.0).unwrap();
let info: TsInfo = get_con().ts_info("test_ts_alter").unwrap();
assert_eq!(info.chunk_count, 1);
assert_eq!(info.chunk_size, 4096 * 2);
assert_eq!(info.labels, vec![("a".to_string(), "b".to_string())]);

let _: Value = get_con()
.ts_alter(
"test_ts_alter",
TsOptions::default().chunk_size(4096 * 4).label("c", "d"),
)
.unwrap();
let info2: TsInfo = get_con().ts_info("test_ts_alter").unwrap();
assert_eq!(info2.chunk_size, 4096 * 4);
assert_eq!(info2.labels, vec![("c".to_string(), "d".to_string())]);
}

#[test]
fn test_ts_range() {
let _: () = get_con().del("test_ts_range").unwrap();
Expand Down

0 comments on commit 3430c82

Please sign in to comment.