public long AddListItem(string key, StackExchange.Redis.RedisValue value, string value_ttl) { if (string.IsNullOrWhiteSpace(key) || string.IsNullOrWhiteSpace(value_ttl)) { throw new ArgumentException("Parameter is invalid.", "key or value_ttl", null); } if (value == StackExchange.Redis.RedisValue.Null || value == StackExchange.Redis.RedisValue.EmptyString) { throw new ArgumentException("Parameter is invalid.", "value", null); } try { StackExchange.Redis.RedisValue[] _v = new StackExchange.Redis.RedisValue[2]; _v[0] = value_ttl; _v[1] = value; return(_db.ListRightPush(key, _v)); } catch (Exception) { throw; } finally { } }
public void SerializeInfo() { Utility.StatusItem _StatusItem = Utility.StatusItem.None; this.Serialized_Data = Utility.ConvertObjToRedisValue(this.Data, out _StatusItem); this.StatusItem = _StatusItem; this.UpdateSerialized_TTL(); //Update TTL and generate new ttl string. }
/// <summary> /// Check and convert native type supported from Redis. /// </summary> /// <param name="value"></param> /// <param name="type"></param> /// <returns></returns> internal static object ConvertRedisValueToObject(StackExchange.Redis.RedisValue value, Type type, StatusItem statusItem) { object result = null; if (typeof(String) == type) { if ((statusItem & StatusItem.Compressed) == StatusItem.Compressed) { byte[] tmp = Utility.Deflate((Byte[])value, System.IO.Compression.CompressionMode.Decompress); result = System.Text.Encoding.UTF8.GetString(tmp); } else { result = (String)value; } } else if (typeof(Int16) == type) { result = (Int16)value; } else if (typeof(Int32) == type) { result = (Int32)value; } else if (typeof(Int64) == type) { result = (Int64)value; } else if (typeof(Boolean) == type) { result = (Boolean)value; } else if (typeof(Single) == type) { result = (Single)value; } else if (typeof(Double) == type) { result = (Double)value; } else { result = (Byte[])value; if ((statusItem & StatusItem.Compressed) == StatusItem.Compressed) { result = Utility.Deflate((Byte[])result, System.IO.Compression.CompressionMode.Decompress); } if ((statusItem & StatusItem.Serialized) == StatusItem.Serialized) { result = Utility.DeSerialize((Byte[])result); //If not supported De-Serialize Object... } } return(result); }
public Task DeleteByClientIdsAsync(Guid[] clientIds) { if (clientIds == null || clientIds.Length == 0) { return(TaskEx.CompletedTask); } var values = new StackExchange.Redis.RedisValue[clientIds.Length]; for (int i = 0; i < clientIds.Length; i++) { values[i] = clientIds[i].ToString(); } var db = _redis.RedisConn.GetDatabase(); return(db.HashDeleteAsync(_redisKeySpeedDataByClientId, values)); }
public void StoreCalendarSuccesfully() { //arrange ICalendar calendar = CreateCalendar(); string calendarHashKey = Schema.CalendarHashKey(CalendarName); //act JobStore.StoreCalendar(CalendarName, calendar, false, false); StackExchange.Redis.HashEntry[] calendarProperties = Db.HashGetAll(calendarHashKey); StackExchange.Redis.RedisValue serializedCalendar = (from hashEntry in calendarProperties where hashEntry.Name == RedisJobStoreSchema.CalendarSerialized select hashEntry.Value).FirstOrDefault(); ICalendar retrievedCalendar = JsonConvert.DeserializeObject(serializedCalendar, _serializerSettings) as ICalendar; //assert Assert.IsNotNull(retrievedCalendar); Assert.AreEqual(retrievedCalendar.Description, calendar.Description); }
/// <summary> /// Obtenir du cache partagé /// </summary> /// <param name="DirectInvoiceid"></param> /// <returns></returns> public DirectInvoice GetDirectInvoice(string iddirectinvoice) { DirectInvoice retour = null; try { // Obtien d'abord l'objet sur MemCached si Existe if (env != null) { StackExchange.Redis.ConfigurationOptions redisconfig = new StackExchange.Redis.ConfigurationOptions(); redisconfig.EndPoints.Add("22ec9a54-2921-43af-a4e9-9b1e7aff2b9b.pdb.ovh.net", 21784); redisconfig.Password = "******"; StackExchange.Redis.ConnectionMultiplexer redis = StackExchange.Redis.ConnectionMultiplexer.Connect(redisconfig); StackExchange.Redis.IDatabase redisDb = redis.GetDatabase(); StackExchange.Redis.RedisKey key = iddirectinvoice; StackExchange.Redis.RedisValue val = redisDb.StringGet(key, StackExchange.Redis.CommandFlags.None); if (!string.IsNullOrWhiteSpace(val)) { retour = new DirectInvoice(); retour.FromStringData(val); } } // sinon regarde en base if (retour == null) { Dictionary <string, object> ins = new Dictionary <string, object>(); ins.Add("iddirectinvoice", iddirectinvoice); retour = this.GetOneDefault <DirectInvoice>(ins); } return(retour); } catch (Exception ex) { throw new Exception("GetDirectInvoice " + ex.Message, ex); } }
public long UpdateTTL_Item(string key, string ttl) { if (string.IsNullOrWhiteSpace(key) || string.IsNullOrWhiteSpace(ttl)) { throw new ArgumentException("Parameter is invalid.", "key or ttl", null); } try { StackExchange.Redis.RedisValue[] _v = new StackExchange.Redis.RedisValue[1]; _v[0] = ttl; _db.ListSetByIndex(key, 0, _v[0]); return(1); } catch (Exception) { throw; } finally { } }
/// <summary> /// enregistre en base et dans le cache partagé /// </summary> public void SaveDirectInvoice(DirectInvoice directinvoice) { try { // Enregistrement des clef (données persistantes) en bases System.Data.DataRowState rowstate = directinvoice.GetRow().RowState; if (rowstate == System.Data.DataRowState.Detached || rowstate == System.Data.DataRowState.Added) { this.InsertBubble(directinvoice, true, false); } else { this.SaveBubble(directinvoice); } // Enregistrement des données non persistantes sur MemCached if (env != null) { StackExchange.Redis.ConnectionMultiplexer redis = StackExchange.Redis.ConnectionMultiplexer.Connect(GetRedisConfig()); StackExchange.Redis.IDatabase redisDb = redis.GetDatabase(); StackExchange.Redis.RedisValue val = directinvoice.ToStringData(); StackExchange.Redis.RedisKey key = directinvoice.IdDirectInvoice; redisDb.StringSet(key, val, null, StackExchange.Redis.When.Always, StackExchange.Redis.CommandFlags.None); // redng75Oj82p // !!! stocker dans memecached } } catch (Exception ex) { throw new Exception("SaveDirectInvoice " + ex.Message, ex); } }
/// <summary> /// Check and convert native type supported from Redis. /// </summary> /// <param name="value"></param> /// <returns></returns> internal static StackExchange.Redis.RedisValue ConvertObjToRedisValue(object value, out StatusItem statusItem) { statusItem = StatusItem.None; StackExchange.Redis.RedisValue result = StackExchange.Redis.RedisValue.Null; if (typeof(Byte[]) == value.GetType()) { if (Properties.Settings.Default.UseCompression) { result = Utility.Deflate((Byte[])value, System.IO.Compression.CompressionMode.Compress); statusItem = StatusItem.Compressed; } else { result = (Byte[])value; } } else if (typeof(String) == value.GetType()) { if (Properties.Settings.Default.UseCompression) //&& ((String)value).Length > 512 { byte[] tmp = System.Text.Encoding.UTF8.GetBytes((String)value); result = Utility.Deflate(tmp, System.IO.Compression.CompressionMode.Compress); statusItem = StatusItem.Compressed; } else { result = (String)value; } } else if (typeof(Int16) == value.GetType()) { result = (Int16)value; } else if (typeof(Int32) == value.GetType()) { result = (Int32)value; } else if (typeof(Int64) == value.GetType()) { result = (Int64)value; } else if (typeof(Boolean) == value.GetType()) { result = (Boolean)value; } else if (typeof(Single) == value.GetType()) { result = (Single)value; } else if (typeof(Double) == value.GetType()) { result = (Double)value; } else { if (Properties.Settings.Default.UseCompression) { byte[] tmp = Utility.Serialize(value); //If not supported Serialize Object... result = Utility.Deflate(tmp, System.IO.Compression.CompressionMode.Compress); statusItem = StatusItem.Compressed | StatusItem.Serialized; } else { result = Utility.Serialize(value); //If not supported Serialize Object... statusItem = StatusItem.Serialized; } } return(result); }