Last active
February 8, 2018 15:25
-
-
Save dejanstojanovic/1af9a44f55ad9f0656873135595da081 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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