Install Ubuntu redis

Source: Internet
Author: User
Tags install redis redis server
http://blog.fens.me/linux-redis-install/

Install redis in Ubuntu
 

This article describes how to connect to a nosql database using the R language. Involved nosql products, including redis, MongoDB, hbase, hive, Cassandra, and neo4j. I hope that through my introduction, the majority of R language enthusiasts will have more development choices and make more exciting applications.

 

About

 
  • Conan, Java, R, PHP, and JavaScript
  • Weibo: @ conan_z
  • Blog: http://blog.fens.me
  • Email: [email protected]
 

Reprinted please indicate the source:
Http://blog.fens.me/linux-redis-install/

 

 

Preface

 

Redis is a common memory-based Key-value database, which is more advanced than memcache and supports multiple data structures, which are efficient and fast. Using redis can easily solve high-concurrency data access problems. As a constant monitoring signal, it is also very good.

 

Directory

 
  1. Install redis in Windows
  2. Install redis in Linux Ubuntu
  3. Access redis through the command line Client
  4. Modify redis configurations
1. Install redis in Windows 
 

Installing the redis database on Windows is very simple. Download the executable Installation File (exe) and double-click to install it. : Https://github.com/rgl/redis/downloads

 
  • Redis Server Run Command: redis installation directory/redis-server.exe
  • Redis client Run Command: redis installation directory/redis-cli.exe
2. Install redis in Linux Ubuntu 
 

The Linux system used in this article is Ubuntu 12.04.2 lts 64bit. you can install the redis database package through apt-Get.

 

Install the redis database in Linux Ubuntu

 
# Install the redis server ~ Sudo apt-Get install redis-Server
 

After the installation is complete, the redis server will automatically start. We check the redis server program.

 
# Check the system process of the redis server ~ PS-Aux | grep redisredis 4162 0.1 0.0 10676 1420? SS/usr/bin/redis-server/etc/redis. confconan 4172 0.0 0.0 11064 924 pts/0 S + grep -- color = auto redis # Run the startup command to check the status of the redis server ~ Netstat-nlt | grep 6379tcp 0 0 127.0.0.1: 6379 0.0.0.0: * listen # check the status of the redis server through the startup command ~ Sudo/etc/init. d/redis-server statusredis-server is running
3. Access redis through the command line Client 
 

After the redis server is installed, the redis command line client program is automatically installed together.

 

Enter the redis-CLI command on the local machine to start the service. The client program accesses the redis server.

 
~ Redis-cliredis 127.0.0.1: 6379> # Command Line Help redis 127.0.0.1: 6379> helpredis-cli 2.2.12type: "Help @" to get a list of commands in "Help
 

Basic redis client command operations

 

Add a string record key1

 
# Add a record key1redis 127.0.0.1: 6379> set key1 "hello" OK # print record redis 127.0.0.1: 6379> Get key1 "hello"
 

Add a digital record key2

 
# Add a digital record key2set key2 1ok # Add a number to redis 127.0.0.1: 6379> incr key2 (integer) 2 redis 127.0.0.1: 6379> incr key2 (integer) 3 # print record redis 127.0.0.1: 6379> Get key2 "3"
 

Add a list record key3

 
# Add a list record key3redis 127.0.0.1: 6379> lpush key3 A (integer) 1 # Insert the list from the left redis 127.0.0.1: 6379> lpush key3 B (integer) 2 # insert list redis 127.0.0.1: 6379> rpush key3 C (integer) 3 # print list records in the left-to-right order redis 127.0.0.1: 6379> lrange key3 0 31) "B" 2) "A" 3) "C"
 

Add a hash table record key4

 
# Add a hash table to record key4redis 127.0.0.1: 6379> hset key4 name "John Smith" (integer) 1 # Insert the key and value values of the email into the hash table redis 127.0.0.1: 6379> hset key4 email "[email protected]" (integer) 1 # print the value of redis 127.0.0.1 whose name is key in the hash table: 6379> hget key4 name "John Smith" # print the entire hash table redis 127.0.0.1: 6379> hgetall key41) "name" 2) "John Smith" 3) "email" 4) "[email protected]"
 

Add a hash table record key5

 
# Add a hash table record key5, insert multiple keys and values at a time redis 127.0.0.1: 6379> hmset key5 username antirez password p1pp0 age 3ok # print the hash table, redis 127.0.0.1: 6379> hmet key5 username age1) "antirez" 2) "3" # print the complete hash table record redis 127.0.0.1: 6379> hgetall key51) "username" 2) "antirez" 3) "password" 4) "p1pp0" 5) "Age" 6) "3"
 

Delete record

 
# View all key lists redis 127.0.0.1: 6379> keys * 1) "key2" 2) "key3" 3) "key4" 4) "key5" 5) "key1" # Delete key1, key5redis 127.0.0.1: 6379> Del key1 (integer) 1 redis 127.0.0.1: 6379> Del key5 (integer) 1 # view all keys list redis 127.0.0.1: 6379> keys * 1) "key2" 2) "key3" 3) "key4"
4. Modify the redis Configuration 
 

4.1 access account using redis

 

By default, you do not need a password to access the redis server. To increase security, you need to set an access password for the redis server. Set the access password to redisredis.

 

Use VI to open the configuration file redis. conf of the redis Server

 
~ Sudo VI/etc/redis. conf # uncomment requirepassrequirepass redisredis
 

4.2 remote access to the redis Server

 

By default, the redis server does not allow remote access, but only local access. Therefore, we need to enable the remote access function.

 

Use VI to open the configuration file redis. conf of the redis Server

 
~ Sudo VI/etc/redis. conf # comment bind # bind 127.0.0.1
 

After modification, restart the redis server.

 
~ sudo /etc/init.d/redis-server restartStopping redis-server: redis-server.Starting redis-server: redis-server.
 

Log on to the redis server without a password

 
~ redis-cliredis 127.0.0.1:6379> keys *(error) ERR operation not permitted
 

You can log on, but cannot execute commands.

 

Log on to the apsaradb for redis server and enter the password.

 
~  redis-cli -a redisredisredis 127.0.0.1:6379> keys *1) "key2"2) "key3"3) "key4"
 

After login, everything is normal.

 

Check the network listening port of redis.

 
Check the port occupied by the redis server ~ Netstat-nlt | grep 6379tcp 0 0 0.0.0.0: 6379 0.0.0.0: * listen
 

We can see that the network listener from 127.0.0.1: 3306 to 0 0.0.0.0: 3306 indicates that redis has allowed remote access.

 

We remotely access the redis server in another Linux

 
~ redis-cli -a redisredis -h 192.168.1.199redis 192.168.1.199:6379> keys *1) "key2"2) "key3"3) "key4"
 

Remote Access is normal. Through the above operation, we have installed the redis database server in the Linux Ubuntu system.

 

 

Install Ubuntu redis

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.