Redis Basic installation and configuration detailed
1. Installation
wget http://download.redis.io/releases/redis-3.2.3.tar.gz
Compile Installation:
Tar XF redis-3.2.3.tar.gz
CD redis-3.2.3
Make && make install
Configuration:
Mkdir/etc/redis set up configuration file storage directory
CP-A redis.conf/etc/redis/6379.conf Replication configuration file
CP-A Utils/redis_init_script/etc/init.d/redis Replication Startup script
Mkdir-p/home/redis-home set up a data storage directory
ip= ' IP addr show eth0 | grep eth0 | grep inet | Cut-d ""-F 6 | Cut-d "/" F 1 ' Get interface IP
Sed-i "S/^bind.*$/bind 127.0.0.1 $ip/"/etc/redis/6379.conf Configure bind bind IP addresses
Sed-i ' s/^daemonize no/daemonize yes/'/etc/redis/6379.conf configuration boot to Yes
Sed-i ' S/^dir. \//dir \/home\/redis-home/'/etc/redis/6379.conf configuration data storage file for the established Redis-home directory
Sed-i ' 3i# chkconfig:-14\n# descript:redis init script '/etc/init.d/redis config boot file add chkconfig description
Start:
Chkconfig--add redis configuration Reids Join boot
Chkconfig redis on configuration Redis boot
Service Redis Start Redis
Dbsize Test Redis is working properly
Service Redis stop shutdown Redis
2.redis.conf
Daemonize Yes if the program runs later, the default no
Pidfile/var/run/redis.pid background running, need to develop PID
Port 6379 Default Listener 6379
Timeout 0 Link Timeout
LogLevel Notice log level, debug,verbose,notice,warning
LogFile "" "Output log file, ' stdout ' flag output, if later run, output to/dev/null
# syslog-enabled no output to the system log
# syslog-ident Redis System log Identifier
# syslog-facility Local0
Databases 16 set the number of databases
Save 900 1
Save 300 10
Save 60 10000 over 900s and 1 keys change, the Save action is triggered
Rdbcompression Yes to compress data when storing data, default Yes
Dbfilename Dump.rdb Save the file name of the dump data
Dir./working directory, must be a directory rather than a file
Slaveof <masterip> <masterport> slaveof to set one Redis instance to another redis from the library
Masterauth <master-password>
Slave-serve-stale-data Yes
# requirepass foobared Specify password login required
# maxclients 10000 Connection maximum limit, recommended No limit
# maxmemory <bytes> Use maximum memory limit, recommended not limited
# maxmemory-policy noeviction Default configuration: Volatile-lru: Use the lrunning algorithm to remove the previous set, ALLKEYS-LRU delete any lru that follows the key,volatile-random algorithm, Randomly delete the expired set of key,allkeys-random, randomly delete a key,volatile-ttl, delete the recently expiring key.noeviction, do not expire at all, write an error
AppendOnly No when this mode is turned on, each action is recorded in the Appendonly.aof file and read into memory to rebuild the database when the Redis is restarted
Appendfilename "Appendonly.aof"
# Appendfsync Always
Appendfsync everysec
# Appendfsync No No: Fsync, just notify the OS can flush data, specifically whether flush depends on the OS. Better performance.
Always: Every time you write a append only log file, you will fsync. Poor performance, but very safe.
Everysec: No interval of 1 seconds for a fsync. Compromise
No-appendfsync-on-rewrite No
Auto-aof-rewrite-percentage 100
Auto-aof-rewrite-min-size 64MB append only file for automatic rewrite, for 0 o'clock off rewrite,
Slowlog-log-slower-than 10000 negative, then closing slow log,0 will cause each command to be logged
Slowlog-max-len 128
Redis CLUSTER
Redis Basic Data type
String Redis is the most basic type, can be any type of string, or it can be a numeric
Set assignment, usage: set key value
Get value, use: get key
INCR increment number, only useful for numeric type keys, equivalent to Java i++ operation, usage: INCR key< br> Incrby Add the specified number, only for numeric types of keys useful, equivalent to the Java i+=3, usage: Incrby key increment, meaning that the key from the increment,increment can be negative, indicating a decrease.
Decr Descending numbers, only useful for numeric type keys, equivalent to Java I-Compact, usage: DECR key
Decrby reduce specified numbers, only useful for numeric type keys, equivalent to Java i-=3, usage: Decrby key decrement , meaning that the key decrement,decrement can be positive, indicating an increase. The
Incrbyfloat increases the specified floating-point number, which is useful only for numeric types of keys: Incrbyfloat key increment
APPEND append values to the tail, equivalent to "Hello" in Java. APPEND ("World") , Usage: APPEND key value
STRLEN get string length, usage: STRLEN key
Mset Set the value of multiple keys at the same time, use: Mset key1 value1 [Key2 value2 ...]
Mget Gets the value of more than one key at a time, using: Mget Key1 [Key2 ...]
hash A collection of multiple key-value pairs that can be used to store objects, equivalent to the hashmap<string,string> in Java;
Hset Assignment, Usage: Hset key field value
Hmset assign multiple fields at once, use: Hmset key field1 value1 [field2 values]
Hget values, usage: Hset ke Y field
Hmget The value of multiple fields at one time, using: Hmset key field1 [Field2]
Hgetall The value of all fields at once, using: Hgetall key
Hexists determine if the field exists, usage: H EXISTS key field
Hsetnx assignment when the field does not exist, use: Hsetnx key field value
Hincrby to add numbers, only useful for numeric type values, usage: Hincrby key field Increme NT
Hdel Delete field, usage: Hdel key field
Hkeys get all field names, usage: Hkeys key
Hvals get all field values, usage: hvals key
Hlen Get number of fields, usage: HL EN key
List doubly linked list
Lpush adds an element to the left end of the list, using: Lpush key value
Rpush adds an element to the right end of the list using: Rpush key value
Lpop eject the element from the left end of the list, use: Lpop key
Rpop from column Table right-side pop-up elements, usage: Rpop key
Llen Get the number of elements in the list, use: Llen key
Lrange Get the elements of a fragment in the list, use: Lrange key start stop, index starting from 0,-1 for the last Element
Lrem Deletes the value specified in the list, using: Lrem key count value to delete the element with value of the previous count value in the list, when Count>0 starts at the left, and count<0 from the right, count= 0 o'clock deletes all elements of value
Lindex gets the element value of the specified index, usage: lindex key index
LSET sets the element value for the specified index, using: LSET key index value
LTRIM only keep the list Set fragment, Usage: LTRIM key start Stop, contains the start and stop
Linsert insert elements in the list, usage: Linsert key before| After Privot value, start looking for the first element with a value of privot from the left, and then before or after the second argument to insert value
before or after the element Rpoplpush To escape an element from a list to another list, use: Rpoplpush source destination
set Internal implementation is a value-null HashMap, equivalent to hashset< in Java String>
Sadd add elements, Usage: Sadd key value1 [value2 value3 ...]
Srem Delete element, usage: Srem key value2 [value2 value3 ...]
Smembers gets all the elements in the collection, using: Smembers key
Sismember Determines whether the element is in the collection, Usage: Sismember key value
Sdiff sets the set to do differential operation, usage: Sdiff key 1 Key2 [Key3 ...], first compute the key1 and key2 difference set, and then use the result and the Key3 do the difference set
Sinter the set to do the intersection operation, use: Sinter key1 Key2 [Key3 ...] The
Sunion the set to do a set operation, using: Sunion key1 key2 [Key3 ...]
SCard Gets the number of elements in the collection, using: SCard key
Sdiffstore sets the set and stores the result: Sdiffstore destination key1 Key2 [Key3 ...] The
Sinterstore the collection and stores the results, using: Sinterstore destination key1 Key2 [Key3 ...] The
Sunionstore the set and stores the results, using: Sunionstore destination key1 Key2 [Key3 ...]
Srandmember randomly gets the elements in the collection, using: Srandmember key [Count], when Count>0, gets the count of the elements in the collection randomly, and when count<0, the random collection gets the | Count| and elements that may be duplicated.
Spop randomly pops an element from the collection using: Spop key
Sorted set ordered set type
Zadd add elements, Usage: Zadd key score1 value1 [score2 value2 score3 value3 ...]
Zscore gets the fraction of the element, using: Zscore key value
Zrange Gets the element that is ranked in a range: Zrange key start Stop [Withscore], sorted by element in order from small to large, starting at 0 Number that contains the element for start and stop, and the Withscore option indicates whether the element score is returned
Zrevrange gets the element ranked in a range, using: Zrevrange key start Stop [Withscore], Same as the previous command usage, just this sort of reverse order. The
Zrangebyscore gets the elements within the specified fraction range, using: Zrangebyscore key min Max, which contains Min and Max, (min means not including min, Max means no Max, +inf represents Infinity
ZIN Crby adds a fraction of an element, using: Zincrby key increment value
Zcard Gets the number of elements in the collection, usage: Zcard key
Zcount Gets the number of elements in the specified fraction range, usage: Zcount key Min Max, min and Max's usage is the same as in 5.
Zrem deletes one or more elements, usage: Zrem key value1 [value2 ...]
Zremrangebyrank deletes elements according to the rank range, usage: Zremrangebyrank key start stop
Zremrangebyscore deletes elements by fraction range, usage: zremrangebyscore The use of key min Max, Min and Max is the same as in 4
Zrank gets the ranking of the elements of a positive order, using: Zrank key value
Zrevrank gets the ranking of the elements in reverse order: Zrevrank key value< /p>