Skip to content

Instantly share code, notes, and snippets.

@dejanstojanovic
Last active February 8, 2018 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dejanstojanovic/1af9a44f55ad9f0656873135595da081 to your computer and use it in GitHub Desktop.
Save dejanstojanovic/1af9a44f55ad9f0656873135595da081 to your computer and use it in GitHub Desktop.
class Program
{
static ConnectionMultiplexer redisConnection = ConnectionMultiplexer.Connect("<REDIS connection string>");
static void Main(string[] args)
{
var key = "counter.test";
var expiry = TimeSpan.FromMinutes(5);
IDatabase db = redisConnection.GetDatabase(3);
var count = db.StringIncrement(key, 1);
var ttl = db.KeyTimeToLive(key);
if (!ttl.HasValue)
{
db.KeyExpire(key, expiry);
ttl = expiry;
}
Console.WriteLine($"Count: {count}");
Console.WriteLine($"TTL(s): {ttl.Value.TotalSeconds}");
Console.ReadLine();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment