Exemple #1
0
        public static T GetComplexObject <T>(string objName)
        {
            var ser      = new DataContractJsonSerializer(typeof(T));
            var redisObj = RedisConnector.Get(objName);

            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(redisObj.ToString())))
            {
                var processedObj = (T)ser.ReadObject(ms);
                return(processedObj);
            }
        }
Exemple #2
0
        public static void SetComplexObject <T>(object obj, string objName)
        {
            //Saving and retrieval of a single complex object
            var ser     = new DataContractJsonSerializer(typeof(T));
            var objJSON = string.Empty;

            using (var ms = new MemoryStream())
            {
                ser.WriteObject(ms, obj);
                objJSON = Encoding.UTF8.GetString(ms.ToArray());
            }

            RedisConnector.Set(objName, objJSON);
        }
Exemple #3
0
        public static void SetComplexList <T>(List <T> listobj, string objName)
        {
            List <string> lstStrJSON = new List <string>();

            foreach (T obj in listobj)
            {
                var ser     = new DataContractJsonSerializer(typeof(T));
                var objJSON = string.Empty;

                using (var ms = new MemoryStream())
                {
                    ser.WriteObject(ms, obj);
                    objJSON = Encoding.UTF8.GetString(ms.ToArray());
                }

                lstStrJSON.Add(objJSON);
            }
            RedisConnector.Set(objName, lstStrJSON);
        }
Exemple #4
0
        public static List <T> GetComplexList <T>(string objName)
        {
            //Getting a list of complex objects from Redis
            if (RedisConnector.GetDatabase() != null)
            {
                var      lstObj          = (List <string>)RedisConnector.Get(objName);
                List <T> lstRetrievedObj = new List <T>();
                var      ser             = new DataContractJsonSerializer(typeof(T));

                foreach (string str in lstObj)
                {
                    using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(str)))
                    {
                        var processedObj = (T)ser.ReadObject(ms);
                        lstRetrievedObj.Add(processedObj);
                    }
                }
                return(lstRetrievedObj);
            }
            else
            {
                return(null);
            }
        }
Exemple #5
0
 public static void DeleteKeys(string keyName)
 {
     //Get a list of keys belonging to a particular user
     RedisConnector.GetDatabase().KeyDelete(keyName);
 }