Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The installation process and basic Operation of redis3 in linux

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "redis3 installation process and basic operation of linux". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Redis installation process

[root@hadoop0 opt] # tar-zxvf redis-3.0.5.tar.gz

[root@hadoop0 opt] # cd redis-3.0.5/

[root@hadoop0 redis-3.0.5] # ls-l

[root@hadoop0 redis-3.0.5] # make

[root@hadoop0 redis-3.0.5] # cd src/

[root@hadoop0 src] # make install

Hint: It's a good idea to run 'make test';)

INSTALL install

INSTALL in

[root@hadoop0 src] # cd / usr/local/

[root@hadoop0 local] # mkdir-p / usr/local/redis/bin

[root@hadoop0 local] # mkdir-p / usr/local/redis/etc

[root@hadoop0 local] # mv / opt/redis-3.0.5/redis.conf / usr/local/redis/etc/

[root@hadoop0 src] # mv redis-benchmark redis-check-aof redis-check-dump redis-cli redis-sentinel redis-server redis-trib.rb / usr/local/redis/bin/

[root@hadoop0 bin] # cd / usr/local/bin

[root@hadoop0 bin] #. / redis-server

(note: generate a warning and start in the foreground. If you want to start in the background, modify the redis.conf configuration file: # daemonize yes YES runs as a daemon, NO vice versa)

5436:C 06 Nov 18:51:10.541 # Warning: no config file specified, using the default config. In order to specify a config file use. / redis-server / path/to/redis.conf

5436 Nov 06 it was originally set to 18 51 it was originally set to 10.542 * Increased maximum number of open files to 10032.

5436:M 06 Nov 18:51:10.558 # Warning: 32 bit instance detected but no memory limit set. Setting 3 GB maxmemory limit with 'noeviction' policy now.

_. _

_.-``_'-. _

_.-``` `_. '' -. _ Redis 3.0.5 (00000000Universe 0) 32 bit

.-``.-```. ```\ / _, _'-. _

(',.-`|`,) Running in standalone mode

| | `-. _` -.-`_ _.-.`` -. _ |'` _. -'| Port: 6379 |

| | `-. _`. _ / _. -'| PID: 5436 |

`-. _` -. _ `. /. -'_. -'

| | `-. _ _. -'|

| | `-. _` -. _ _. -'_. -'| http://redis.io |

`-. _` -. _ `. -'_. -'

| | `-. _ _. -'|

| | `-. _` -. _. -'_. -'|

`-. _` -. _ `. -'_. -'

`-. _`. _ _. -'_. -'

`-. _. -'

`-. _. -'

5436:M 06 Nov 18:51:10.562 # WARNING: The TCP backlog setting of 511 cannot be enforced because / proc/sys/net/core/somaxconn is set to the lower value of 128.

5436:M 06 Nov 18:51:10.563 # Server started, Redis version 3.0.5

5436:M 06 Nov 18:51:10.565 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory=1' to / etc/sysctl.conf and then reboot or run the command' sysctl vm.overcommit_memory=1' for this to take effect.

5436 Nov M 06 18 51R 10.567 * The server is now ready to accept connections on port 6379

[root@hadoop0 bin] #. / redis-server.. / etc/redis.conf

(note: startup mode 2: eliminate the warning to start in the foreground. If you want to start in the background, modify redis.conf:#daemonize yes YES to run as a daemon, and vice versa.)

5447 it was originally set to M 06 Nov 18 22 it was originally set to 51.791 * Increased maximum number of open files to 10032.

5447:M 06 Nov 18:52:51.792 # Warning: 32 bit instance detected but no memory limit set. Setting 3 GB maxmemory limit with 'noeviction' policy now.

_. _

_.-``_'-. _

_.-``` `_. '' -. _ Redis 3.0.5 (00000000Universe 0) 32 bit

.-``.-```. ```\ / _, _'-. _

(',.-`|`,) Running in standalone mode

| | `-. _` -.-`_ _.-.`` -. _ |'` _. -'| Port: 6379 |

| | `-. _`. _ / _. -'| PID: 5447 |

`-. _` -. _ `. /. -'_. -'

| | `-. _ _. -'|

| | `-. _` -. _ _. -'_. -'| http://redis.io |

`-. _` -. _ `. -'_. -'

| | `-. _ _. -'|

| | `-. _` -. _. -'_. -'|

`-. _` -. _ `. -'_. -'

`-. _`. _ _. -'_. -'

`-. _. -'

`-. _. -'

Profile description

Configure the redis.conf profile:

# whether to run as a daemon

Daemonize yes

# configure the storage path and file name of pid. Default is the current path.

Pidfile redis.pid

# Redis default listening port

Port 6379

# disconnect after how many seconds the client is idle

Timeout 300

# Log display level

Loglevel verbose

# specify the file name of the log output, or specify to the standard output port

Logfile stdout

# set the number of databases. The default database connection is 0. You can connect different databases through select N.

Databases 16

# policies for saving data to disk

# when a piece of Keys data is changed, refresh to disk once in 900s

Save 900 1

# when 10 pieces of Keys data are changed, refresh to disk once in 300 seconds

Save 300 10

# when 1w pieces of keys data are changed, refresh to disk once in 60 seconds

Save 60 10000

# whether to compress data objects when dump .rdb database

Rdbcompression yes

# File name of the data saved in the dump database

Dbfilename dump.rdb

# working directory of Redis

Dir / home/falcon/redis-2.0.0/

# Replication #

# replication configuration of Redis

# slaveof

# masterauth

# SECURITY #

# requirepass foobared

# LIMITS #

# maximum number of client connections

# maxclients 128

# maximum memory utilization

# maxmemory

# APPEND ONLY MODE #

# whether to enable the log feature

Appendonly no

# rules for refreshing logs to disk

# appendfsync always

Appendfsync everysec

# appendfsync no

# VIRTUAL MEMORY #

# whether to enable the VM feature

Vm-enabled no

# vm-enabled yes

Vm-swap-file logs/redis.swap

Vm-max-memory 0

Vm-page-size 32

Vm-pages 134217728

Vm-max-threads 4

# ADVANCED CONFIG #

Glueoutputbuf yes

Hash-max-zipmap-entries 64

Hash-max-zipmap-value 512

# whether to reset the Hash table

Activerehashing yes

Five Golden Flowers: the Type of five big data

The value value can be a String, hashes, list, sets, and sorted sets.

Commands for value operations

Exists (key): confirm whether a key exists

Del (key): delete a key

Type (key): type of return value

Keys (pattern): returns all key that satisfy a given pattern

Randomkey: one of the randomly returned key spaces

Keyrename (oldname, newname): rename key

Dbsize: returns the number of key in the current database

Expire: set the active time of a key (s)

Ttl: get the active time of a key

Select (index): query by index

Move (key, dbindex): move the key in the current database to the dbindex database

Flushdb: deletes all key in the currently selected database

Flushall: delete all key in all databases

Commands for String operations

Set (key, value): assigns the value value to the string named key in the database

Get (key): returns the value of the string named key in the database

Getset (key, value): assign the last value to the string named key

Mget (key1, key2, … , key N): returns the value of multiple string in the library

Setnx (key, value): add string with the name key and the value value

Setex (key, time, value): add string to the library and set the expiration time time

Mset (key N, value N): set the values of multiple string in batch

Msetnx (key N, value N): if all string named key I do not exist

Incr (key): string add 1 operation named key

Incrby (key, integer): string named key adds integer

Decr (key): string minus 1 operation named key

Decrby (key, integer): string named key reduces integer

Append (key, value): the value of the string named key is appended to value

Substr (key, start, end): returns the substring of the value of string with the name key

Commands for List operations

Rpush (key, value): add an element with the value value to the end of the list named key

Lpush (key, value): add an element with a value of value to the list header named key

Llen (key): returns the length of the list named key

Lrange (key, start, end): returns the element between start and end in the list named key

Ltrim (key, start, end): intercept list named key

Lindex (key, index): returns the element of the index location in the list named key

Lset (key, index, value): assign a value to the element of index position in the list named key

Lrem (key, count, value): delete the element whose value is value in the list of count key

Lpop (key): returns and deletes the first element in the list named key

Rpop (key): returns and deletes the tail element in the list named key

Blpop (key1, key2, … Key N, timeout): the block version of the lpop command.

Brpop (key1, key2, … Key N, timeout): the block version of rpop.

Rpoplpush (srckey, dstkey): returns and deletes the trailing element of the list named srckey and adds it to the header of the list named dstkey

Commands for Set operations

Sadd (key, member): add the element member to the set named key

Srem (key, member): deletes the element member in the set named key

Spop (key): randomly returns and deletes an element in the set named key

Smove (srckey, dstkey, member): move to a collection element

Scard (key): returns the cardinality of the set named key

Sismember (key, member): whether member is an element of set named key

Sinter (key1, key2, … Key N): find the intersection

Sinterstore (dstkey, (keys)): find the intersection and save the intersection to the collection of dstkey

Sunion (key1, (keys)): Union set

Sunionstore (dstkey, (keys)): join and save the union to the collection of dstkey

Sdiff (key1, (keys)): subtraction set

Sdiffstore (dstkey, (keys)): take the difference set and save the difference set to the collection of dstkey

Smembers (key): returns all elements of a set named key

Srandmember (key): randomly returns an element of set with the name key

Commands for Hash operations

Hset (key, field, value): add the element field to the hash named key

Hget (key, field): returns the value corresponding to field in the hash named key

Hmget (key, (fields)): returns the value corresponding to field I in the hash named key

Hmset (key, (fields)): add the element field to the hash named key

Hincrby (key, field, integer): add integer to the value of field in the hash named key

Hexists (key, field): whether there is a domain with the key field in the hash named key

Hdel (key, field): delete the domain with the key field in the hash named key

Hlen (key): returns the number of elements in a hash named key

Hkeys (key): returns all keys in the hash with the name key

Hvals (key): returns the value of all keys in the hash named key

Hgetall (key): returns all keys (field) and their corresponding value in the hash named key

Small example:

# start the Redis client tool under the Shell command line.

Command line connection parameters

Redis-cli parameter

Usage: redis-cli [OPTIONS] [cmd [arg [arg...]

-h Server hostname (default: 127.0.0.1)

-p Server port (default: 6379)

-s Server socket (overrides hostname and port)

-a Password to use when connecting to the server

-r Execute specified command N times

-I When-r is used, waits seconds per command.

It is possible to specify sub-second times like-I 0.1

-n Database number

-x Read last argument from STDIN

-d Multi-bulk delimiter in for raw formatting (default:\ n)

C Enable cluster mode (follow-ASK and-MOVED redirections)

-- raw Use raw formatting for replies (default when STDOUT is not a tty)

-- latency Enter a special mode continuously sampling latency

-- slave Simulate a slave showing commands received from the master

-- pipe Transfer raw Redis protocol from stdin to server

-- bigkeys Sample Redis keys looking for bigkeys

-- eval Send an EVAL command using the Lua script at

-- help Output this help and exit

-- version Output version and exit

/ > redis-cli

# clear the currently selected database to facilitate understanding of the following examples.

Redis 127.0.0.1 6379 > flushdb

OK

# add simulation data of String type.

Redis 127.0.0.1 6379 > set mykey 2

OK

Redis 127.0.0.1 hello 6379 > set mykey2 "hello"

OK

# add simulation data of Set type.

Redis 127.0.0.1 6379 > sadd mysetkey 12 3

(integer) 3

# add simulation data of Hash type.

Redis 127.0.0.1 stephen 6379 > hset mmtest username "stephen"

(integer) 1

# get all the key in the current database that conforms to the schema according to the schema in the parameter. As you can see from the output, the command does not distinguish between the types of Value associated with Key when executed.

Redis 127.0.0.1 6379 > keys my*

1) "mysetkey"

2) "mykey"

3) "mykey2"

# two Keys have been deleted.

Redis 127.0.0.1 6379 > del mykey mykey2

(integer) 2

# check whether the Key just deleted still exists. From the returned result, mykey has indeed been deleted.

Redis 127.0.0.1 6379 > exists mykey

(integer) 0

# check the Key that has not been deleted to compare with the results of the above command.

Redis 127.0.0.1 6379 > exists mysetkey

(integer) 1

# move the mysetkey key from the current database to the database with ID 1, and you can see from the result that the move has been successful.

Redis 127.0.0.1 6379 > move mysetkey 1

(integer) 1

# Open the database with ID 1.

Redis 127.0.0.1 6379 > select 1

OK

# check whether the Key just moved exists. From the returned result, it already exists.

Redis 127.0.0.1 redis [1] > exists mysetkey

(integer) 1

# reopen the default database with ID 0.

Redis 127.0.1 6379 [1] > select 0

OK

# check whether the Key you just removed no longer exists. From the returned result, you can see that it has been removed.

Redis 127.0.0.1 6379 > exists mysetkey

(integer) 0

# prepare new test data.

Redis 127.0.0.1 hello 6379 > set mykey "hello"

OK

# rename mykey to mykey1

Redis 127.0.0.1 6379 > rename mykey mykey1

OK

# since mykey has been renamed, getting it again will return nil.

Redis 127.0.0.1 6379 > get mykey

(nil)

# get it through the new key name.

Redis 127.0.0.1 6379 > get mykey1

"hello"

# because mykey no longer exists, an error message is returned.

Redis 127.0.0.1 6379 > rename mykey mykey1

(error) ERR no such key

# prepare to test key for renamenx

Redis 127.0.0.1 hello 6379 > set oldkey "hello"

OK

Redis 127.0.0.1 world 6379 > set newkey "world"

OK

# the command could not be executed successfully because newkey already exists.

Redis 127.0.0.1 6379 > renamenx oldkey newkey

(integer) 0

# check the value of newkey and find that it is not overwritten by renamenx.

Redis 127.0.0.1 6379 > get newkey

"world"

# Test data prepared for the following example.

Redis 127.0.0.1 hello 6379 > set mykey "hello"

OK

# set the timeout of the key to 100 seconds.

Redis 127.0.0.1 6379 > expire mykey

(integer) 1

# use the ttl command to see how many seconds are left.

Redis 127.0.0.1 6379 > ttl mykey

(integer) 97

# execute the persist command immediately, and the key that has timed out becomes the persistent key, that is, the timeout of the Key is removed.

Redis 127.0.0.1 6379 > persist mykey

(integer) 1

The return value of # ttl tells us that the key has not timed out.

Redis 127.0.0.1 6379 > ttl mykey

(integer)-1

# prepare data for subsequent expire commands.

Redis 127.0.0.1 6379 > del mykey

(integer) 1

Redis 127.0.0.1 hello 6379 > set mykey "hello"

OK

# set the timeout of the key for 100 seconds.

Redis 127.0.0.1 6379 > expire mykey

(integer) 1

This is the end of the content of "redis3 installation process and basic Operation in linux". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report