Exemplo n.º 1
0
        public void KeyRename()
        {
            IRedis redis = ServiceStackRedis.Default;
            var    key   = Guid.NewGuid().ToString();
            var    value = Guid.NewGuid().ToString();

            redis.StringSet(key, value);
            Assert.IsTrue(redis.KeyExists(key));

            var key2     = Guid.NewGuid().ToString();
            var renamed1 = redis.KeyRename(key, key2);

            Assert.IsTrue(renamed1);

            Assert.IsFalse(redis.KeyExists(key));
            Assert.IsTrue(redis.KeyExists(key2));

            redis.KeyDelete(key2);
            try {
                var renamed12 = redis.KeyRename(key, key2);
                Assert.Fail();
            }
            catch (Exception ex) {
                Assert.IsTrue(ex is RedisException);
            }
        }
Exemplo n.º 2
0
 public Repository(IDatabase database, string tableName, IRedis redis)
 {
     Database = database;
     TableName = tableName;
     TableColumns = ReflectionUtils.GetTableColumns(typeof(T));
     Redis = redis;
 }
Exemplo n.º 3
0
 public Resque(IJobCreator jobCreator, IFailureService failureService, IRedis client)
 {
     JobCreator = jobCreator;
     FailureService = failureService;
     Client = client;
     Workers = new List<Worker>();
 }
Exemplo n.º 4
0
 public Repository(IDatabase database, string tableName, IRedis redis)
 {
     Database     = database;
     TableName    = tableName;
     TableColumns = null;
     Redis        = redis;
 }
Exemplo n.º 5
0
 public Repository(IDatabase database, string tableName, List <TableColumn> tableColumns, IRedis redis)
 {
     Database     = database;
     TableName    = tableName;
     TableColumns = tableColumns;
     Redis        = redis;
 }
Exemplo n.º 6
0
        public void SetUp()
        {
            var connection = new RedisConnection("localhost", dbIndex: 10);
            this.redis = this.redisFactory.CreateRedis(connection);

            this.redis.FlushDB();
        }
Exemplo n.º 7
0
 public TransactionMiner(IBlockChain blockChain, IRedis redis, IWallet wallet, ITransactionPool transactionPool)
 {
     this._IBlockChain      = blockChain;
     this._IRedis           = redis;
     this._IWallet          = wallet;
     this._ITransactionPool = transactionPool;
 }
Exemplo n.º 8
0
 public TicketImpl(HuobiContext db, IRedis redis, IUser user)
 {
     this.m_db      = db;
     this.m_iTicket = this;
     this.m_redis   = redis;
     this.m_user    = user;
 }
Exemplo n.º 9
0
 static CacheManager()
 {
     RunTimeCache = (RunTimeCache)CacheFactory.GetCache("RunTime");
     RedisDefault = (RedisCache)CacheFactory.GetCache("RedisDefault");
     RedisDb      = CacheFactory.GetRedis("RedisDb");
     RedisChat    = CacheFactory.GetRedis("RedisChat");
 }
Exemplo n.º 10
0
 public Resque(IJobCreator jobCreator, IFailureService failureService, IRedis client)
 {
     JobCreator     = jobCreator;
     FailureService = failureService;
     Client         = client;
     Workers        = new List <Worker>();
 }
Exemplo n.º 11
0
        public void SortedSet_Ordered()
        {
            var    cacheKey = Guid.NewGuid().ToString();
            IRedis redis    = ServiceStackRedis.Default;

            var random = new Random();
            var list   = Enumerable.Repeat(0, 4).Select(r => random.Next(100)).ToList();

            list.ForEach(i => redis.SortedSetAdd(cacheKey, i.ToString(), (double)i));

            var list1 = redis.SortedSetRangeByRank(cacheKey, order: Order.Ascending);

            Assert.AreEqual(list1.Length, list.Count);

            var array1 = list.ToArray();

            Array.Sort(array1);
            for (int i = 0; i < list1.Length; i++)
            {
                Assert.AreEqual((Int32)list1[i], array1[i]);
            }

            var list2 = redis.SortedSetRangeByRank(cacheKey, order: Order.Descending);

            Assert.AreEqual(list2.Length, list.Count);

            var array2 = array1.Reverse().ToArray();

            for (int i = 0; i < list2.Length; i++)
            {
                Assert.AreEqual((Int32)list2[i], array2[i]);
            }
        }
Exemplo n.º 12
0
 public ValuesController(IDistributedCache cache, Token token, IConfiguration config, IRedis redis, IArticle articleServer)
 {
     this.m_cache       = cache;
     this.m_token       = token;
     this.m_config      = config;
     m_redis            = redis;
     this.articleServer = articleServer;
 }
Exemplo n.º 13
0
 public RedisBackend(IRedis redisClient, QueuedItem payload, Exception exception, IWorker worker, string queue)
 {
     RedisClient = redisClient;
     Payload     = payload;
     Exception   = exception;
     Worker      = worker;
     Queue       = queue;
 }
Exemplo n.º 14
0
        public Queue(IRedis client, string name)
        {
            Client    = client;
            Name      = name;
            RedisName = string.Format("queue:{0}", name);

            Client.SAdd("queues", name);
        }
Exemplo n.º 15
0
 public static T Add <T>(this IRedis cache, T entity, long db)
 {
     using (var redisClient = Redis.RedisManager.GetPooledRedisClient(db).GetClient())
     {
         var tClient = redisClient.As <T>();
         return(tClient.Store(entity));
     }
 }
Exemplo n.º 16
0
 public static void RemoveById <T>(this IRedis cache, object id, long db)
 {
     using (var redisClient = Redis.RedisManager.GetPooledRedisClient(db).GetClient())
     {
         var tClient = redisClient.As <T>();
         tClient.DeleteById(id);
     }
 }
Exemplo n.º 17
0
 public static IList <T> GetAll <T>(this IRedis cache)
 {
     using (var redisClient = Redis.RedisManager.GetPooledRedisClient().GetClient())
     {
         var tClient = redisClient.As <T>();
         return(tClient.GetAll());
     }
 }
Exemplo n.º 18
0
 public static IList <string> GetAllKeys <T>(this IRedis cache, long db)
 {
     using (var redisClient = Redis.RedisManager.GetPooledRedisClient(db).GetClient())
     {
         var tClient = redisClient.As <T>();
         return(tClient.GetAllKeys());
     }
 }
Exemplo n.º 19
0
 public static T GetById <T>(this IRedis cache, object id, long db)
 {
     using (var redisClient = Redis.RedisManager.GetPooledRedisClient(db).GetClient())
     {
         var tClient = redisClient.As <T>();
         return(tClient.GetById(id));
     }
 }
Exemplo n.º 20
0
 public static IList <T> GetByIds <T>(this IRedis cache, IEnumerable ids, long db)
 {
     using (var redisClient = Redis.RedisManager.GetPooledRedisClient(db).GetClient())
     {
         var tClient = redisClient.As <T>();
         return(tClient.GetByIds(ids));
     }
 }
Exemplo n.º 21
0
 public static void RemoveByIds <T>(this IRedis cache, IEnumerable ids, long db)
 {
     using (var redisClient = Redis.RedisManager.GetPooledRedisClient(db).GetClient())
     {
         var tClient = redisClient.As <T>();
         tClient.DeleteByIds(ids);
     }
 }
Exemplo n.º 22
0
 public static void RemoveAll <T>(this IRedis cache, long db)
 {
     using (var redisClient = Redis.RedisManager.GetPooledRedisClient(db).GetClient())
     {
         var tClient = redisClient.As <T>();
         tClient.DeleteAll();
     }
 }
Exemplo n.º 23
0
 public static void Remove <T>(this IRedis cache, T entity)
 {
     using (var redisClient = Redis.RedisManager.GetPooledRedisClient().GetClient())
     {
         var tClient = redisClient.As <T>();
         tClient.Delete(entity);
     }
 }
Exemplo n.º 24
0
 public static void AddAll <T>(this IRedis cache, IEnumerable <T> entities, long db)
 {
     using (var redisClient = Redis.RedisManager.GetPooledRedisClient(db).GetClient())
     {
         var tClient = redisClient.As <T>();
         tClient.StoreAll(entities);
     }
 }
Exemplo n.º 25
0
 public RedisBackend(IRedis redisClient, QueuedItem payload, Exception exception, IWorker worker, string queue)
 {
     RedisClient = redisClient;
     Payload = payload;
     Exception = exception;
     Worker = worker;
     Queue = queue;
 }
Exemplo n.º 26
0
        public Queue(IRedis client, string name)
        {
            Client = client;
            Name = name;
            RedisName = string.Format("queue:{0}", name);

            Client.SAdd("queues", name);
        }
Exemplo n.º 27
0
 public void Setup()
 {
     calculatorService = container.GetInstance <ICalculator>();
     parserService     = container.GetInstance <IParser>();
     redisService      = container.GetInstance <IRedis>();
     starshipService   = container.GetInstance <IStarship>();
     mapperService     = container.GetInstance <IMapper>();
     logger            = Substitute.For <ILogger>();
 }
Exemplo n.º 28
0
 /// <summary>
 ///
 /// </summary>
 public void Dispose()
 {
     if (_redis == null || _redis.NoClose)
     {
         return;
     }
     _redis.Dispose();
     _redis = null;
 }
Exemplo n.º 29
0
        public void ListTest()
        {
            var         cacheKey   = Guid.NewGuid().ToString();
            IRedis      redis      = ServiceStackRedis.Default;
            var         linkList   = new LinkedList <String>();
            const Int32 listLength = 4;

            Action init = () => {
                redis.KeyDelete(cacheKey);
                linkList.Clear();

                for (int i = 0; i < listLength; i++)
                {
                    var cacheValue = Guid.NewGuid().ToString();

                    if ((Guid.NewGuid().GetHashCode() & 1) == 0)
                    {
                        linkList.AddFirst(cacheValue);
                        //ListLeftPush
                        redis.ListLeftPush(cacheKey, linkList.First.Value);
                    }
                    else
                    {
                        linkList.AddLast(cacheValue);
                        //ListLeftPush
                        redis.ListRightPush(cacheKey, linkList.Last.Value);
                    }
                }
            };

            init();
            Assert.AreEqual(linkList.Count, redis.ListLength(cacheKey));


            for (int i = 0; i < listLength; i++)
            {
                RedisField cacheItem;
                if ((Guid.NewGuid().GetHashCode() & 1) == 0)
                {
                    cacheItem = redis.ListLeftPop(cacheKey);
                    Assert.AreEqual(linkList.First.Value, (String)cacheItem);
                    linkList.RemoveFirst();
                }
                else
                {
                    cacheItem = redis.ListRightPop(cacheKey);
                    Assert.AreEqual(linkList.Last.Value, (String)cacheItem);
                    linkList.RemoveLast();
                }

                Assert.AreEqual(linkList.Count, redis.ListLength(cacheKey));
            }

            var cacheEists = redis.KeyExists(cacheKey);

            Assert.IsFalse(cacheEists);
        }
Exemplo n.º 30
0
 public ArticleImpl(HuobiContext db, IType type, IUser user, IComment comment, IRedis redis)
 {
     this.m_db       = db;
     this.m_iArticle = this;
     this.m_iType    = type;
     this.m_iUser    = user;
     this.m_iComment = comment;
     this.m_redis    = redis;
 }
Exemplo n.º 31
0
 private IRedis CreateClient()
 {
     _redis = IocHelper.Create <IRedis>();
     if (_redis == null)
     {
         throw new Exception("未正确注册Redis对象");
     }
     ChangeDb();
     return(_redis);
 }
Exemplo n.º 32
0
 public ApiController(ILogger<ApiController> logger, IClock clock, IBlockChain blockChain, IRedis redis, IWallet wallet, ITransactionPool transactionPool, ITransactionMiner transactionMiner)
 {
     this._ILogger = logger;
     this._IClock = clock;
     this._IBlockChain = blockChain;
     this._IRedis = redis;
     this._IWallet = wallet;
     this._ITransactionPool = transactionPool;
     this._ITransactionMiner = transactionMiner;
 }
Exemplo n.º 33
0
 /// <summary>
 /// 设置缓存
 /// </summary>
 public static void Set <T>(string cacheType, string key, T value, int Hours = 8640) where T : class, new()
 {
     if (string.Compare(cacheType, CacheType.Web, true) == 0)
     {
         BaseCache.Set <T>(key, value, Hours);
     }
     else if (string.Compare(cacheType, CacheType.Redis, true) == 0)
     {
         IRedis.SetAsy <T>(key, value, Hours);
     }
 }
Exemplo n.º 34
0
        public Worker(IJobCreator locator, IFailureService failureService, IRedis client, params string[] queues)
        {
            JobCreator = locator;
            FailureService = failureService;
            Client = client;

            if(queues == null || queues.Length == 0)
                throw new ArgumentException("Invalid Queues");

            Queues = queues;
        }
Exemplo n.º 35
0
 /// <summary>
 /// 删除缓存
 /// </summary>
 public static void Remove(string cacheType, string key)
 {
     if (string.Compare(cacheType, CacheType.Web, true) == 0)
     {
         BaseCache.Remove(key);
     }
     else if (string.Compare(cacheType, CacheType.Redis, true) == 0)
     {
         IRedis.RemoveAsy(key);
     }
 }
Exemplo n.º 36
0
 public RedisDirectory(IRedis redis, string serviceName,IList<Node> initNodes)
 {
     this.redis = redis;
     this.serviceName = serviceName;
     if (initNodes == null || initNodes.Count == 0)
     {
         this.nodes = helper.LoadLocal(serviceName);
     }
     else
     {
         this.nodes = initNodes;
         helper.Save(initNodes, serviceName);
     }
     this.redis.Subscribe(Refresh, serviceName);
 }
 internal static IServer TryGetServer(IRedis redis, bool checkConnected = true)
 {
     return redis == null ? null : TryGetServer(redis.Multiplexer, checkConnected);
 }
Exemplo n.º 38
0
 public void FixtureSetUp()
 {
    Redis = RedisManager.Configure(c => c.ConnectTo("127.0.0.1", 6379).UsingDatabase(Database)).Redis();
 }
Exemplo n.º 39
0
 public MultiQueue(IRedis client, string[] names)
 {
     Client = client;
     Names = names;
     RedisNames = names.Select(x => string.Format("queue:{0}", x)).ToArray();
 }
Exemplo n.º 40
0
 public ResqueClient(IRedis client)
 {
     Client = client;
 }
Exemplo n.º 41
0
 public RedisBackendFactory(IRedis redisClient)
 {
     RedisClient = redisClient;
 }
Exemplo n.º 42
0
 public RedisSession(IRedis redis)
 {
     _redis = redis;
 }