Redis Installation and use

Source: Internet
Author: User
Tags redis xmlns
installation under CentOS

-Download Compressed package wget Installation

CD redis-3.2.6 make

&& make install
redis-server/etc/redis.conf #启动时指定配置文件

CP Redis-benchmark REDIS-CLI redis-server/usr/bin/
This will not be implemented with the addition of the./, and can be anywhere to perform test Redis

[Root@localhost redis-3.2.6]# redis-cli> set name Hi
OK> get Name
Turn off Redis Services
REDIS-CLI shutdown use in spring maven Dependency
      <artifactId> spring-data-redis</artifactid>
XML Configuration

On the internet to see a circle, are configured with annotations, usually these configuration code like to use XML style, configure

<?xml version= "1.0" encoding= "UTF-8"?> <beans xmlns= "Http://" Xmlns:xs I= "Http://" xsi:schemalocation= "Http:// Http:// "> <bean id=" poolconfig "class=" Redis.clients.jedis.JedisPoolConfig "/> <bean id=" jedisconnectionfactory "class=" "> <property name=" HostName "Val Ue= ""/> <property name= "port" value= "6379"/> <property name= "password" value= "xxx"/ > <property name= "poolconfig" ref= "Poolconfig"/> </bean> <bean id= "Stringredisseriali Zer "class=" "/> <bean id=" Redistemplate " class= "" > <property name= "ConnectionFactory" ref= "jedisconnectionfactory"/> <property name= "Keyserializer" ref= "stringRedisSerial Izer "/> </bean> </beans>

How to work with Redis

Import org.springframework.beans.factory.annotation.Autowired;

Import org.springframework.stereotype.Component;
Import Java.util.HashMap;
Import Java.util.Map;

Import Java.util.concurrent.TimeUnit;
 /** * Created on 2017/1/25.

    */@Component public class Redishandler {@Autowired private redistemplate<string,object> redistemplate;
    Public Object GetValue (final String key) {return Redistemplate.opsforvalue (). get (key); 
        The public void SetValue (final String key,final string value) {Redistemplate.opsforvalue (). Set (Key,value);
    Redistemplate.expire (key,1, timeunit.seconds);
        public void SetHi (final Hi user) {final String key = String.Format ("hi:%s", User.getid ());

        Final map< string, object > Properties = New hashmap< String, Object > (); Properties.put ("id", User.getId ());
        Properties.put ("Name", User.getname ());
        Properties.put ("msg", user.getmsg ());

        Properties.put ("num", User.getnum ());
    Redistemplate.opsforhash (). Putall (Key, properties);

        Public Hi Gethi (final int id) {Final String key = String.Format ("hi:%s", id);
        Final String name = (string) redistemplate.opsforhash (). Get (Key, "name");
        Final Integer num = (integer) redistemplate.opsforhash (). Get (Key, "num");

        Final String msg = (string) redistemplate.opsforhash (). Get (Key, "MSG");
    return new Hi (ID, name, num,msg); }


You can then use the protected mode

about redis.conf

Redis.clients.jedis.exceptions.JedisDataException:DENIED Redis is running in protected mode because protected mode is ENA Bled, no bind address was Specified,no Authentication password are requested to clients.
 The This mode connections is only accepted from the loopback interface. If you want-to-connect from external computers to Redis-adopt one of the following solutions:1) Just disable PR otected mode sending the command ' CONFIG SET protected-mode No ' from the loopback interface by connecting to Redis from th E same host The server is running, however make sure Redis are not publicly accessible from the Internet if your do so.
 Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the PROTECTE 
 d mode option to ' No ', and then restarting the server. 
 3) If You started the server manually just for testing, restart it with the '--protected-mode no ' option. 4) Setup a bind AddreSS or an authentication password. Note:you only need to does one of the above things in order for the server to start accepting connections from the outside .

If this is the case, the Redis default has a protected mode yes. Other machines in this mode are not connected, only the bind IP can be connected. Set it to no, then comment out the bind machine and set the Requiredpass, And then you can connect the

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: 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.