-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSessionModel.cs
More file actions
40 lines (33 loc) · 1.26 KB
/
SessionModel.cs
File metadata and controls
40 lines (33 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using RedisSession4Net.Core.Cache;
using System;
namespace RedisSession4Net.Web.Models
{
public class SessionModel : ISessionPropertities
{
public RedisHelper Redis { get; set; }
public int SampleInteger
{
get { return this.Redis.Get<int>(nameof(SampleInteger), x => Convert.ToInt32(x)); }
set { this.Redis.Add(nameof(SampleInteger), value); }
}
public string SampleString
{
get { return this.Redis.Get<string>(nameof(SampleString)); }
set { this.Redis.Add(nameof(SampleString), value); }
}
public bool SampleBoolean
{
get { return this.Redis.Get<bool?>(nameof(SampleBoolean), x => Convert.ToBoolean(x)) ?? false; }
set { this.Redis.Add(nameof(SampleBoolean), value); }
}
public DateTime SampleDateTime
{
get { return this.GetDateTime(nameof(SampleDateTime)); }
set { this.SetDateTime(nameof(SampleDateTime), value); }
}
private DateTime GetDateTime(string key)
=> this.Redis.Get<DateTime>(key, obj => DateTime.Parse(obj.ToString()));
private void SetDateTime(string key, DateTime dt)
=> this.Redis.Add(key, dt.ToString());
}
}