Approaching Redis (i)--redis installation and basic key operation

Source: Internet
Author: User
Tags redis server

Redis is an open-source NoSQL key-value storage System. Redis is often mentioned with MemCache , but compared to MemCache ,redis is a database that can persist data, while Redis The data structure is rich--string, hash, list, set, sorted set.

1. Install and start Redis:

[Email protected] ~]# cd/usr/local/src[[email protected] src]# wget http://download.redis.io/releases/ Redis-3.0.0.tar.gz[[email protected] src]# tar-zxf redis-3.0.0.tar.gz

Unlike most other software that is compiled and installed, Redis has done ./configure, so direct make&& make install :

[Email protected] src]# CD Redis-3.0.0[[email protected] redis-3.0.0]# makezmalloc.h:50:31:error:jemalloc/jemalloc.h : No such file or directoryzmalloc.h:55:2:error: #error "Newer version of Jemalloc required" make[1]: ***[ADLIST.O] Error 1

through the error message is not difficult to find,jemalloc version is too low, with the Yum command installation:

[email protected] redis-3.0.0]# yum install-y jemalloc-devel[[email protected] redis-3.0.0]# MAKECC:.. /deps/hiredis/libhiredis.a:no such file or DIRECTORYCC:.. /deps/lua/src/liblua.a:no such file or DIRECTORYCC:.. /deps/jemalloc/lib/libjemalloc.a:no such file or directorymake[1]: ***[redis-server] Error 1[[email protected] redis-3.0.0]# yum install-y hiredis-devel[[email protected] redis-3.0.0]# yum install-y lua-devel

after installing these libraries, if the same No such file or directory error is still reported under the PWD directory , it can be resolved by re- compiling the Redis source package again:

[Email protected] src]# tar-zxf redis-3.0.0.tar.gz-c/usr/local/[[email protected] src]# Cd/usr/local/redis-3.0.0[[em AIL protected] redis-3.0.0]# makehint:it ' s agood idea-to-run ' make test ';) make[1]: leavingdirectory '/usr/local/redis-3. 0.0/src '

The above information indicates that the compilation installation was successful, at which point we need to use a binary file located under/usr/local/redis-3.0.0/src/, respectively:

(1)Redis-benchmark -- for redis performance Testing

(2)redis-check-aof -- tools for checking the AOF log

(3)redis-check-dump -- tools for checking the RBD log

(4)redis-server -- redis Server process

(5)redis-cli -- redis client Process

(6)Redis-sentinel -- Soft link file, soft link to redis-server

of course, for convenience, we can also install these binaries separately in other directories (here PREFIX need to use uppercase):

[[email protected] redis-3.0.0]# make install Prefix=/usr/local/redis[[email protected] redis]# Ls/usr/local/redis/bin /redis-benchmark redis-check-dump redis-sentinelredis-check-aof redis-cli redis-server

This allows all of our available binaries to be moved to the specified directory. Also for easy configuration, copy a Redis profile to the installation directory:

[Email protected] redis]# cp/usr/local/redis-3.0.0/redis.conf.

in this way, we can start with the following command Redis server , the following ./redis.conf Specifies that the Redis server is using the redis.conf configuration file under the current directory:

[Email protected] redis]# bin/redis-server./redis.conf

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/6C/3F/wKioL1VCTLmRHfOmAAHumJzWmUA081.jpg "title=" Redis.png "alt=" Wkiol1vctlmrhfomaahumjzwmua081.jpg "/>

Figure -1 Redis Boot Success page

if the command runs after 1 , it indicates a successful start. The default port for Redis is 6379. At this point, open a new shelland use the following command to connect to the Redis server using a redis client :

[Email protected] ~]#/usr/local/redis/redis-cli-h 127.0.0.1-p 6379

where-h specifies the Redis server IP ,-p specifies the Redis server port. If not explicitly specified, the 127.0.0.1:6379 is connected . After the command executes, the following line appears to indicate that the connection was successful:

127.0.0.1:6379>

If you want to close Redis Server, use the following command:

[Email protected] ~]#/usr/local/redis/bin/redis-cli-h 127.0.0.1-p6379 shutdown

2.Redis Operation Key :

Use the following command on the Redis Client command line to operate on key :

(1) Increase and check Key-value:

127.0.0.1:6379> set name lucyok127.0.0.1:6379> get Name "Lucy" 127.0.0.1:6379> set sex female127.0.0.1:6379> Set Job nurse127.0.0.1:6379> keys *//Three regular match symbols can be used, *? [] 1) "Job" 2) "Sex" 3) "name" 127.0.0.1:6379> keys n?me1) "name" 127.0.0.1:6379> keys j[abco]b1) "Job"

(2 ) Delete key:

127.0.0.1:6379> del Job (integer) 1//return 1 indicates successful operation, return 0 indicates operation failed

(3) change key:

127.0.0.1:6379> set sex maleok127.0.0.1:6379> rename sex personsex//Whether or not Personsex is present, renaming will succeed ok127.0.0.1:6379 > Renamenx personsex Name//renamenx = Rename if new name does Notexist, that is, there will be no overwrite of the original Key-value (integer) 0//Return 1 indicates successful operation, Returns 0 indicates that the operation failed 127.0.0.1:6379> renamenx sex personsex (integer) 1//returns 1 indicating that the operation was successful and returning 0 indicates that the operation failed

(4) move key:

Redis has three storage spaces by default, which can be easily understood as the number of sheets, numbered 0-16. By default, all Key-value are located under 0 tables and can be moved to the specified numbered table using the Move command, which selects the table with the specified number:

127.0.0.1:6379> move name 1 (integer) 1127.0.0.1:6379> keys *) "Sex" 127.0.0.1:6379> Select 1ok127.0.0.1:6379[1 ]> keys *) "name"

(5) return random key:

127.0.0.1:6379> randomkey "name" 127.0.0.1:6379> randomkey "name" 127.0.0.1:6379> randomkey "Sex"

(6) whether the corresponding key exists:

127.0.0.1:6379> exists name (integer) 1//return 1 means present, return 0 means no 127.0.0.1:6379> exists person (integer) 0//return 1 indicates existence, Returns 0 indicating that there is no

(7) determine the type of key:

127.0.0.1:6379> type namestring127.0.0.1:6379> type Jobnone

the possible types are string, list, set, order set, hash, or none if key does not exist.

(8) query The key declaration period in seconds:

127.0.0.1:6379> ttl name (integer)-1//return-1 means permanent, return-2 means that key does not exist, and return n means n seconds expires 127.0.0.1:6379> ttl person (integer)- 2

to use in milliseconds, use the pttl command.

(9) set the key declaration period in seconds:

127.0.0.1:6379> expire name (integer) 1127.0.0.1:6379> ttl name (integer) 12

to use in milliseconds, use the pttl command.

(ten) to make the key permanently effective:

127.0.0.1:6379> expire name (integer) 1127.0.0.1:6379> persist name (integer) 1127.0.0.1:6379> ttl name ( Integer)-1


This article is from the "barrel of fake dog excrement" blog, please be sure to keep this source http://xitongjiagoushi.blog.51cto.com/9975742/1641138

Approaching Redis (i)--redis installation and basic key operation

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.