Пример #1
0
        public void HashTest()
        {
            var    cacheKey = Guid.NewGuid().ToString();
            IRedis redis    = ServiceStackRedis.Default;

            var count  = 10;
            var names  = new String[count].ToList();
            var values = new String[count];

            for (int i = 0; i < count; i++)
            {
                names[i]  = Guid.NewGuid().ToString();
                values[i] = Guid.NewGuid().ToString();
            }
            var list = Enumerable.Range(0, count)
                       .Select(i => new RedisEntry(names[i], values[i]))
                       .ToArray();

            redis.HashSet(cacheKey, list);
            Assert.AreEqual(redis.HashLength(cacheKey), count);

            var array = redis.HashGet(cacheKey, names.Select(x => (RedisField)x).ToArray());

            for (int i = 0; i < count; i++)
            {
                Assert.IsTrue(array[i] == values[i]);
            }

            var hash = redis.HashGetAll(cacheKey);

            Assert.AreEqual(hash.Length, count);
            for (int i = 0; i < count; i++)
            {
                Assert.IsTrue(hash[i].Name == names[i]);
                Assert.IsTrue(hash[i].Value == values[i]);
            }

            for (int i = 0; i < count; i++)
            {
                var cacheItem = redis.HashGet(cacheKey, names[i]);
                Assert.IsTrue((String)cacheItem == values[i]);
            }

            for (int i = 0; i < count; i++)
            {
                var deleted = redis.HashDelete(cacheKey, names[i]);
                Assert.IsTrue(deleted);
            }

            var exist = redis.KeyExists(cacheKey);

            Assert.IsFalse(exist);
        }
Пример #2
0
        /// <summary>
        /// 根据ID删除数据
        /// </summary>
        /// <param name="t">HuobiProject.Models</param>
        /// <returns>
        /// Success:T
        /// Failed:F
        /// </returns>
        bool ICURD <TTicket> .Delete(TTicket t)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                TTicket tk = m_iTicket.Retrieve(t);
                m_db.TTicket.Remove(tk);
                m_db.SaveChanges();

                m_redis.HashDelete(RedisDB, t.TicketId);

                scope.Complete();
            }
            return(true);
        }