Key-value Database Redis

Source: Internet
Author: User
Tags redis redis version install redis

Redis is a representative of the Key-value database in the open source NoSQL, developed in C language, followed by BSD License. Supports memory, disk persistence storage, and it has a very rich data type, including strings, linked lists, ordered collections, and so on. High availability comes with a master-slave architecture, and cluster functionality is being developed and is well worth looking forward to. Knowing how powerful it is, let's start by installing and experiencing this NoSQL database. Tools/Materials

os:centos6.2 64bit

Software:redis Yum Installation 1

Since CentOS does not have a repository with Redis, we first download third-party Fedora repository:

wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

RPM-IVH epel-release-6-8.noarch.rpm


2

Installing Redis:yum Install Redis

View Redis Installation items: Find/-name *redis*







3

Start Redis Service: redis-server/etc/redis.conf



4

Verifying the Redis service: telnet localhost 6379

Set Kin 1

Get Kin END

Source Installation

Download the source installation package:

Yum install Tcl #redis需要安装tcl

Yum Install gcc #编译需要gcc

Yum Install Jemalloc-devel

Cd/usr/local/src

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

Tar xvzf redis-2.8.9.tar.gz

CD redis-2.8.9

Make #编译

Make install #安装

Copy the configuration file to the/etc directory:

CP redis.conf/etc/

Vi/etc/redis.conf

Daemonize No = daemonize Yes

To start the Redis service:

Redis-server/etc/redis.conf




To verify the Redis service:

Redis-cli Ping

PONG

Redis-cli

Set Kin 1

Get Kin
Refer to the following article: http://doc.redisfans.com/set/srandmember.html srandmember

srandmember Key [Count]

If the command executes, only the key parameter is supplied, then a random element in the collection is returned.

Starting with Redis version 2.6, the Srandmember command accepts the optional count parameter: If Count is a positive number and is less than the collection cardinality, the command returns an array containing count elements, each of which differs from the elements in the array. If count is greater than or equal to the collection cardinality, then the entire collection is returned. If count is a negative number, the command returns an array in which the elements in the array may recur multiple times , and the length of the array is the absolute value of count.

This action is similar to  SPOP , but  SPOP  removes and returns random elements from the collection, and  SRANDMEMBER  returns only random elements without any changes to the collection. available Versions: >= 1.0.0 time complexity: is O (1) when only the   key  parameter is supplied. If the   count  parameter is provided, then O (n), N is the number of elements in the returned array. return Value: returns an element when only the   key  parameter is supplied, or returns   nil  if the collection is empty. Returns an array if the   count  parameter is provided, or an empty array if the collection is empty.

# add element

redis> sadd fruit Apple Banana cherry
(integer) 3

# Only given the key parameter, return a random element

redis> Srandmember fr Uit
"Cherry"

redis> srandmember fruit
"Apple"

# given 3 is the Count parameter, returning 3 random elements
# Each random element is not the same

Redis > Srandmember Fruit 3
1) "Apple"
2) "Banana"
3) "Cherry"

# given-3 is the Count parameter, returning 3 random elements
# elements may Repeat multiple

redis> srandmember fruit-3
1) "Banana"
2) "Cherry"
3) "Apple"

redis> Srandmember fruit-3
1) "Apple"
2) "Apple"
3) "Cherry"

# returns the entire collection

if Count is an integer and is greater than or equal to the collection cardinality redis> Srandmember Fruit
1) "Apple"
2) "Banana"
3) "Cherry"

# If Count is a negative number and the absolute value of count is greater than the base of the collection c29/># then the length of the returned array is the absolute value of Count

redis> srandmember fruit-10
1) "Banana"
2) "Apple"
3) "Banana" C34/>4) "Cherry"
5) "Apple" (
6) "Apple"
7) "Cherry"
8) "Apple"
9) "Apple"
) "Banana"

# Srandmember does not modify the contents of the collection

redis> smembers fruit
1) "Apple"
2) "Cherry"
3) "Banana"

# Returns nil or an empty array when the collection is empty

redis> srandmember not-exists
(nil)

redis> srandmember not-eixsts
( Empty list or set)

Refer to the following article: http://blog.csdn.net/yhl27/article/details/9936189 [Redis] redis-cli Command Summary

Redis provides a rich command to manipulate databases and various data types, which can be used on Linux endpoints.

In programming, such as using Redis's Java language Pack, these commands have a corresponding method. The following is a summary of the commands provided by Redis.

Official website Command list: http://redis.io/commands (English)

1. Commands related to connection operation

Quit: Close connection (connection)

Auth: simple Password Authentication

2. Commands for value operations

Exists (key): Verify that a key exists

Del (key): Delete a key

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.