Using Jedis to develop Redis under Java

Source: Internet
Author: User

about Redis

Redis is an open source, Key-value database that is written in ANSI C language, supports the network, and can be persisted based on memory.

Download the resources needed for development

http://download.csdn.net/detail/wangj1130/9143339

Redis Installation

Unzip the redis-2.6 in the resource into Redis-2.6\bin\release decompression Redisbin64

Redis-server.exe is the Reids service program, you can double-click to run directly. If you run directly, Redis prints a warning:

# warning:no config file specified, using the default Config. In order to specify a config file use redis-server/path/to/redis.conf

This means that you do not specify a Redis profile, Reids uses the default configuration, and you can run Redis by specifying reids.conf from the command line after you configure the environment variable

Jedis use

Jedis-2.1.0.jar and Commons-pool-1.5.6.jar in the new Project introduction resource

Demo

 Public class Jedisdemo {    publicstaticvoid  main (string[] args) {        new Jedis ("127.0.0.1", 6379);        Jedis.connect ();        Jedis.set ("message", "Hello World");        System.out.println (Jedis.get ("message"));        Jedis.quit ();    }}

Using the Redis Connection pool demo

 Public classJedisdemo { Public Static voidMain (string[] args) {jedispoolconfig config=NewJedispoolconfig (); Config.setmaxactive (20); Config.setmaxidle (5); Config.setmaxwait (1000l); Config.settestonborrow (false); Jedispool Jedispool=NewJedispool (config, "127.0.0.1", 6379); Jedis Jedis=Jedispool.getresource (); Jedis.set ("Message", "Hello World"); System.out.println (Jedis.get ("Message"));    Jedis.quit (); }}

Using Jedis to develop Redis under Java

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.