Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Redis Sessions for RiveScript

This module installs support for using a Redis cache to store user variables for RiveScript.

pip install rivescript_redis

By default, RiveScript keeps user variables in an in-memory dictionary. This driver allows for using a Redis cache instead. All user variables will then be persisted to Redis automatically, which enables the bot to remember users after a reboot.

Quick Start

from rivescript import RiveScript
from rivescript_redis import RedisSessionManager

# Initialize RiveScript like normal but give it the RedisSessionManager.
bot = RiveScript(
    session_manager=RedisSessionManager(
        # You can customize the key prefix: this is the default. Be sure to
        # include a separator like '/' at the end so the keys end up looking
        # like e.g. 'rivescript/username'
        prefix='rivescript/',

        # All other options are passed directly through to redis.StrictRedis()
        host='localhost',
        port=6379,
        db=0,
    ),
)

bot.load_directory("eg/brain")
bot.sort_replies()

# Get a reply. The user variables for 'alice' would be persisted in Redis
# at the (default) key 'rivescript/alice'
print(bot.reply("alice", "Hello robot!"))

Example

An example bot that uses this driver can be found in the eg/sessions directory of the rivescript-python project.

See Also

  • Documentation for redis-py, the Redis client module used by this driver.

License

This module is licensed under the same terms as RiveScript itself (MIT).