Tag: Set Service a color list default value CSharp composite BSP
The previous Redis series has already talked about Redis download, installation, the next one, mainly using the Servicestack.redis provided by Redis, a simple example of how the development library is used as a caching service in a C # project, with little nonsense, directly on the code.
private void Testredis () {var Redis = new Redisclient ("localhost");//Create Redis instance (hostname based on the actual project settings, Can be configured in the form of a configuration file) var records = new List<testinfo> (); /***** operation generic Data *******/if (redis.exists ("Testinfos") <= 0)//Determine if a cache exists {//Add generic collection data Redis.set ("Testinfos", new List<testinfo> () {new TestInfo () {ID = 1, name = "One"}, new TestInfo () {id = 2, name = "$"}, new TestInfo () {id = 3, Name = ""}, New TestInfo () {id = 4, name = "44"}}); Redis.expire ("Testinfos", 60); Set to one-minute expiration} records = Redis.get<list<testinfo>> ("Testinfos"); Gets the Redis cache data//redis.remove ("Testinfos"); Delete a cache//records = redis.get<list<testinfo>> ("Testinfos"); Attempted re-fetch after deletion, result is null (returns NULL when a non-existent reference type is obtained in Redis)/*Operation generic data *******//***** linked list Operation *******/var testredislist = redis.as<testinfo> (); iredislist<testinfo> testData = testredislist.lists["TestData"]; Specify a list of Redis.expire ("TestData", 60); Set to one-minute expiration Testdata.addrange (records); Add Data Testredislist.save (); Save linked list data var testdatalist = redis.as<testinfo> (). lists["TestData"]. ToList (); Get list data/***** linked list operations *******//***** operations int type data *******/if (redis.exists ("Testint") <= 0) {Redis.set ("Testint", 11);//Save slowly data of type int} var recordstr = redis.get& Lt;int> ("Testint"); Obtain Data Redis.remove ("Testint"); Delete a cache var redisintval = redis.get<int> ("Testint"); Attempted re-fetch after deletion, result is 0 (default value is returned when Redis gets a nonexistent value type)/***** operation int type data *******/}
Example of using Redis in Redis series 2-c#