Redis基本认识
前言
公司手游使用redis作为数据库,虽然做的是测试工作,但还是觉得有必要了解一些redis的相关概念以及基本操作。以前做页游测试时涉及到memcache,Tokyo Tyrant但使用的是别人开发好的工具,了解几乎为零。了解以下命令,可以完成基本的查询插入操作。
一、基本认识:
redis本质上是一个Key-Value类型的内存数据库,扩展了memcache。整个数据库全部加载在内存中进行操作,并且定期通过异步操作把数据库数据flush到硬盘上保存。
[*] redis可以看做Memcache的扩展,基于内存并支持数据持久化存储。
[*] 支持网络、日志型、Key-Value型数据库
[*] 支持常规数值、字符串,Lists、Sets、Sorted Sets、Hashes。
[*] 获取帮助信息:help command
二、基本操作:
set key value设置key及其valueget key查询数据del key删除键值exists key验证键值是否存在,0代表不存在,1代表存在setnx keykey已经存在返回0,不存在返回1并设置成功setex key有效期10秒钟:setex name jake 10setrange 设置指定key的子字符串:setrange key 8 163.com
将key的第八个字符及其后7个字符的串替换为163.co
mset key1 key2…一次设置多个keymget key1 key2…一次获取多个键的值msetnx key1 key2…一次设置多个键值对并判断是否已存在getset key设置key的值,并返回key的旧值getrange key n1 n2 获取指定key指定范围的子字符串
最后的字符是-1,依次向前递减
incr key值加1incrby key intValue加上指定值decr值减1decrby key intValue减去指定值append key string追加字符串在末尾strlen key获取指定字符串的长度 三、hash表操作,特别使用于存储对象:
1、hset key field value
summary: Set the string value of a hash field
2、hsetnx key field value
summary: Set the value of a hash field, only if the field does not exist
3、hmset key field value
summary: Set multiple hash fields to multiple values
4、hget key field
summary: Get the value of a hash field
5、hmget key field
summary: Get the values of all the given hash fields
6、hincrby key field increment
summary: Increment the integer value of a hash field by the given number
7、hexists key field
summary: Determine if a hash field exists
8、hlen key
summary: Get the number of fields in a hash
9、hdel key key field
summary: Delete one or more hash fields
10、hkeys
summary: Get all the fields in a hash
11、hvals
summary: Get all the values in a hash
12、hgetall
summary: Get all the fields and values in a hash
页:
[1]