layout: post
title: Redis简介与基础命令
date: 2018-03-22
tags: [“Redis”,”软件服务”]


一、Redis简介

Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs and geospatial indexes with radius queries.

Redis has built-in replication, Lua scripting, LRU eviction, transactions and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.

注意:只有3.x的版本支持redis-cluster功能,老点的2.x并不支持(cluster非replication)

二、data structure base command

1、string类型value的操作

  1. SET 设置字符串键值
  2. GET 获取字符串键值
  3. EXISTS 判断键值是否存在
  4. INCR 当前值加1inter类型)
  5. DECR 当前值减1inter类型)
  6. SETNX Set the value of a key, only if the key does not exist
  7. SETEX 设置密钥的值和到期日期
  8. INCRBYFLOAT Increment the float value of a key by the given amount
  9. MGET 获取多个值
  10. MSET 设置多个值

2、list类型value的操作

  1. LPUSH 在栈左方插入数据
  2. RPUSH 在栈右方插入数据
  3. LPOP 左方栈弹出数据
  4. RPOP 右方栈弹出数据
  5. LPUSHX Prepend a value to a list, only if the list exists
  6. RPUSHX Prepend a value to a list, only if the list exists
  7. LRANGE Get a range of elements from a list
  8. LINDEX Get an element from a list by its index
  9. LSET Set the value of an element in a list by its index

3、set类型value的操作

  1. SADD 添加集合
  2. SPOP 从集合中随机弹出元素
  3. SREM Remove one or more members from a set
  4. SRANDMEMBER Get one or multiple random members from a set
  5. SINTER Intersect multiple sets(交集)
  6. SUNION 并集

4、sort set 类型value的操作

  1. ZADD Add one or more members to a sorted set, or update its score if it already exists
  2. ZCARD Get the number of members in a sorted set
  3. ZCOUNT Count the members in a sorted set with scores within the given values
  4. ZRANK Determine the index of a member in a sorted set

5、hash类型value的操作

  1. HSET Set the string value of a hash field
  2. HMSET Set multiple hash fields to multiple values
  3. HGET Get the value of a hash field
  4. HMGET Get the values of all the given hash fields
  5. HKEYS Get all the fields in a hash
  6. HVALS Get all the values in a hash
  7. HDEL Delete one or more hash fields
  8. HGETALL Get all the fields and values in a hash

6、pubsub

  1. PUBLISH Post a message to a channel
  2. SUBSCRIBE Listen for messages published to the given channels
  3. UNSUBSCRIBE Stop listening for messages posted to the given channels
  4. PSUBSCRIBE Listen for messages published to channels matching the given patterns
  5. PUNSUBSCRIBE Stop listening for messages posted to channels matching the given patterns

三、Redis System Command

文档更新时间: 2018-12-20 15:18   作者:张尚