redisim


Nameredisim JSON
Version 0.0.4 PyPI version JSON
download
home_pageNone
Summaryredisim
upload_time2024-03-26 12:20:44
maintainerNone
docs_urlNone
authorlloydzhou@gmail.com
requires_python>=3.8
licenseMIT
keywords redis im websocket
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            

# 使用redis stream实现im

## redis key

1. `u:<uid>` hash, 存放用户信息,例如name/avatar等
2. `s:<uid>` stream, 这个队列用于接收/发送用户消息
3. `c:<uid>` sorted set, 用于存放用户联系人(包括群组)
4. `gm:<gid>` set, 用于存放群用户id
5. `gs:<gid>` stream, 用于接收/发送群消息
6. `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
1. using tornado WebSocketHandler to create websocket.
2. 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




            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "redisim",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "Redis, IM, Websocket",
    "author": "lloydzhou@gmail.com",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/19/de/86116d196424e3389e22ef1faa735b31ee4103caddb6cd4462b6566b9176/redisim-0.0.4.tar.gz",
    "platform": null,
    "description": "\n\n# \u4f7f\u7528redis stream\u5b9e\u73b0im\n\n## redis key\n\n1. `u:<uid>` hash, \u5b58\u653e\u7528\u6237\u4fe1\u606f\uff0c\u4f8b\u5982name/avatar\u7b49\n2. `s:<uid>` stream, \u8fd9\u4e2a\u961f\u5217\u7528\u4e8e\u63a5\u6536/\u53d1\u9001\u7528\u6237\u6d88\u606f\n3. `c:<uid>` sorted set, \u7528\u4e8e\u5b58\u653e\u7528\u6237\u8054\u7cfb\u4eba\uff08\u5305\u62ec\u7fa4\u7ec4\uff09\n4. `gm:<gid>` set, \u7528\u4e8e\u5b58\u653e\u7fa4\u7528\u6237id\n5. `gs:<gid>` stream, \u7528\u4e8e\u63a5\u6536/\u53d1\u9001\u7fa4\u6d88\u606f\n6. `gi:<gid>` hash, \u5b58\u653e\u7fa4\u4fe1\u606f\uff0c\u4f8b\u5982name\uff0c\u8fd8\u6709\u4e00\u4e9b\u914d\u7f6e\u4fe1\u606f\uff08\u4f8b\u5982\u52a0\u7fa4\u662f\u5426\u9700\u8981\u9a8c\u8bc1\uff1f\uff09\n\n## redis module\n> redis module\u5b9e\u73b0IM\n\n### IM.RECIVE\n> IM.RECIVE [uid] BLOCK [ms] COUNT [count] START [start]  \n> \u83b7\u53d6\u5386\u53f2\u6d88\u606f\uff0c\u4ee5\u53ca\u76d1\u542c\u65b0\u7684\u6d88\u606f\n\n### IM.MESSAGE\n> IM.RECIVE [GROUP | USER] [uid | gid] [mid]  \n> \u83b7\u53d6\u5355\u6761\u6d88\u606f\n\n### IM.SEND\n> IM.SEND [uid] [tuid] [field value] [field value ... ]  \n> \u53d1\u9001\u5355\u804a\u6d88\u606f\n\n### IM.GSEND\n> IM.GSEND [uid] [gid] [field value] [field value ... ]  \n> \u53d1\u9001\u7fa4\u804a\u6d88\u606f\n\n### IM.USER\n> IM.USER  [uid]  \n> (get user info)  \u83b7\u53d6\u7528\u6237\u4fe1\u606f  \n> IM.USER  [uid] [field value] [field value ... ]  \n> (create user or update user info)\n\n### IM.GROUP\n> IM.GROUP [gid]  \n> (get group info)  \n> IM.GROUP [gid] [uid] [field value] [field value ... ]  \n> (create group or update group info)\n\n### IM.LINK\n> IM.LINK [uid] [tuid]  \n> (add to user contact list)\n\n### IM.UNLINK\n> IM.UNLINK [uid] [tuid]  \n> (remove from user contact list)\n\n### IM.JOIN\n> IM.LINK [uid] [gid]  \n> (add to user group)\n\n### IM.QUIT\n> IM.QUIT [uid] [gid]  \n> (remove from user group)\n\n## GUI\n1. using tornado WebSocketHandler to create websocket.\n2. using svelte create simple ui to send message (using localStorage to save message)\n\n\n## docker\n\n```\ndocker run --rm --name=redisim -p 8888:8888 lloydzhou/redisim\n```\n\n# python sdk\n```\npip install redisim\n```\n## demo\n```\nimport asyncio\nimport redis.asyncio as redis\nimport redisim\n\nasync def main():\n    client = redis.Redis(decode_responses=True)\n    res = await client.im().recive(user_id, **kwargs)\n    print(res)\n\nasyncio.run(main())\n```\n\n## lua script version\n```\nim = client.im(module=False)\n```\n\n## apache/kvrocks\n\nusing lua script version with apache/kvrocks\n\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "redisim",
    "version": "0.0.4",
    "project_urls": {
        "Code": "http://github.com/lloydzhou/redisim",
        "Documentation": "http://github.com/lloydzhou/redisim",
        "Issue tracker": "http://github.com/lloydzhou/redisim/issues"
    },
    "split_keywords": [
        "redis",
        " im",
        " websocket"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "19de86116d196424e3389e22ef1faa735b31ee4103caddb6cd4462b6566b9176",
                "md5": "13e5e80afc116aabf132903ee1f75cb5",
                "sha256": "84f1c6f98a16be4a2369202fecb885e48f0d8f291d15993e574ecb2a368188e0"
            },
            "downloads": -1,
            "filename": "redisim-0.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "13e5e80afc116aabf132903ee1f75cb5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 7474,
            "upload_time": "2024-03-26T12:20:44",
            "upload_time_iso_8601": "2024-03-26T12:20:44.167188Z",
            "url": "https://files.pythonhosted.org/packages/19/de/86116d196424e3389e22ef1faa735b31ee4103caddb6cd4462b6566b9176/redisim-0.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-26 12:20:44",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lloydzhou",
    "github_project": "redisim",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "redisim"
}
        
Elapsed time: 0.22390s