Facebook
From Sweltering Zebra, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 280
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Newtonsoft.Json;
  8. using StackExchange.Redis;
  9. namespace RedisProject
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             string json = File.ReadAllText("C:\\json.json");
  16.             List<Persona> personList = JsonConvert.DeserializeObject<List<Persona>>(json);
  17.  
  18.             Console.WriteLine("Deserialized");
  19.             ConnectionMultiplexer connection = ConnectionMultiplexer.Connect("kpredis.redis.cache.windows.net:6380,password=xzSEjBK3uiTuIJjdkLsNDqtckMBH62lLjTOmcIn8eEo=,ssl=True,abortConnect=False");
  20.             IDatabase cache = connection.GetDatabase();
  21.  
  22.             foreach (var persona in personList)
  23.             {
  24.                 cache.StringSet(persona.name, JsonConvert.SerializeObject(persona));
  25.             }
  26.  
  27.            
  28.  
  29.         }
  30.         private static Lazy<ConnectionMultiplexer> lazyConnection = new Lazy<ConnectionMultiplexer>(() =>
  31.         {
  32.             return ConnectionMultiplexer.Connect("contoso5.redis.cache.windows.net,abortConnect=false,ssl=true,password=...");
  33.         });
  34.  
  35.         public static ConnectionMultiplexer Connection
  36.         {
  37.             get
  38.             {
  39.                 return lazyConnection.Value;
  40.             }
  41.         }
  42.     }
  43. }
  44.