public RedisData.Response Get(LambdaRedisArg data) { var resp = new RedisData.Response() { status = RedisError.E_CHAOS.ToString(), k = data.k }; try{ ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(data.redisURI); IDatabase cache = redis.GetDatabase(); var redisResp = cache.StringGetWithExpiry(data.k); if (redisResp.Value.IsNullOrEmpty) { resp.v = ""; resp.status = RedisError.E_NOTFOUND.ToString(); } else { resp.v = redisResp.Value.ToString(); if (redisResp.Expiry != null) { TimeSpan tmp = (TimeSpan)redisResp.Expiry; resp.ttlSec = (int)tmp.TotalSeconds; } resp.status = RedisError.E_OK.ToString(); } } catch (Exception ex) { m_ctx.Log(ex.Message); resp.status = RedisError.E_CRITICAL.ToString(); resp.meta = ex.Message; } return(resp); }
public RedisData.Response Set(LambdaRedisArg data) { var resp = new RedisData.Response() { status = RedisError.E_CHAOS.ToString(), k = data.k }; try { ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(data.redisURI); IDatabase cache = redis.GetDatabase(); m_ctx.Log("SetTTL > " + data.ttlSec.ToString()); if (data.ttlSec > 0) { if (cache.StringSet(data.k, data.v, TimeSpan.FromSeconds(data.ttlSec))) { resp.status = RedisError.E_OK.ToString(); } else { resp.status = RedisError.E_CRITICAL.ToString(); } } else { if (cache.StringSet(data.k, data.v)) { resp.status = RedisError.E_OK.ToString(); } else { resp.status = RedisError.E_CRITICAL.ToString(); } } } catch (Exception ex) { m_ctx.Log(ex.ToString()); resp.status = RedisError.E_CRITICAL.ToString(); resp.meta = ex.Message; } return(resp); }