Redis configuration and test access through C #

Source: Internet
Author: User

First, install a Ubuntu Virtual Machine to install redis. Ubuntu unity is stuck in the virtual machine. You can install the traditional gnome interface as follows:

Sudo aptitude install gnome-session-Fallback

After the installation is complete, you can select the gnome interface at the logon location.

Redis compilation and installation in Linux is very simple. Access redis. Io to obtain the stable version of the source code. Redis-2.8.13.tar.gz

After the download is complete, run the following command:

Tar xzf redis-2.8.13.tar.gz

CD redis-2.8.13

Make

Sudo make install

 

Make install will copy the compiled program to/usr/local/bin. Execute Command

Redis-server can start the redis server. The default port is 6379. You can test it with the built-in client,

[Email protected]: ~ $ Redis-cli-H 127.0.0.1-P 6379
127.0.0.1: 6379> Ping
Pong

127.0.0.1: 6379> set Bar 1
OK
127.0.0.1: 6379> keys *
1) "bar"
127.0.0.1: 6379> exists bar
(Integer) 1
127.0.0.1: 6379> exists n
(Integer) 0
Wagner. 0.0.1: 6379> del bar
(Integer) 1

OK. Everything is normal.

 

There are various languages on the http://redis.io/clients page client, C # there are also a lot of, more commonly used is servicestack. redis, this client can be in nuget or get, can also be downloaded from GitHub.

After the dependencies are installed, you can write a simple C # program to test the virtual machine's IP address is 192.168.79.128:

class Program    {        static void Main(string[] args)        {            var client = new RedisClient("192.168.79.128", 6379);            client.Set<string>("user", "HelloRedis");            client.Set<int>("Age", 23);            Console.WriteLine("Getting Data from Redis \r\n Name:{0}; Age:{1}.",                client.Get<string>("user"), client.Get<int>("Age"));            Console.ReadLine();        }    }

 

Output result:

Go back to the VM and check the redis service:

[Email protected]: ~ $ Redis-cli-H 127.0.0.1-P 6379
127.0.0.1: 6379> keys *
1) "Age"
2) "user"

More to learn e ......

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.