Một mục mã nguồn mở trong kho dữ liệu GitHub của TopGit: tj/connect-redis, 2.8k sao, TypeScript. Redis session store for Connect
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
connect-redis provides Redis session storage for Express.
Installation
connect-redis requires express-session and redis:
npm install redis connect-redis express-session
TypeScript note: types included in the package, don't install @types/connect-redis.
API
Full setup:
import {RedisStore} from "connect-redis"
import session from "express-session"
import {createClient} from "redis"
// Initialize client.
let redisClient = createClient()
redisClient.connect().catch(console.error)
// Initialize store.
let redisStore = new RedisStore({
client: redisClient,
prefix: "myapp:",
})
// Initialize session storage.
app.use(
session({
store: redisStore,
resave: false, // required: force lightweight session keep alive (touch)
saveUninitialized: false, // recommended: only save session when data exists
secret: "keyboard cat",
}),
)
RedisStore(options)
Options
client
An instance of redis
prefix
Key prefix in Redis (default: sess:).
Note: This prefix appends to whatever prefix you may have set on the client itself.
Note: You may need unique prefixes for different applications sharing the same Redis instance. This limits bulk commands exposed in express-session (like length, all, keys, and clear) to a single application's data.
ttl
If the session cookie has a expires date, connect-redis will use it as the TTL.
Otherwise, it will expire the session using the ttl option (default: 86400 seconds or one day).
ttl also has external callback support. You can use it for dynamic TTL generation. It has access to session data.
Note: The TTL is reset every time a user interacts with the server. You can disable this behavior in some instances by using disableTouch.
Note: express-session does not update expires until the end of the request life cycle. Calling session.save() manually beforehand will have the previous value.
disableTouch
Disables resetting the TTL when using touch (default: false)
The express-session package uses touch to signal to the store that the user has interacted with the session but hasn't changed anything in its data. Typically, this helps keep the users session alive if session changes are infrequent but you may want to disable it to cut down the extra calls or to prevent users from keeping sessions open too long. Also consider enabling if you store a lot of data on the session.
This option disables key expiration requiring the user to manually manage key cleanup outside of connect-redis. Only use if you know what you are doing and have an exceptional case where you need to manage your own expiration in Redis.
Note: This has no effect on express-session setting cookie expiration.
serializer
Provide a custom encoder/decoder to use when storing and retrieving session data from Redis (default: JSON.parse and JSON.stringify).
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/tj/connect-redis là nguồn chính thức.
tj/connect-redis có bao nhiêu sao?
tj/connect-redis có 2.8k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/tj/connect-redis. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
tj/connect-redis có tag gì không?
Bản đồng bộ chưa ghi nhận topic GitHub nào cho tj/connect-redis. GitHub topics hiển thị ở thanh bên phải trang repo — đó là nơi đáng kiểm tra nhất.
tj/connect-redis còn đang phát triển không?
Commit gần nhất trên tj/connect-redis là 5 ngày trước (theo timestamp GitHub). Repo có 345 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
tj/connect-redis viết bằng ngôn ngữ gì?
tj/connect-redis chủ yếu viết bằng TypeScript. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc đầy đủ README ở tab phía trên.
Muốn nghe thêm một ý kiến về connect-redis?
Hỏi một AI đọc được trang này — một cú bấm là có ngay nhận định về connect-redis.