Code Monkey home page Code Monkey logo

Comments (3)

aembke avatar aembke commented on September 28, 2024 1

Ah I should do a better job documenting this, but RedisMap was built to be a NewType in order to support generic inputs on certain functions. It is designed to be used as an intermediate type so callers can use HashMap or BTreeMap, but it's rare for a caller to need to manually construct a RedisMap by hand.

In your case you can probably collapse that code into this:

let _: () = redis_client.set("foo_key", 123, Some(Expiration::EX(10), None, false).await?;

Or, if you did mean to encode a map into a non-nested type like SET, you would need to serialize it to some format, such as JSON, or something like that. Or, you could use HSET which supports nested maps:

let mut values: HashMap<String, i64> = HashMap::new(); // or BTreeMap, etc
values.insert("foo_key".into(), 123);

let _: () = redis_client.hset("KEYS", values).await?;

A quick note on the NewType values such as RedisMap - they are not as easy to use in the current 4.3.2 version on crates.io as I'd like. I'm a few days away from releasing 5.0.0 which makes some big ergonomics improvements to these types, and these interfaces should be easier to use then.

from fred.rs.

fy2462 avatar fy2462 commented on September 28, 2024 1

I found I can not set Expiration with hset, How to do that as set ?

from fred.rs.

fy2462 avatar fy2462 commented on September 28, 2024

The hset command seems what I want, Thanks.

from fred.rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.