Sto utilizzando la libreria di Booksleeve in un'applicazione C#/ASP.NET 4. Attualmente l'oggetto RedisConnection è un oggetto statico attraverso la mia classe MonoLink. Devo mantenere questa connessione aperta o dovrei aprirla/chiuderla dopo ogni query/transazione (come sto facendo ora)? Solo un po 'confuso. Ecco come lo sto usando, al momento:Con quale frequenza devo aprire/chiudere la mia connessione a Booksleeve?
public static MonoLink CreateMonolink(string URL)
{
redis.Open();
var transaction = redis.CreateTransaction();
string Key = null;
try
{
var IncrementTask = transaction.Strings.Increment(0, "nextmonolink");
if (!IncrementTask.Wait(5000))
{
transaction.Discard();
throw new System.TimeoutException("Monolink index increment timed out.");
}
// Increment complete
Key = string.Format("monolink:{0}", IncrementTask.Result);
var AddLinkTask = transaction.Strings.Set(0, Key, URL);
if (!AddLinkTask.Wait(5000))
{
transaction.Discard();
throw new System.TimeoutException("Add monolink creation timed out.");
}
// Run the transaction
var ExecTransaction = transaction.Execute();
if (!ExecTransaction.Wait(5000))
{
throw new System.TimeoutException("Add monolink transaction timed out.");
}
}
catch (Exception ex)
{
transaction.Discard();
throw ex;
}
finally
{
redis.Close(false);
}
// Link has been added to redis
MonoLink ml = new MonoLink();
ml.Key = Key;
ml.URL = URL;
return ml;
}
Grazie, in anticipo, per eventuali risposte/insight. Inoltre, c'è qualche tipo di documentazione ufficiale per questa libreria? Grazie S.O.^_ ^.
Questa dovrebbe essere la risposta accettata – welegan