Is it possible to get the key creation timestamp in redis db using jedis?
Thanks.
NO. There is no such command/support in Redis. Jedis, being a Redis client, does not support this as well.
Related
I have multiple keys in redis for session management and the lifetime of each key is 10 sec. So, losing these keys are fine for me as I can recreate a session.
However, I have one key, which I cannot afford to lose. Hence I would like that whenever the server restarts, redis reads only this keys from its persistent storage, and keep on persisting these as and when they change.
Is there an inbuilt redis way to achieve this?
Yes, reference
https://redis.io/topics/persistence
redis supports persistence.
some keys do not have expiration date. Best way I can think of is to use "get *" (but there are millions of keys), store that and then use the TTL to see if has an expiry. If it doesn't then you set it.
Would this be the way to go?
I see a similar question here, that's not a unix command. How would I implement this in unix or maybe C#(I am using SSH Nuget package)?
2 ways to do that:
through the redis database notification, you can know the op on redis key, and by subscribe those messages, you can run ttl on those keys.
run a task that scan the redis key set and run ttl on them.
The main idea is that do it quick and dont block the redis.
I have a requirement where i am pushing my keys to redis with some expiration time. Also have a subscriber for listening key expiration events and then have a callback to my other system which can perform some business rules on it. Is it a good design to have faith in redis pub-sub for this usecase?
Average TTL for keys will be in range ~15 minutes.
Using other design will make me having a scheduler/cron(every minute) or some polling system.
Yes, I have been using Redis pub/sub for exactly the same use case in production and has been working quite well for me without any issues.
I am building a security service as part of a suite of services that make up an application. I am considering using Redis to store sessions. A session is a data structure that looks like this:
{
string : sessionToken
DateTime : expiryUtc
string[] : permissionKeys
}
All I need to do is create, read and remove sessions. If I can have Redis remove expired sessions then great but not essential. As a noob to Redis I have some reading to do but can someone with Redis experience give me any guidance on the correct way to achieve this, assuming Redis is a good choice. BTW I'm on the Mono platform and have so far selected StackExchange.Redis client as at some stage I will want to cluster Redis. I am open to changing this selection.
You can go with Redis hashes, they will match your structure pretty well: http://redis.io/topics/data-types-intro#redis-hashes The session token can be the key of the whole hash. The StackExchange Redis client has a KeyExpire method which can take a DateTime parameter, so you can have Redis expire your keys. Inside Redis hashes you can't have nested structures so your permissionKeys and any other values that will go inside must be stored as simple values - you can serialize them as json.
And one more thing with hashes is that they allow for some memory optimization: http://redis.io/topics/memory-optimization#use-hashes-when-possible which can be pretty usefull if you will have many sessions to create (because Redis will store all these in ram).
I'm using redis hashes to store metadata associated with a single key which in my case is userId. I have a batchAPI where I pass in a batch of userIds and get the metadata back. Redis Cluster doesn't support multi key commands so What's the best way to achieve this with RedisCluster? I am using Jedis as the Java Client to connect to Redis.
If Lettuce is an option for you, then from 4.0.Final MGET on cluster is supported:
The cluster API was extended to run a command on multiple nodes and invocation to multi-key commands DEL, MGET, MSET and MSETNX perform automatic pipelining if the keys belong to different slots/masters.
(Source: https://github.com/mp911de/lettuce/releases/tag/4.0.Final)