stefanwille / crystal-redis

Full featured Redis client for Crystal
MIT License
380 stars 61 forks source link

Question about return types #52

Closed jwoertink closed 6 years ago

jwoertink commented 6 years ago

This might not be the place for this question, but I'm hoping you might know or at least where I should look for an answer...

If I store Time.now, the value I get back is going to be a string. Is there a way to get back that Time instance?

redis = Redis.new
redis.set("time", Time.now)
value = redis.get("time")
puts typeof(value) #=> (String | Time)

I can't just cast it with .as(Time) because I get a cast from String to Time failed error.

jwoertink commented 6 years ago

After some thought, I came up with an idea for this. Storing as a string, and pulling back out as string will be fine.