RedisIt is an open-source log-type and Key-Value database written in ansi c language that supports the network and can be persistent based on memory. It also provides APIs in multiple languages.
--- Wikipedia
InProc mode is easy to lose and causes concurrency problems. If SQLServer or SQLServer mode is used, performance is consumed.
Redis uses this solution to solve several problems,
1. Fast Redis access.
2. User data is not easy to lose.
3. clusters are easily supported when there are many users.
4. view online users.
5. One user can log on at a time. (Implemented through code and will be introduced later)
6. Support persistence. (Of course it may be useless)
Program needsWhen the user status is obtained, the sessionid is used as the key to search in Redis.
Automatically intercept requests to call this method(Demo has examples)
Initialize Configuration
sessionRedis= ConfigurationManager.AppSettings[ timeOut = ConfigurationManager.AppSettings[ ( Exception( (.IsNullOrEmpty(timeOut)=== host = sessionRedis.Split(.Parse( writeHost = [] { host[ readHosts = host.Skip(= PooledRedisClientManager(writeHost, readHosts, = writeReadCount, MaxReadPoolSize = writeReadCount, AutoStart =
A delegate is written for control convenience.
F TryRedisWrite<F>(Func<IRedisClient, F>= = (client = Exception( + client.Host + + (client !=
For more information about one call example, see the source code.
KSet(Dictionary<, T><IRedisClient, > fun = (IRedisClient client) =><T>
context = cookie = (cookie == || ==
Methods for accessing users
Get<T>() T:, RedisClient<T> RedisClient<> Login<T>(T obj) T : , RedisClient<T>().KSet(SessionId, obj, TimeSpan(, Managers.TimeOut,
KSetEntryIn(<IRedisClient, > fun = (IRedisClient client) =>
After Encapsulation
RedisClient<>().KSetEntryIn(SessionId, TimeSpan(, Managers.TimeOut,
Here, I use ActionFilter in MVC3 to intercept all user requests.
Register in Global. asax
Session SessionExt(
Call Method
Click to download
SessionManager can be used to retrieve the number of users in the user list, deregister a user, and obtain user information, online user object list, and online user SessionId list based on the user ID.
One user login function will be implemented in the future