public string StoreEntityExt(T entity) { string id = Guid.NewGuid().ToString(); bool added = cacheClient.Add(id, entity, DateTimeOffset.MaxValue); return(id); }
public void Add_Item_To_Redis_Database() { var added = Sut.Add("my Key", "my value"); Assert.True(added); Assert.True(Db.KeyExists("my Key")); }
/// <summary> /// /// </summary> public bool Add <T>(string Key, T Entity) where T : class { var entity = Serialise(Entity); if (_bUseLocalCache) { Utility.Cache.Store <T>(Entity, Key, DateTime.Now.AddMinutes(60), true); return(true); } return(_Cache.Add(Key, entity)); }
public IEnumerable <Entry> Add(Entry entity) { _cacheClient.Add((entity.EntryId).ToString(), entity); var result = _cacheClient.Get <Entry>((entity.EntryId).ToString()); if (result != null) { _sqlLiteRepository.Add(entity); } return((IEnumerable <Entry>)result); }
private void SaveWord(IEnumerable <WordDefinition> words) { foreach (var word in words) { _logger.LogInformation($"Saving word to cache: {word.Word}"); _cacheClient.Add(word.Key, word); } }
public void SaveTempProduct(Product product) { var serializer = new NewtonsoftSerializer(); var cacheClient = new StackExchangeRedisCacheClient(serializer); var productList = new List <Product>(); productList.Add(product); cacheClient.Add("abc", product); }
public Tuple <string, byte[]> this[string index] { get { return(_cache.Get <Tuple <string, byte[]> >(index)); } set { _cache.Add <Tuple <string, byte[]> >(index, value); } }
public bool Save <T>(string key, T value) { bool isSuccess; serializer = new NewtonsoftSerializer(); var redisConfiguration = RedisCachingSectionHandler.GetConfig(); using (cacheClient = new StackExchangeRedisCacheClient(serializer, redisConfiguration)) { isSuccess = cacheClient.Add <T>(key, value); } return(isSuccess); }
static void Main(string[] args) { var serializer = new NewtonsoftSerializer(); ICacheClient client = new StackExchangeRedisCacheClient(serializer, serviceUrl); var person = new { Name = "Héctor Pérez", Subjects = new List <string> { "Español", "Matemáticas" } }; client.Add("People", person, DateTimeOffset.Now.AddMinutes(10)); //ConnectionMultiplexer connection = // ConnectionMultiplexer.Connect(serviceUrl); //IDatabase cache = connection.GetDatabase(); //string cacheCommand = "PING"; //Console.WriteLine(cache.Execute(cacheCommand).ToString()); //cache.StringSet("Message", "Hola!"); //Console.WriteLine(cache.StringGet("Message")); //cache.ListLeftPush("listdemo", new RedisValue[] //{ // "hola", // "adiós", // "Lista de Redis" //}); //cache.SetAdd("setdemo", "cachedemo"); //var setResult = cache.SetPop("setdemo"); //Console.WriteLine(setResult); //connection.Dispose(); //Console.ReadLine(); }
static void Main(string[] args) { ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost"); // for multiple redis servers //ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("server1:6379,server2:6379"); IDatabase db = redis.GetDatabase(); //Loading and getting a string. db.StringSet("some key", "Some Value"); string gottenFromRedisString = db.StringGet("some key"); //Loding and getting a byte array from redis. byte[] key = { 0, 1 }; byte[] value = { 2, 3 }; db.StringSet(key, value); byte[] gottenfromRedisByteArray = db.StringGet(key); var someFellow = new Person { Id = 1, Name = "Milinda", Age = 26, IsMinor = false }; //Loading and getting an Object from Redis using my own serialization methods. db.StringSet(JsonConvert.SerializeObject(someFellow.Id), JsonConvert.SerializeObject(someFellow)); string personJsonString = db.StringGet("1"); Person gottenfromRedisPersonCustom = JsonConvert.DeserializeObject <Person>(personJsonString); //setting and getting an object from redis using StackExchange.Redis.Extensions ISerializer serializer = new NewtonsoftSerializer(); ICacheClient cacheClient = new StackExchangeRedisCacheClient(redis, serializer); bool success = cacheClient.Add(someFellow.Id.ToString(), someFellow); Person gottenfromRedisPerson = cacheClient.Get <Person>("1"); //Writing out the stuff we got back from redis to the console. Console.WriteLine($"Gotten from String: {gottenFromRedisString}"); Console.WriteLine($"Gotten from Array: {gottenfromRedisByteArray}"); Console.WriteLine($"Gotten from Custom Serializer: {gottenfromRedisPersonCustom.Name}"); Console.WriteLine($"Gotten from StackExchange.Redis.Extensions: {gottenfromRedisPerson.Name}"); #if DEBUG Console.ReadLine(); #endif }
static void Main(string[] args) { ISerializer serializer = new NewtonsoftSerializer(); var c = ConnectionMultiplexer.Connect("localhost"); ICacheClient client = new StackExchangeRedisCacheClient(c, serializer); client.Add("Test", new User() { Name = "Test", Age = 100, Birthday = DateTime.Now }); Console.WriteLine(client.Get <User>("Test").ToString()); Console.ReadKey(); }
/// <summary> /// 缓存用户好友列表 /// </summary> /// <param name="userId">用户ID</param> /// <param name="list">好友列表 1,2,3,4 (不知道好友列表长度会不会超过限制,如果超过限制,就不能用string存储了)</param> /// <returns>返回是否成功 true false</returns> public bool SetUserFriendList(int userId, string list) { if (string.IsNullOrEmpty(list)) { return(true); } //用户好友列表key var key = string.Format(LayIMConst.LayIM_All_UserFriends, userId); //如果key已经存在,先remove掉 if (cacheClient.Exists(key)) { cacheClient.Remove(key); } //一天过期 return(cacheClient.Add <string>(key, list, DateTimeOffset.Now.AddDays(1))); }
static void Main(string[] args) { var redisCacheConnectionString = ConfigurationManager.ConnectionStrings["RedisCacheConnection"].ToString(); var cacheConnection = ConnectionMultiplexer.Connect(redisCacheConnectionString); var serializer = new StackExchangeRedisExtensionsMessagePackSerializer(); var cacheClient = new StackExchangeRedisCacheClient(serializer, cacheConnection.Configuration); var testModel = new TestModel { Now = DateTime.Now, UTCNow = DateTime.UtcNow }; cacheClient.Add("testModel", testModel); var fromCache = cacheClient.Get <TestModel>("testModel"); var isNowTimeSame = testModel.Now == fromCache.Now; var isNowTimeSamwWhenAdjusted = testModel.Now == fromCache.Now.AddHours(7); var isUtcNowTimeSame = testModel.UTCNow == fromCache.UTCNow; }
public T Save <T>(instalist.Core.Model.InstaModels.Base.IRedis redis, string partitionKey = "") where T : class { var data = redis as T; if (redis.RedisEntityType == RedisEntityType.String) { RedisContext.Add(redis.RedisKey, data); } else if (redis.RedisEntityType == RedisEntityType.SortedList) { if (string.IsNullOrWhiteSpace(partitionKey)) { throw new NotImplementedException("partition key must be specified"); } var sortedkey = redis.MakeRedisKey(partitionKey).Replace("*", ""); InsertSortedSetWithAutoScore <T>(sortedkey, ref redis); } else { throw new NotFiniteNumberException("not yet implemented"); } return((T)redis); }
private void SendToRedis(string message) { var hosts = JsonConvert.DeserializeObject <List <Host> >(message); var config = new RedisConfiguration() { AbortOnConnectFail = false, KeyPrefix = "MyApp", Hosts = new RedisHost[] { new RedisHost() { Host = "redis", Port = 6379 } }, }; using (var cacheClient = new StackExchangeRedisCacheClient(new NewtonsoftSerializer(), config)) { Console.WriteLine("Adding Hosts..."); cacheClient.Add("myhost", hosts); Console.WriteLine("Hosts Added"); } }
public void Set <T>(CacheItem <T> item) where T : class => Client.Add(item.Key, item.Data, item.ExpiresAt, item.ExpiresIn, item.FireAndForget);
public bool Add<T>(string key, T value) { return ExecuteWithRetry(() => cacheClient.Add(key, value)); }
public void Add(SimpleCaptchaResult captcha) { Connect(); _client.Add <SimpleCaptchaResult>(captcha.Id.ToString(), captcha, DateTimeOffset.Now.AddMinutes(Convert.ToInt32(_configuration["RepositoryTTLMinutes"], CultureInfo.InvariantCulture))); }
public bool Add <T>(string key, T value) { return(cacheClient.Add(key, value)); }
public void StoreValue <TValue>(string key, TValue obj) { CacheClient.Add(key, obj); }
public bool Save(string key, Student student) { return(cacheClient.Add <Student>(key, student)); }
public void Set <T>(string key, T value) => _stackExchangeRedisCacheClient.Add(key, value, DateTimeOffset.Now.AddMinutes(5));
public bool Set <T>(string key, T data) { return(_client.Add <T>(key, data)); }
public void Set <T>(string key, T data, TimeSpan?cacheTime = null) where T : class { _retryPolicy.ExecuteAction(() => _cacheClient.Add(key, data, cacheTime ?? _cacheTime, false)); }