Release notes for v2.0.0-Preview

Siddharth Chatrola 2015-09-29 13:16:47 -07:00
Родитель 637e45404f
Коммит 731435e280
2 изменённых файлов: 62 добавлений и 0 удалений

6
Release-Notes.md Normal file

@ -0,0 +1,6 @@
Below is a summary of the the main features/bug fixes in the most recent releases.
## v2.0.0-Preview
* This release contains a breaking change from '1.*' versions in the format of key names used to store session data. In order to support Redis Clusters, key names now include brackets. As a result of this change, existing session data will not be recognized by this session state provider.
[Sample code to migrate old session data](https://github.com/Azure/aspnet-redis-providers/wiki/v2.0.0-Preview)

56
v2.0.0-Preview.md Normal file

@ -0,0 +1,56 @@
* In your application, You can code like sample below in Global.asax.cs to migrate session data from old format to new format when any request comes (session will be converted only when a request to access that session comes to the app). You have to do this once to update the keys to the new format. Once you have updated all the keys you can remove this code.
// KEYS[] = data-id, internal-id, lock-id, new-data-id, new-internal-id, new-lock-id
readonly string renameSessionScript = (@"
if redis.call('EXISTS', KEYS[1]) ~= 0 then
local expiretime = redis.call('TTL',KEYS[1])
redis.call('RENAME',KEYS[1],KEYS[4])
redis.call('EXPIRE',KEYS[1], expiretime)
end
if redis.call('EXISTS', KEYS[2]) ~= 0 then
local expiretime = redis.call('TTL',KEYS[2])
redis.call('RENAME',KEYS[2],KEYS[5])
redis.call('EXPIRE',KEYS[2], expiretime)
end
if redis.call('EXISTS', KEYS[3]) ~= 0 then
local expiretime = redis.call('TTL',KEYS[3])
redis.call('RENAME',KEYS[3],KEYS[6])
redis.call('EXPIRE',KEYS[3], expiretime)
end
return 1"
);
private static Lazy<ConnectionMultiplexer> lazyConnection = new Lazy<ConnectionMultiplexer>(() =>
{
return ConnectionMultiplexer.Connect("mycache.redis.cache.windows.net,abortConnect=false,ssl=true,password=...");
});
public static ConnectionMultiplexer Connection
{
get
{
return lazyConnection.Value;
}
}
void Application_AuthorizeRequest(object sender, EventArgs e)
{
string sessionId = this.Request.Params.Get("ASP.NET_SessionId");
if(!string.IsNullOrEmpty(sessionId))
{
IDatabase connection = Connection.GetDatabase();
string applicationName = "/"; // application name that you might have specified in web.config if not than default is '/'.
string appIdAndSessionId = applicationName + "_" + sessionId;
RedisKey[] keys = new RedisKey[6];
keys[0] = appIdAndSessionId + "_Data";
keys[1] = appIdAndSessionId + "_Write_Lock";
keys[2] = appIdAndSessionId + "_Internal";
keys[3] = "{" + appIdAndSessionId + "}_Data";
keys[4] = "{" + appIdAndSessionId + "}_Write_Lock";
keys[5] = "{" + appIdAndSessionId + "}_Internal";
connection.ScriptEvaluate(renameSessionScript, keys, new RedisValue[0]);
}
}
* In server farm, if only one server is updated with new session state provider than another problem can happen. e.g. One request comes to server with new session state which converts session data from old format to new format. Now, some other request comes to server running old session state which will now fail to find session as it was converted earlier.