Skip to content

Commit f729487

Browse files
committed
Upgraded dependency to Paho v0.12. Made other dependencies current.
1 parent 0913e36 commit f729487

File tree

6 files changed

+85
-67
lines changed

6 files changed

+85
-67
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
/target/
22
**/*.rs.bk
33
Cargo.lock
4+
/*.vp*
5+
/*.vtg
6+
/.vscode/

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,18 @@ All notable changes to this project will be documented in this file.
33

44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
55

6-
## [v0.3.0](https://github.com/fpagliughi/mqtt.rust.redis/compare/v0.3.0..v0.2.2) - 2021-01-04
6+
## [v0.3.2](https://github.com/fpagliughi/mqtt.rust.redis/compare/v0.3.1..v0.3.2) - 2023-10-26
7+
8+
- Updated to Paho Rust v0.12
9+
- Updated Rust Edition to 2021
10+
-
11+
12+
## [v0.3.1](https://github.com/fpagliughi/mqtt.rust.redis/compare/v0.3.0..v0.3.1) - 2022-01-25
13+
14+
- Updated to Paho Rust v0.10
15+
16+
17+
## [v0.3.0](https://github.com/fpagliughi/mqtt.rust.redis/compare/v0.2.2..v0.3.0) - 2021-01-04
718

819
- Updated to use Paho Rust v0.9
920
- Updated Rust Edition to 2018

Cargo.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[package]
22
name = "paho-mqtt-redis"
3-
version = "0.3.1"
4-
edition = "2018"
3+
version = "0.3.2"
4+
edition = "2021"
5+
rust_version = "1.63.0"
56
authors = ["Frank Pagliughi <fpagliughi@mindspring.com>"]
67
homepage = "https://github.com/fpagliughi/mqtt.rust.redis"
78
repository = "https://github.com/fpagliughi/mqtt.rust.redis"
@@ -13,10 +14,10 @@ a local instance of Redis as the backing store.
1314
"""
1415

1516
[dependencies]
16-
paho-mqtt = "0.10"
17-
redis = "0.21"
17+
paho-mqtt = "0.12"
18+
redis = "0.23"
1819
log = "0.4"
1920

2021
[dev-dependencies]
21-
env_logger = "0.9"
22+
env_logger = "0.10"
2223

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The Paho MQTT Rust library is a wrapper around the Paho C library. It can be inc
1717

1818
```
1919
[dependencies]
20-
paho-mqtt = "0.9"
20+
paho-mqtt = "0.12"
2121
paho-mqtt-redis = "0.3"
2222
```
2323

@@ -75,9 +75,9 @@ It can be done like this:
7575
let persistence = RedisPersistence::new();
7676
7777
let opts = mqtt::CreateOptionsBuilder::new()
78-
.server_uri("tcp://localhost:1883")
79-
.user_persistence(persistence)
80-
.finalize();
78+
.server_uri("tcp://localhost:1883")
79+
.user_persistence(persistence)
80+
.finalize();
8181
8282
let cli = mqtt::AsyncClient::new(opts).unwrap_or_else(|e| {
8383
println!("Error creating the client: {:?}", e);

examples/redis_persist_pub.rs

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// redis_persist_pub.rs
2-
//
2+
//
33
// Example/test for mqtt-redis.
4-
//
4+
//
55
// This shows how to to use mqtt-redis with the Paho MQTT Rust library
66
// in order to have a local Redis server as the persistence store for the
77
// messaging application.
88
//
99

1010
// --------------------------------------------------------------------------
11-
// Copyright (c) 2017-2020 Frank Pagliughi <fpagliughi@mindspring.com>
11+
// Copyright (c) 2017-2023 Frank Pagliughi <fpagliughi@mindspring.com>
1212
// All rights reserved.
1313
//
1414
// Redistribution and use in source and binary forms, with or without
@@ -37,7 +37,7 @@
3737
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
3838
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3939
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40-
//
40+
//
4141

4242
use std::{env, process};
4343

@@ -48,57 +48,57 @@ use paho_mqtt_redis::RedisPersistence;
4848

4949
fn main() {
5050
// Use the environment logger for this example.
51-
env_logger::init();
51+
env_logger::init();
5252

53-
let host = env::args().skip(1).next().unwrap_or(
54-
"tcp://localhost:1883".to_string()
55-
);
53+
let host = env::args()
54+
.nth(1)
55+
.unwrap_or_else(|| "tcp://localhost:1883".to_string());
5656

57-
println!("Connecting to MQTT broker at: '{}'", host);
57+
println!("Connecting to MQTT broker at: '{}'", host);
5858

59-
// Create a client & define connect options
60-
let persistence = RedisPersistence::new();
59+
// Create a client & define connect options
60+
let persistence = RedisPersistence::new();
6161

62-
let create_opts = mqtt::CreateOptionsBuilder::new()
63-
.server_uri(host)
64-
.client_id("rust_redis_pub")
65-
.user_persistence(persistence)
66-
.finalize();
62+
let create_opts = mqtt::CreateOptionsBuilder::new()
63+
.server_uri(host)
64+
.client_id("rust_redis_pub")
65+
.user_persistence(persistence)
66+
.finalize();
6767

68-
let cli = mqtt::AsyncClient::new(create_opts).unwrap_or_else(|err| {
68+
let cli = mqtt::AsyncClient::new(create_opts).unwrap_or_else(|err| {
6969
match err {
70-
mqtt::Error::Paho(-2 /*mqtt::PERSISTENCE_ERROR*/) =>
71-
eprintln!("Error connecting to the local Redis server. Is it running?"),
72-
_ =>
73-
eprintln!("Error creating the client: {:?}", err)
70+
mqtt::Error::Paho(-2 /*mqtt::PERSISTENCE_ERROR*/) => {
71+
eprintln!("Error connecting to the local Redis server. Is it running?")
72+
}
73+
_ => eprintln!("Error creating the client: {:?}", err),
7474
};
75-
process::exit(2);
76-
});
75+
process::exit(2);
76+
});
7777

78-
// Connect and wait for it to complete or fail
79-
if let Err(e) = cli.connect(None).wait() {
80-
println!("Unable to connect: {:?}", e);
81-
process::exit(1);
82-
}
78+
// Connect and wait for it to complete or fail
79+
if let Err(e) = cli.connect(None).wait() {
80+
println!("Unable to connect: {:?}", e);
81+
process::exit(1);
82+
}
8383

84-
// Create a message and publish it
84+
// Create a message and publish it
8585
// Use non-zero QoS to exercise message persistence
86-
println!("Publishing a message to 'test' topic");
86+
println!("Publishing a message to 'test' topic");
8787

8888
let msg = mqtt::Message::new("test", "Hello world!", mqtt::QOS_1);
89-
let tok = cli.publish(msg);
89+
let tok = cli.publish(msg);
9090

91-
if let Err(e) = tok.wait() {
92-
println!("Error sending message: {:?}", e);
93-
}
91+
if let Err(e) = tok.wait() {
92+
println!("Error sending message: {:?}", e);
93+
}
9494

95-
// Disconnect from the broker
96-
println!("Disconnecting from the broker.");
95+
// Disconnect from the broker
96+
println!("Disconnecting from the broker.");
9797

98-
let tok = cli.disconnect(None);
99-
tok.wait().unwrap();
98+
let tok = cli.disconnect(None);
99+
tok.wait().unwrap();
100100

101-
println!("Done");
101+
println!("Done");
102102

103103
drop(cli);
104104
println!("Exiting");

src/lib.rs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// mqtt.rust.redis/src/lib.rs
2-
//
2+
//
33
// Main library source file for 'mqtt-redis'.
44
//
55
// --------------------------------------------------------------------------
6-
// Copyright (c) 2017-2020 Frank Pagliughi <fpagliughi@mindspring.com>
6+
// Copyright (c) 2017-2023 Frank Pagliughi <fpagliughi@mindspring.com>
77
// All rights reserved.
88
//
99
// Redistribution and use in source and binary forms, with or without
@@ -32,7 +32,7 @@
3232
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
3333
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3434
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35-
//
35+
//
3636

3737
//! This is a small example of using Redis as the persistence store for the
3838
//! Paho MQTT Rust client.
@@ -81,10 +81,11 @@
8181
//! use a remote Redis server for this purpose.
8282
//!
8383
84-
#[macro_use] extern crate log;
84+
#[macro_use]
85+
extern crate log;
8586

8687
use paho_mqtt as mqtt;
87-
use redis::{Client, Commands, Connection, RedisResult };
88+
use redis::{Client, Commands, Connection, RedisResult};
8889

8990
// --------------------------------------------------------------------------
9091

@@ -107,7 +108,9 @@ pub struct RedisPersistence {
107108

108109
impl RedisPersistence {
109110
/// Create a new persistence object to connect to a local Redis server.
110-
pub fn new() -> Self { Self::default() }
111+
pub fn new() -> Self {
112+
Self::default()
113+
}
111114
}
112115

113116
impl Default for RedisPersistence {
@@ -122,8 +125,7 @@ impl Default for RedisPersistence {
122125
}
123126
}
124127

125-
impl mqtt::ClientPersistence for RedisPersistence
126-
{
128+
impl mqtt::ClientPersistence for RedisPersistence {
127129
/// Opena the connection to the Redis client.
128130
fn open(&mut self, client_id: &str, server_uri: &str) -> mqtt::Result<()> {
129131
self.name = format!("{}:{}", client_id, server_uri);
@@ -136,7 +138,7 @@ impl mqtt::ClientPersistence for RedisPersistence
136138
}
137139
Err(e) => {
138140
warn!("Redis persistence connect error: {:?}", e);
139-
return Err(mqtt::PersistenceError)?
141+
Err(mqtt::PersistenceError)
140142
}
141143
}
142144
}
@@ -159,7 +161,11 @@ impl mqtt::ClientPersistence for RedisPersistence
159161
let conn = self.conn.as_mut().ok_or(mqtt::PersistenceError)?;
160162
let buf: Vec<u8> = buffers.concat();
161163
debug!("Putting key '{}' with {} bytes", key, buf.len());
162-
redis::cmd("HSET").arg(&self.name).arg(key).arg(buf).execute(conn);
164+
redis::cmd("HSET")
165+
.arg(&self.name)
166+
.arg(key)
167+
.arg(buf)
168+
.execute(conn);
163169
Ok(())
164170
}
165171

@@ -172,8 +178,7 @@ impl mqtt::ClientPersistence for RedisPersistence
172178
if let Ok(v) = conn.hget(&self.name, key) as RedisResult<Vec<u8>> {
173179
debug!("Found key {} with {} bytes", key, v.len());
174180
Ok(v)
175-
}
176-
else {
181+
} else {
177182
Err(mqtt::PersistenceError)
178183
}
179184
}
@@ -185,8 +190,7 @@ impl mqtt::ClientPersistence for RedisPersistence
185190
if let Ok(res) = conn.hdel(&self.name, key) as RedisResult<usize> {
186191
if res != 0 {
187192
debug!("Removed key: {}", key);
188-
}
189-
else {
193+
} else {
190194
debug!("Key not found (assuming OK): {}", key);
191195
}
192196
// Either way, if key is not in the store we report success.
@@ -202,8 +206,7 @@ impl mqtt::ClientPersistence for RedisPersistence
202206
if let Ok(v) = conn.hkeys(&self.name) as RedisResult<Vec<String>> {
203207
debug!("Found keys: {:?}", v);
204208
Ok(v)
205-
}
206-
else {
209+
} else {
207210
warn!("Error looking for keys");
208211
Err(mqtt::PersistenceError)
209212
}
@@ -231,8 +234,8 @@ impl mqtt::ClientPersistence for RedisPersistence
231234
if let Ok(res) = conn.hexists(&self.name, key) as RedisResult<usize> {
232235
debug!("'contains' query returned: {:?}", res);
233236
res != 0
237+
} else {
238+
false
234239
}
235-
else { false }
236240
}
237241
}
238-

0 commit comments

Comments
 (0)