Comments (4)
Heads-up -- in recent versions of https://github.com/go-redis/redis , there is a redis.KeepTTL
value (i.e. -1
) which maps to the REDIS keepttl
option for write operations, but the latest version of cache
takes anything < 0
and remaps it to 0
, so this doesn't flow through to the underlying redis client, and ultimately doesn't turn into keepttl
on the Redis server.
from cache.
Can we support this command for more flexible TTL values?
Could you explain what you mean by this?
from cache.
For each key in Redis, We have set a TTL value for it. I want to get this TTL value and reuse it for the next time set. Sorry if my eng is bad.
For code example:
// Set ttl 3 mins for key
ttl := 3 * time.Minute
redis.Set(ctx, key, val, ttl).Result()
// after a momemt
ttl, _ := redis.TTL(ctx, key).Result()
// re-set ttl to key
redis.Set(ctx, key, val, ttl).Result()
from cache.
Your example is the right way of doing this (you should handle those errors though). If you are doing this in many places, you could just wrap it in a helper function SetWithOldTTL(key, val, cache ...)
. Don't think such a function in the main lib would be ideal.
from cache.
Related Issues (20)
- LRU cache
- feature: encapsulate server-assisted client side caching HOT 1
- Crashed with "makeslice: cap out of range" HOT 2
- Allow setting msgpack struct tag
- When cache.Once is called with a Redis dropped connection it does not fail HOT 3
- Cache corruption in TinyLRU local cache when keys expire HOT 1
- TTL in TinyLFU vs TTL in cache.Item HOT 1
- How to save the array HOT 1
- Nil comparaison used for Item.Value field is not accurate HOT 1
- Add batch delete feature HOT 1
- unknown compression method: 3d HOT 6
- Add instructions to use context.WithCancel() to documentation HOT 1
- Is it safe to use it with concurrency? HOT 4
- Is there any way to flushdb with go redis cache? HOT 2
- Dates are unmarshaled to time.Local HOT 1
- How to set item with no expiration? HOT 4
- Cache with mock doesn't work HOT 1
- go-redis V9 compatibility HOT 2
- add support redis/rueidis
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cache.