Skip to content

Commit f30388b

Browse files
author
Blair McKenzie
committed
add version of setnx with expire
1 parent 9c7b653 commit f30388b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

packages/custom/cfredis.cfc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,6 +1938,29 @@ Thanks!
19381938
</cfif>
19391939
</cffunction>
19401940

1941+
<!--- SETNXEX - Long setnxex(String key, String value, Numeric seconds) --->
1942+
<cffunction name="setnxex" access="public" returntype="numeric" output="no">
1943+
<cfargument name="key" type="string" required="yes" />
1944+
<cfargument name="value" type="string" required="yes" />
1945+
<cfargument name="seconds" type="numeric" required="yes" />
1946+
1947+
<cfset var connection = '' />
1948+
<cfset var result = '' />
1949+
1950+
<cfset connection = getResource() />
1951+
<cfset result = connection.setnx(JavaCast("string", arguments.key), JavaCast("string", arguments.value)) />
1952+
<cfif result eq 1>
1953+
<cfset connection.expire(JavaCast("string", arguments.key), JavaCast("int", arguments.seconds)) />
1954+
</cfif>
1955+
<cfset returnResource(connection) />
1956+
1957+
<cfif isDefined("result")>
1958+
<cfreturn result />
1959+
<cfelse>
1960+
<cfreturn 0 />
1961+
</cfif>
1962+
</cffunction>
1963+
19411964

19421965
<!--- SETRANGE - long setrange(String key, long offset, String value) --->
19431966
<cffunction name="setrange" access="public" returntype="numeric" output="no">

0 commit comments

Comments
 (0)