使用redis stream实现im
redis key
u:<uid>hash, 存放用户信息,例如name/avatar等s:<uid>stream, 这个队列用于接收/发送用户消息c:<uid>sorted set, 用于存放用户联系人(包括群组)gm:<gid>set, 用于存放群用户idgs:<gid>stream, 用于接收/发送群消息gi:<gid>hash, 存放群信息,例如name,还有一些配置信息(例如加群是否需要验证?)
redis module
redis module实现IM
IM.RECIVE
IM.RECIVE [uid] BLOCK [ms] COUNT [count] START [start]
获取历史消息,以及监听新的消息
IM.MESSAGE
IM.RECIVE [GROUP | USER] [uid | gid] [mid]
获取单条消息
IM.SEND
IM.SEND [uid] [tuid] [field value] [field value ... ]
发送单聊消息
IM.GSEND
IM.GSEND [uid] [gid] [field value] [field value ... ]
发送群聊消息
IM.USER
IM.USER [uid]
(get user info) 获取用户信息
IM.USER [uid] [field value] [field value ... ]
(create user or update user info)
IM.GROUP
IM.GROUP [gid]
(get group info)
IM.GROUP [gid] [uid] [field value] [field value ... ]
(create group or update group info)
IM.LINK
IM.LINK [uid] [tuid]
(add to user contact list)
IM.UNLINK
IM.UNLINK [uid] [tuid]
(remove from user contact list)
IM.JOIN
IM.LINK [uid] [gid]
(add to user group)
IM.QUIT
IM.QUIT [uid] [gid]
(remove from user group)
GUI
- using tornado WebSocketHandler to create websocket.
- using svelte create simple ui to send message (using localStorage to save message)
docker
docker run --rm --name=redisim -p 8888:8888 lloydzhou/redisim
python sdk
pip install redisim
demo
import asyncio
import redis.asyncio as redis
import redisim
async def main():
client = redis.Redis(decode_responses=True)
res = await client.im().recive(user_id, **kwargs)
print(res)
asyncio.run(main())
lua script version
im = client.im(module=False)
apache/kvrocks
using lua script version with apache/kvrocks
Metadata
Release files for redisim 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| redisim-0.0.5.tar.gz | 7.5 kB | Without provenance | Details for redisim-0.0.5.tar.gz |
Release files / redisim-0.0.5.tar.gz
| Download URL | redisim-0.0.5.tar.gz |
|---|---|
| Size | 7.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
97b8e5897abd5d933943d85ff5235c84843885fce24edc6d4a1ad15cfc94eab9
|
|
BLAKE2b-256 checksum How to use checksums |
0c47ba1dfce782782c00f26885249430be00b60957aa512c39bbfb65fc4888b1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.8
|
Security for redisim 0.0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.