Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding redis connection dispose method #58

Merged
merged 1 commit into from
Dec 16, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions CBRedis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public static bool SetRedisKey(string key, string value, int? expTimeMin) //
{
cache.StringSet(key, value, TimeSpan.FromMinutes(Convert.ToDouble(expTimeMin)));
}


connection.Close();
connection.Dispose();

return true;
}
Expand All @@ -72,6 +74,9 @@ public static string GetRedisKeyValue(string key)
IDatabase cache = connection.GetDatabase(0);
result = cache.StringGet(key);

connection.Close();
connection.Dispose();

return result;
}
catch (Exception)
Expand All @@ -90,13 +95,17 @@ public static bool SetSortedSetRank(string sid, double point)
{
IDatabase cache = connection.GetDatabase(1);
cache.SortedSetAdd(globalVal.CloudBreadRankSortedSet, sid, point);

connection.Close();
connection.Dispose();

}
catch (Exception)
{

throw;
}

return true;
}

Expand All @@ -109,7 +118,11 @@ public static long GetSortedSetRank(string sid)
try
{
IDatabase cache = connection.GetDatabase(1);
rank = cache.SortedSetRank(globalVal.CloudBreadRankSortedSet, sid, Order.Descending) ?? 0;
rank = cache.SortedSetRank(globalVal.CloudBreadRankSortedSet, sid, Order.Descending) ?? 0;

connection.Close();
connection.Dispose();

}
catch (Exception)
{
Expand All @@ -124,7 +137,7 @@ public static long GetSortedSetRank(string sid)
/// Get my rank and then call this method to fetch +-10 rank(total 20) rank
public static SortedSetEntry[] GetSortedSetRankByRange(long startRank, long endRank)
{

ConnectionMultiplexer connection = ConnectionMultiplexer.Connect(redisConnectionStringRank);

try
Expand All @@ -133,6 +146,10 @@ public static SortedSetEntry[] GetSortedSetRankByRange(long startRank, long endR
//SortedSetEntry[] rank = cache.SortedSetRangeByScoreWithScores(globalVal.CloudBreadRankSortedSet, startRank, endRank, Exclude.None, Order.Descending);
SortedSetEntry[] se = cache.SortedSetRangeByRankWithScores(globalVal.CloudBreadRankSortedSet, startRank, endRank, Order.Descending);
//return JsonConvert.SerializeObject(se);

connection.Close();
connection.Dispose();

return se;
}
catch (Exception)
Expand All @@ -153,6 +170,10 @@ public static SortedSetEntry[] GetTopSortedSetRank(int countNumber)
{
IDatabase cache = connection.GetDatabase(1);
SortedSetEntry[] sse = cache.SortedSetRangeByScoreWithScores(globalVal.CloudBreadRankSortedSet, order: Order.Descending, take: countNumber);

connection.Close();
connection.Dispose();

return sse;

}
Expand Down Expand Up @@ -198,7 +219,7 @@ public static bool FillAllRankFromDB()
/// make SortedSetEntry to fill out
SortedSetEntry[] sse = new SortedSetEntry[dt.Rows.Count];
Int64 i = 0;
foreach(DataRow dr in dt.Rows)
foreach (DataRow dr in dt.Rows)
{
// fill rank row to redis struct array
sse[i] = new SortedSetEntry(dr[0].ToString(), Int64.Parse(dr[1].ToString()));
Expand All @@ -208,6 +229,9 @@ public static bool FillAllRankFromDB()
// fill out all rank data
cache.SortedSetAdd(globalVal.CloudBreadRankSortedSet, sse);

connection.Close();
connection.Dispose();

return true;
}

Expand Down Expand Up @@ -238,6 +262,9 @@ public static void saveRedisLog(string key, string message, int? expTimeDays)
cache.StringSetAsync(key, message, TimeSpan.FromDays(Convert.ToDouble(expTimeDays)));
}

connection.Close();
connection.Dispose();

}
catch (Exception)
{
Expand Down