예제 #1
0
        public override bool TryGet <T>(String key, out T entry)
        {
            var val = _redis.StringGet(BuildCacheKey(key));

            if (!val.HasValue)
            {
                entry = default(T);
                return(false);
            }
            entry = NewtonsoftJsonUtil.Parse <T>(val);
            return(true);
        }
예제 #2
0
        public void StringTest()
        {
            var    cacheKey = Guid.NewGuid().ToString();
            IRedis redis    = ServiceStackRedis.Default;

            //StringGet
            var cacheField = redis.StringGet(cacheKey);

            Assert.IsFalse(cacheField.HasValue);
            Assert.AreEqual((String)cacheField, null);

            //StringSet
            var cacheValue = Guid.NewGuid().ToString();

            redis.StringSet(cacheKey, cacheValue);

            //StringGet again
            cacheField = redis.StringGet(cacheKey);
            Assert.IsTrue(cacheField.HasValue);
            Assert.AreEqual((String)cacheField, cacheValue);

            //KeyDelete
            redis.KeyDelete(cacheKey);
        }