Questo articolo è un articolo speculare di traduzione automatica, clicca qui per saltare all'articolo originale.

Vista: 27351|Risposta: 1

[Redis] Redis. Componente open-source .NET Beetle.Redis

[Copiato link]
Pubblicato su 29/12/2015 11:58:16 | | | |
Beetle.Redis è un client open-source Redis per un componente .net che offre un modo molto semplice per gli sviluppatori di accedere facilmente a Redis, fornendo al contempo il supporto ai formati dati per json e protobuf. L'accesso predefinito basato sui pool di connessione permette agli sviluppatori di accedere a Redis in modo conciso ed efficiente senza doversi preoccupare di una serie di cose complesse come threading e sincronizzazione delle connessioni.
disposizione

  1. <configSections>
  2.     <section name="redisClientSection" type="Beetle.Redis.RedisClientSection, Beetle.Redis, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
  3.   </configSections>
  4.   <redisClientSection dB="0"  xmlns="urn:Beetle.Redis">
  5.     <writes>
  6.       <add host="192.168.0.105" connections="9"/>
  7.     </writes>
  8.     <reads>
  9.       <add host="192.168.0.105" connections="9"/>
  10.     </reads>
  11.   </redisClientSection>
Copia codice

Le configurazioni sopra sono gli indirizzi dei servizi di lettura/scrittura, il numero predefinito di connessioni è 9 e l'accesso al database è 0. Più informazioni di servizio redis possono essere configurate in base alle esigenze dell'applicazione effettiva.


L'uso del componente è molto semplice, non è necessario definire le informazioni di connessione come altri componenti client Redis prima dell'uso, e il componente utilizzerà automaticamente l'ambiente di configurazione di redisClientSection per gestire di default il corrispondente servizio Redis.


Stringa get/set


  1. StringKey key = "HENRY";
  2.             string Remark = "henryfan gz cn 18 [email]henryfan@msn.com[/email] 28304340";
  3.             key.Set(Remark);
  4.             Assert.AreEqual(Remark, key.Get());
Copia codice
Json Get/Set


  1. JsonKey rk = "henry_json";
  2.             UserBase ub = new UserBase();
  3.             ub.Name = "henryfan";
  4.             ub.City = "gz";
  5.             ub.Counrty = "cn";
  6.             ub.Age = 10;
  7.             rk.Set(ub);
  8.             Assert.AreEqual(ub.Name, rk.Get().Name);
Copia codice
Protobuf Get/Set


  1. ProtobufKey rk = "henry_protobuf";
  2.             UserBase ub = new UserBase();
  3.             ub.Name = "henryfan";
  4.             ub.City = "gz";
  5.             ub.Counrty = "cn";
  6.             ub.Age = 10;
  7.             rk.Set(ub);
  8.             Assert.AreEqual(ub.Name, rk.Get().Name);
Copia codice


Elenco


  1. [TestMethod]
  2.         public void LST_POP_PUSH()
  3.         {
  4.             ProtobufList lst = "USERS";
  5.             lst.Push(new UserBase { Name = "henry", Age = 18, City = "gz", Counrty = "cn" });
  6.             Assert.AreEqual("henry", lst.Pop().Name);
  7.         }
  8.         [TestMethod]
  9.         public void LST_REMOVE_ADD()
  10.         {
  11.             ProtobufList lst = "USERS";
  12.             lst.Add(new UserBase { Name = "henry", Age = 18, City = "gz", Counrty = "cn" });
  13.             lst.Add(new UserBase { Name = "bbq", Age = 18, City = "gz", Counrty = "cn" });
  14.             Assert.AreEqual("bbq", lst.Remove().Name);
  15.         }
  16.         [TestMethod]
  17.         public void LST_Length()
  18.         {
  19.             ProtobufList lst = "USERS";
  20.             lst.Clear();
  21.             lst.Add(new UserBase { Name = "henry", Age = 18, City = "gz", Counrty = "cn" });
  22.             lst.Add(new UserBase { Name = "bbq", Age = 18, City = "gz", Counrty = "cn" });
  23.             Assert.AreEqual(lst.Count(), 2);
  24.         }
  25.         [TestMethod]
  26.         public void LST_Region()
  27.         {
  28.             ProtobufList lst ="USERS";
  29.             lst.Clear();
  30.             for (int i = 0; i < 10; i++)
  31.             {
  32.                 lst.Add(new UserBase { Name = "henry" + i, Age = 18, City = "gz", Counrty = "cn" });
  33.             }
  34.             IList items = lst.Range();
  35.             Assert.AreEqual(items[0].Name, "henry0");
  36.             Assert.AreEqual(items[9].Name, "henry9");
  37.             items = lst.Range(5, 7);
  38.             Assert.AreEqual(items[0].Name, "henry5");
  39.             Assert.AreEqual(items[2].Name, "henry7");
  40.         }
Copia codice
MapSet


  1. [TestMethod]
  2.         public void MapSet()
  3.         {

  4.             JsonMapSet map = "HENRY_INFO";
  5.             UserBase ub = new UserBase();
  6.             ub.Name = "henryfan";
  7.             ub.City = "gz";
  8.             ub.Counrty = "cn";
  9.             ub.Age = 10;
  10.             Contact contact = new Contact();
  11.             contact.EMail = "hernyfan@msn.com";
  12.             contact.QQ = "28304340";
  13.             contact.Phone = "13660223497";
  14.             map.Set(ub, contact);
  15.             IList data = map.Get();
  16.             Assert.AreEqual(ub.Name, ((UserBase)data[0]).Name);
  17.             Assert.AreEqual(contact.Phone, ((Contact)data[1]).Phone);

  18.         }
  19.         [TestMethod]
  20.         public void MapSetdRemove()
  21.         {
  22.             JsonMapSet map = "HENRY_INFO";
  23.             UserBase ub = new UserBase();
  24.             ub.Name = "henryfan";
  25.             ub.City = "gz";
  26.             ub.Counrty = "cn";
  27.             ub.Age = 10;
  28.             Contact contact = new Contact();
  29.             contact.EMail = "hernyfan@msn.com";
  30.             contact.QQ = "28304340";
  31.             contact.Phone = "13660223497";
  32.             map.Set(ub, contact);
  33.             map.Remove();
  34.             contact = map.Get();
  35.             Assert.AreEqual(null, contact);

  36.         }
  37.         [TestMethod]
  38.         public void MapSetClear()
  39.         {
  40.             JsonMapSet map = "HENRY_INFO";
  41.             UserBase ub = new UserBase();
  42.             ub.Name = "henryfan";
  43.             ub.City = "gz";
  44.             ub.Counrty = "cn";
  45.             ub.Age = 10;
  46.             Contact contact = new Contact();
  47.             contact.EMail = "hernyfan@msn.com";
  48.             contact.QQ = "28304340";
  49.             contact.Phone = "13660223497";
  50.             map.Set(ub, contact);
  51.             map.Clear();
  52.             IList data = map.Get();
  53.             Assert.AreEqual(null, data[0]);
  54.             Assert.AreEqual(null, data[1]);
  55.         }
Copia codice


Prestazione

Esempio
Scaricare

Beetle.Redis.0.6.6.5.rar (244.2 KB, Numero di download: 1)




Precedente:schema di configurazione sessionState cookieless
Prossimo:5 cose da sapere prima di usare Redis
Pubblicato su 22/09/2021 20:25:08 |
Impara a imparare...
Disconoscimento:
Tutto il software, i materiali di programmazione o gli articoli pubblicati dalla Code Farmer Network sono destinati esclusivamente all'apprendimento e alla ricerca; I contenuti sopra elencati non devono essere utilizzati per scopi commerciali o illegali, altrimenti gli utenti dovranno sostenere tutte le conseguenze. Le informazioni su questo sito provengono da Internet, e le controversie sul copyright non hanno nulla a che fare con questo sito. Devi eliminare completamente i contenuti sopra elencati dal tuo computer entro 24 ore dal download. Se ti piace il programma, ti preghiamo di supportare software autentico, acquistare la registrazione e ottenere servizi autentici migliori. In caso di violazione, vi preghiamo di contattarci via email.

Mail To:help@itsvse.com