- Redis Installation
You need to obtain the Redis installation package before you install it. Here we do not detail the installation package. Here Redis-x64-3.2.100.zip installation package is an example of a DOS command to get the installation directory.
Enter Redis-server--service-install redis.windows-service.conf--loglevel verbose on the command line
So the Redis service is installed.
2. Redis Stop
Redis-server--service-stop
3. Redis Boot
Redis-server--service-start
4. Setting the port and password
Modify the port and Requirepass fields in the redis.windows-service.conf file, and then restart the Redis
5. Client Connection Test
Redis-cli-h 127.0.0.1-p 5379-a Password
6. Use Redis in ASP. First we create the project Redis.demo.
1), add Reference Stackexchange.redis using the NuGet management package
2), the Connectionmultiplexer object is the most central object of the Stackexchange.redis. Instances of this class need to be shared and reused throughout the application domain, and it is necessary to use Singleton to create and store this object. Lock (Locker)
{
Do not create links if content exists
if (Redisconnect = = null)
Redisconnect = GetManager ();
}
3), in the message formation, the important concept is the producer, the consumer, the message middleware.
First, get a Isubscriber object first. On the producer side we post a message:
Sub = Redisconnect.getsubscriber ();
Channel name
var mychannel = "Demo";
Publish a message
Sub. Publish (MyChannel, "Hello word!");
Subscribe to a channel named demo
Sub. Subscribe (MyChannel, (channel, message) =
{
Output subscription data after receiving a subscription message
Console.WriteLine (message);
});
4), the in-memory database uses
var reidsdb=redisconnect.getdatabase (1);
The DB object returned here Getdatabase () is very lightweight and does not need to be cached, each time it is taken.
Writing data to the Redis database key value
Redisdb. Stringset ("Test1", "Hello word!");
Querying data in a Redis database key
var mes = Redisdb. Stringget ("Test1");
Output data
Console.WriteLine (Mes. ToString ());
5), the simple case of using Redis in ASP. Here is the end, the specific code such as
Run this program we can get the following output
7. Summary: Redis is an open source. High performance. Cache and storage systems based on key-value pairs provide multiple key-value data types to accommodate cache and storage requirements in different scenarios. At the same time, many of the high-level features of Redis are used for different roles in Message Queuing and task queues.
This digest self-intelligent Car Core official website: http://www.thinkobd.cn/
Using Redis in ASP. "This digest self-knowledge car core website"