linux install redis complete step

Recently on the linux server need to install redis, to store data, increase the speed of the user access to data, because it is first installed, then I found an article on Baidu, according to this blog successfully installed, thus Bo the main article about cleaning up recording for later use, but also for the need of a friend to provide a convenient,

Reference Bowen address: https: //www.cnblogs.com/lauhp/p/8487029.html

 

installation:

1. Get redis resources

  wget http://download.redis.io/releases/redis-4.0.8.tar.gz

2. Extract

  takes xzvf Redis-4.0.8.tar.gz

3. Install

  cd-repeat 4.0.8

  make

  cd src

  make install PREFIX=/usr/local/redis

4. Move to the installation configuration file directory

  cd ../

  mkdir /usr/local/redis/etc

  mv redis.conf /usr/local/redis/etc

 5. Configure redis to start background

  vi /usr/local/redis/etc/redis.conf // will daemonize no change daemonize yes

6. redis added to the boot

  vi /etc/rc.local // add content in it: / usr / local / redis / bin / redis-server /usr/local/redis/etc/redis.conf (meaning turn calls this turn redis command)

7. Turn redis

  /usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf 

 

8. redis-cli, redis-server copy to bin, so redis-cli instructions can be used directly in any directory

  cp /usr/local/redis/bin/redis-server /usr/local/bin/

  cp /usr/local/redis/bin/redis-cli /usr/local/bin/

 

9. Set redis password

  a. Run the command: redis-cli

  b. Review existing redis password (Optionally, there may be no)

    Run the command: config get requirepass If you do not set your password, then run the result will be as shown below

  c. Set redis password

    Run the command: config set requirepass **** (**** password for you to be set), set up successful will return 'OK' words

  d. Test connector

    Restart redis service

    // (redis-cli -h 127.0.0.1 -p 6379 -a **** (**** password set for you))

    Enter redis-cli command mode, using auth '*****' (**** password you set for the) landing

       

 

Common Commands  

  redis-server /usr/local/redis/etc/redis.conf // start redis

  pkill redis // stop redis

  Uninstall redis:

    rm -rf / usr / local / redis // delete the installation directory

    rm -rf / usr / bin / redis- * // delete all associated command scripts redis

    rm -rf /root/download/redis-4.0.4 // extract the folder to delete redis

 

8- Start redis:

In two ways:

redis-server &

 

加上`&`号使redis以后台程序方式运行

or it could be

 

redis-server

 

9- detect whether there is a background process

 

ps -ef |grep redis

10- 6379 detects whether the port is listening

 

netstat -lntp | grep 6379

Sometimes reported abnormal

The reason: Redis has started

Solution: Turn off Redis, you can restart

 

  1.  
    redis -cli shutdown
  2.  
    redis -server

Then you can see Redis pleasant run.

 

Use redis-cliclient connection is properly detected

 

  1.  
    redis-cli
  2.  
    127.0.0.1:6379> keys *
  3.  
    ( empty list or set)
  4.  
    127.0.0.1:6379> set key "hello world"
  5.  
    OK
  6.  
    127.0.0.1:6379> get key
  7.  
    "hello world"

 

Stop redis:

Using Client

 

redis-cli shutdown

Because the Redis can properly handle the SIGTERM signal, it is also possible to directly kill -9

 

kill -9 PID

 

# Start redis server
$ src / redis-Server
 
 
# start redis client
$ src / redis-cli

 

 

Redis clients for common operations

Redis is a key-value database, supports five data types: string (string), hash (hash), list (list), set (collection) and zset (sorted set: an ordered set).

  • When the value is a string type, including command set get setnx incr del so on.

> Set server: name "fido" // setting key
the OK
> GET Server: // Get the key name
"Fido"
> // SET SETNX Connections 10 Not IF EXISTS
the OK
> incr Connections // atoms values increased value
(integer ) 11
> incr Connections
(Integer) 12
> del Connections // delete Key
(Integer) 1
> incr Connections
(Integer) 1

 

When the value is of type list, including command rpush lpush llen lrange lpop rpop del like.

 

> Rpush friends "Alice" // appended.
(Integer). 1
> RPUSH Friends "Bob"
(Integer) 2
> LPUSH Friends "Sam" // inserted at the beginning
(Integer). 3
 
> Lrange Friends list 0 -1 // Returns subset, similar slicing
. 1) "Sam"
2) "Alice"
. 3) "Bob"
> Lrange Friends 0. 1
. 1) "Sam"
2) "Alice"
> Lrange Friends. 1 2
. 1) "Alice"
2) " Bob "
 
> LLEN Friends // returns a list of length
(Integer) 3
> lpop Friends // Removes and returns the first element of the list
" Sam "
> RPOP Friends // Removes and returns the last element of the list
" Bob "
> lrange Friends 0 - 1
1) "Alice"
 
>del friends // Delete Key
(Integer) 1 // 1 for success and 0 for failure

 

When the value is set types, including command sadd srem sismember smembers sunion del like.

> Sadd superpowers "flight" // add elements
(Integer) 1
> Sadd Superpowers "the X-ray-Vision"
(Integer) 1
> Sadd Superpowers "Reflexes"
(Integer) 1
> Srem Superpowers "Reflexes" // delete elements
1
 
> sismember superpowers "flight" // test whether the element in the collection
(Integer). 1
> sismember Superpowers "Reflexes"
(Integer) 0
> smembers Superpowers // returns a collection of all the elements
. 1) "X-ray Vision"
2) "Flight"
 
> birdpowers Sadd "pecking"
(Integer) 1
> Sadd birdpowers "Flight"
(Integer) 1
> SUNION Superpowers birdpowers // merge multiple set, the return elements merge list
1) "x-ray vision"
2) "flight"
3) "pecking"
 
> del superpowers   // 删除key

(integer) 1

 

When the value is zset type, including command zadd zrange del like, pay attention to a number value for sorting.

> Zadd hacker 1940 "Alan Kay" // value to specify a number, such as in the year 1940 as a number
(Integer) 1
> Zadd Hacker 1906 "Grace Hopper"
(Integer) 1
> Zadd Hacker 1953 "Richard Stallman"
(Integer) 1
> Zadd Hacker 1965 "Yukihiro Matsumoto"
(Integer) 1
> Zadd Hacker 1916 "Claude Shannon"
(Integer) 1
> Zadd Hacker 1969 "Linux Torvalds"
(Integer) 1
> Zadd Hacker 1957 "Sophie Wilson"
(Integer) 1
> Zadd 1912 Hacker "Alan Turing"
(Integer). 1
 
> Z Range the Hacker 2. 4 // returns the ordered set of elements in a slice
. 1) "the Shannon Claude"
2) "Alan Kay"
. 3) "Richard Stallman"
 
> Del hacker // delete key

(integer) 1

 

When the value is a hash type, as will be appreciated dictionary hash type, to specify a value for the field mapping command comprises hset hmset hget hgetall hdel hincrby del like.

 

> Hset user: 1000 name "John Smith" // assign a value to the field, such as name
(Integer) 1
> HSET the User: 1000 Email "[email protected]"
(Integer) 1
> HSET the User: 1000 password " s3cret "
(Integer) 1
> hgetall the User: 1000 // obtain the hash table of all members, including field and value
1)" name "
2)" John Smith "
3)" Email "
4)" [email protected] "
. 5)" password "
. 6)" s3cret "
 
> hmset User: 1001 name" Mary Jones "password" hidden "In Email
" [email protected] "// field and a plurality of value
the OK
> hget User: 1001 // name acquisition value according to Field,
"Mary Jones"
  
> HSET the User:1000 visits 10 // field can be mapped to a digital value
(Integer) 1
> hincrby User: 1000 Visits 1 increased value // value of atom, an increase
(Integer) 11
> hincrby the User: 10 // 1000 Visits increase 10
21 (Integer)
> HDEL the User: 1000 Visits // delete the field and its value
(Integer) 1
> hincrby the User: 1000 Visits 1
(Integer) 1
 
> del the User : 1000 // delete key

(integer) 1

 

Set and view key life cycle, key expiration will be automatically deleted, including expire ttl command and so on.

> The SET Resource: Lock "Redis Demo"
the OK
> The expire Resource: Lock 120 // set life cycle 120s
(Integer) 1
> ttl Resource: Lock // see how much time is left in the current life cycle
(Integer) 109
> ttl Resource: after 120s lock // view, showing returns -2 expired or absent
(Integer) -2
 
> SET Resource: Lock "the Redis Demo 2"
the OK
> TTL Resource: -1 to indicate lock // never expires
(integer) - 1

 

 

 

See if there is above linux install redis, redis start

 

1, detects whether the installation redis-cli and redis-server;

  1.  
    [root @localhost bin]# whereis redis-cli
  2.  
    redis- cli: /usr/bin/redis-cli
  3.  
     
  4.  
    [root @localhost bin]# whereis redis-server
  5.  
    redis- server: /usr/bin/redis-server

 

 

Set redis under Linux system password

Linux set redis the system password:

1, enters the command-line operation redis

Run the command: redis-cli

 

2, view existing redis password (optional, can not)

Run the command: config get requirepass If you do not set your password, then run the result will be as shown below

 

3 , set redis password

Run the command: config set requirepass **** (**** password for you to be set), set up successful will return 'OK' words

 

4, restart the service redis

ctrl + C to exit the current command run from the command line:

redis-cli -h 127.0.0.1 -p 6379 -a **** (**** password for your heart set)

Guess you like

Origin www.cnblogs.com/happywish/p/10944253.html