Skip to content

Commit 5cd8c0d

Browse files
authored
Prepare generate (#23)
* prepare_generate to set new session id if old id does not exists * fixed inconsistent session behaviour in redis store during update * update/insert redis session with rename even if old_key is not found in store * prepare for release
1 parent a28d367 commit 5cd8c0d

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [0.5.6] - 2024-02-16
4+
5+
### Fixed
6+
7+
- Update/insert redis session with rename even if old_key is not found in store'
8+
39
## [0.5.5] - 2024-02-16
410

511
### Fixed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "ruts"
33
description = "A middleware for tower sessions"
4-
version = "0.5.5"
4+
version = "0.5.6"
55
edition = "2021"
66
rust-version = "1.75.0"
77
authors = ["Jimmie Lovell <[email protected]>"]

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Add the following to your `Cargo.toml`:
2323

2424
```toml
2525
[dependencies]
26-
ruts = "0.5.5"
26+
ruts = "0.5.6"
2727
```
2828

2929
## Quick Start

src/store/redis/lua.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,14 @@ pub(crate) static INSERT_WITH_RENAME_SCRIPT: &str = r#"
5252
local key_seconds = tonumber(ARGV[3])
5353
local field_seconds = ARGV[4]
5454
55-
local renamed = redis.call('RENAMENX', old_key, new_key)
56-
if renamed == 0 then
57-
return 0 -- Either old_key doesn't exist or new_key already exists
55+
local old_exists = redis.call('EXISTS', old_key)
56+
if old_exists == 1 then
57+
local renamed = redis.call('RENAMENX', old_key, new_key)
58+
if renamed == 0 then
59+
return 0
60+
end
5861
end
5962
60-
-- Now we own new_key exclusively
6163
local inserted = redis.call('HSETNX', new_key, field, value)
6264
6365
redis.call('EXPIRE', new_key, key_seconds)
@@ -76,12 +78,14 @@ pub(crate) static UPDATE_WITH_RENAME_SCRIPT: &str = r#"
7678
local key_seconds = tonumber(ARGV[3])
7779
local field_seconds = ARGV[4]
7880
79-
local renamed = redis.call('RENAMENX', old_key, new_key)
80-
if renamed == 0 then
81-
return 0 -- Either old_key doesn't exist or new_key already exists
81+
local old_exists = redis.call('EXISTS', old_key)
82+
if old_exists == 1 then
83+
local renamed = redis.call('RENAMENX', old_key, new_key)
84+
if renamed == 0 then
85+
return 0
86+
end
8287
end
8388
84-
-- Now we own new_key exclusively
8589
local updated = redis.call('HSET', new_key, field, value)
8690
8791
redis.call('EXPIRE', new_key, key_seconds)

0 commit comments

Comments
 (0)