I am currently trying to convert the following Redis command into rust:
HSET book_store_list 1 1,2,3
Essentially, create the bookstore_list Hash, with a Field (1) and value (1,2,3) which works fine within the Redis GUI.
The issue is that the hset API in rust redis does not seem to work as I envisioned.
For example:
let vector = vec![1,2,3]
hset("book_store_list", 1, &vector)
Results in two Field-Value entries within the book_store_list hash
Field 1 Value 1 Field 2 Value 3
The issue is that the redis rust crate seems to interpret the [1,2,3] vector to be separate values (with 2 and 3 being a new field value pair) to be cached in instead of one value. Just wondering if anyone has faced this issue before?
Believe that I have found the answer. In order for Redis to accept [1,2,3] as one singular value, we must call the to_string api from the serde_json crate like so:
let value = serde_json::to_string(&vector).unwrap();
I guess the lesson of this is to stringify all values before invoking any HSET commands in rust redis!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With