【redis,nosql】redis键值数据库

2023-12-15 09:27:50

什么是redis数据库

Redis?is?an?open?source,?in-memory?data structure store?used?as?a?database,?cache, message broker, and?streaming?engine.
?

存储模式

字符串(String)

Redis?strings?store?sequences?of?bytes,?including?text,?serialized?objects,?and?binary?arrays.?As such, strings?are?the?simplest?type?of?value?you?can?associate?with?a?Redis?key.

redis以二进制保存数据?

列表(list)

Redis?lists?are?linked?lists?of?string?values.?Redis?lists?are?frequently?used?to:

(1)Implement?stacks?and?queues.?

(2)Build?queue?management?for?background?worker?systems.

按照列表插入顺序排序

注意:1. 允许重复出现值

集合(Set)

A?Redis?set?is?an?unordered?collection?of?unique?strings?(members).?

You?can?use?Redis?sets?to?efficiently:
(1)Track?unique?items?(e.g.,?track?all?unique?IP?addresses?accessing?a?given?blog?post).
(2)Represent?relations?(e.g.,?the?set?of?all?users?with?a?given?role).
(3)Perform?common?set?operations?such?as?intersection,?unions,?and?differences.

Set:无序唯一的字符串或数字,操作:交、并、差

注意:1. 字符串值不能重复,不排序

有序集合(Softed Set)?

?散列表(hash)

Redis?hashes?are?record?types?structured?as?collections?of?field-value pairs. You?can?use?hashes?to represent basic objects and to store groupings of counters, among other?things.

bitmaps

hyperloglogs

geospatial indexes

stream

命令

字符串命令

检查是否装好?

redis-server redis.windows.conf

运行

redis-cli -h 127.0.0.1 -p 6379

保存(修改)键值对

set test "test value"

如果存在不修改,如果不存在,添加?

setnx key value
msetnx key value [key value...]

?删除键值对

del key [key...]

获得键值对

get test
mget value [value...]

判断是否存在键值对

exists test

?自增

incr test

自增大于1

INCRBY key num

?获取服务器信息

info [属性]

改变数据库?

select index

存在多少键值对?

dbsize

模糊查询(显示键名)

keys [键名]

看值的类型?

type [键名]

查看值的长度

strlen key

清空数据库?

flushdb

清空所有数据库?

flushall

清屏

clear

List(列表)命令?

插入

左插入

lpush key value [value...]

右插入

rpush key value [value...]

查询

lrange key start stop
lrange newList 0 -1//查询全部

?删除

删除左边第一个元素

lpop key

删除右边第一个元素?

rpop key

Set(集合)命令

SADD添加数据(增)

 sadd key member [member……]

SREM删除数据(删)

 srem key member [member...]

SMEMBERS 获得元素(查)

 smembers key

SISMEMBER 判断是否是成员

SINTER 取交集

SCAED 获取集合的长度

scard key

?srandmember随机返回元素

srandmember key [count]

?count:随机返回的元素个数

Hash命令

hset插入

hset hashtable:key1 key2 value

hget获得值

hget hashtable:key1 key2

hmset多个插入

hmget多个获得值

hgetall获取全部

hexists是否存在值

hexists key1 key2

hdel删除

hdel key1 key2 [key1 key2]

位图命令

bitcount命令

bitcount key [start end]

文章来源:https://blog.csdn.net/David_Hzy/article/details/134506283
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。